我正在尝试将内嵌图像列入白名单。是否有办法像image_tag那样将随机数添加到javascript_include_tag 将内嵌图片列入白名单。
基于CSP: img-src,它提到img-src
支持'nonce-<base64-value>'
我对image-src
的CSP政策
policy.img_src :self
我尝试了以下操作,并确认随机数出现在dom中。
#fruist_store.html.haml
= image_tag('https://assets.myfruitstore.com', nonce: content_security_policy_nonce)
但是image_tag
上的随机数似乎不像script-src
那样受尊敬。我还在
[Report Only] Refused to load the image 'https://assets.myfruitstore.com' because it violates the following Content Security Policy directive: "img-src self
我想知道是否还有另一种方法可以完成这项工作,或者那是不确定的事情。
更新:
因此基于Rails content_security_policy.rb#L134,似乎Rails不会将随机数添加到image_src
所以我将政策更新为
policy.img_src :self, -> {%(nonce-{request.content_security_policy_nonce})}
但仍将其标记为违规