Rails 5将随机数添加到image_tag以将CSP image-src违规列入白名单

时间:2019-06-21 06:25:46

标签: ruby-on-rails ruby-on-rails-5 content-security-policy

我正在尝试将内嵌图像列入白名单。是否有办法像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})}

但仍将其标记为违规

0 个答案:

没有答案