我在仅报告模式下使用以下内容安全策略:
Content-Security-Policy-Report-Only "default-src 'self'; report-uri /log_violations"
当我访问服务器上的 URL 时,其 HTML 页面包含以下内容:
<!DOCTYPE html>
<head>
<title>
Test document
</title>
</head>
<html>
<body>
Hello
</body>
</html>
我在 Firefox 57.0 的第 1 行看到以下错误消息:
Content Security Policy: The page’s settings observed the loading of a
resource at self (“default-src http://www3.thestar.com”). A CSP report
is being sent. Source: ;!function(){var t=0,e=function(t,e){ret...
在其他浏览器中,例如 Edge、Chrome,我没有看到这些错误。
您认为这是 Firefox 的怪癖还是我设置不正确的地方?我很困惑为什么该政策拒绝每页的第一行。
最佳答案
您可能安装并启用了一个扩展程序,该扩展程序正在将内容注入(inject)到页面中。尝试在 new Firefox profile 中打开页面不带任何扩展程序来查看您是否看到报告的 CSP 违规行为。
Firefox 计划从 Firefox 58 开始在 CSP 检查中排除扩展程序注入(inject)的内容,因此这应该会减少扩展程序在页面上执行操作时产生的噪音。
来自Mozilla blog ,
Starting with Firefox 58, the CSP of a web page does not apply to content inserted by an extension. This allows, for example, the extension to load its own resources into a page.
关于firefox - 内容安全策略在第 1 行失败 (Firefox 57.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47519661/