CSP:https 站点上的相对 img src 尝试 link 到 http 图像
CSP: Relative img src on https site tries to link to http image
我在 HTTPS 上有一个站点,我正在 link 访问具有相对 link 的图像。我正在使用 rails 助手
生成 link
<%= image_tag url_for(screenshot.attachment) %>
它会生成像
这样的图像标签
<img src="/rails/blobs/myimage.jpg"/>
虽然该站点是在 HTTPS 上并且我使用的是相对路径,但我收到以下 CSP 错误
Refused to load the image 'http://example.com/rails/blobs/myimage.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%22screenshot.jpg%22%3B+filename%2A%3DUTF-8%27%27screenshot.jpg'
because it violates the following Content Security Policy directive: "img-src 'self' https: data:".
我不明白为什么它要尝试从 HTTP 加载图像。
从你的 nginx 配置必须做 https 转发。那么这个问题就解决了。
添加 only_path 并将其设置为 false。
url_for(screenshot.attachment, :only_path => false)
默认情况下它是假的,但可以肯定的是,将它添加到您的助手中并查看它是如何工作的。
如果没有帮助,您可以创建完整的 url 喜欢
request.host + url_for(screenshot.attachment)
我在 HTTPS 上有一个站点,我正在 link 访问具有相对 link 的图像。我正在使用 rails 助手
生成 link <%= image_tag url_for(screenshot.attachment) %>
它会生成像
这样的图像标签<img src="/rails/blobs/myimage.jpg"/>
虽然该站点是在 HTTPS 上并且我使用的是相对路径,但我收到以下 CSP 错误
Refused to load the image 'http://example.com/rails/blobs/myimage.jpg?content_type=image%2Fjpeg&disposition=inline%3B+filename%3D%22screenshot.jpg%22%3B+filename%2A%3DUTF-8%27%27screenshot.jpg'
because it violates the following Content Security Policy directive: "img-src 'self' https: data:".
我不明白为什么它要尝试从 HTTP 加载图像。
从你的 nginx 配置必须做 https 转发。那么这个问题就解决了。
添加 only_path 并将其设置为 false。
url_for(screenshot.attachment, :only_path => false)
默认情况下它是假的,但可以肯定的是,将它添加到您的助手中并查看它是如何工作的。
如果没有帮助,您可以创建完整的 url 喜欢
request.host + url_for(screenshot.attachment)