firefox - 内容安全策略在第 1 行失败 (Firefox 57.0)

标签 firefox content-security-policy

我在仅报告模式下使用以下内容安全策略:

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/

相关文章:

html - 使用 -moz-transform 进行 CSS 转换

javascript - firefox 选项卡中的 firebug 或 'how to embed a custom editor' 编辑器?

CSS:菜单在 Firefox 中以正确的空格显示

iframe - 如何在 iframe 中允许 Geolocation API?

http - 如何在不声明过期的情况下强制浏览器获取新 header ?

html - 如何确保 CSS 反转的按钮间距均匀?

用于检测页面何时加载到 Firefox 的另一个窗口中的 Javascript

javascript - 什么 CSP 子 iframe 从其父级继承?

javascript - 无法将 nonce 属性应用于我的内联 css