【发布时间】:2016-06-01 07:28:21
【问题描述】:
我无法理解下面的 CSP 违规报告(由 FireFox 44.0.2 / Ubuntu 发送)。这里真正被阻止的是什么,为什么?
应该注意的是,我是否将'self' 或(在报告中自动翻译)https://www.example.com 写入 CSP 标头并不重要。
此外,我不知道渲染页面中缺少任何内容。
那么我能做些什么呢? (显然,如果每个页面都触发虚假违规报告,我不应该在我的实时网站中添加报告)
{
"csp-report":{
"blocked-uri":"self",
"document-uri":"https://www.example.com/foo/bar/baz.html",
"original-policy":"report-uri https://reportserver.example.com/ContentSecurityPolicy-report.php;
default-src https://www.example.com;
style-src https://example.com https://www.example.com https://fonts.googleapis.com;
script-src https://www.example.com https://code.jquery.com https://ajax.googleapis.com;
font-src https://fonts.gstatic.com",
"referrer":"https://www.example.com/foo/bar/wtf.html",
"source-file":"https://www.example.com/foo/bar/baz.html",
"violated-directive":"style-src https://example.com https://www.example.com https://fonts.googleapis.com"
}
}
【问题讨论】:
-
这是否部署在任何我可以查看的地方?根据您的描述,我想不出任何除了 Firefox 中的错误。
-
@oreoshake 你可以在
https://www.redeker.de/上看到这个(在“仅报告”模式下从外部)。同时我有点怀疑被阻止的可能是一些'unsafe-inline'风格,即style="..."添加到标签,但这在html源代码中不可见,因为它稍后会被每个脚本添加(脚本本身是允许的CSP)。但如果你能证实这个怀疑,我会很高兴。 -
是的,不安全的内联是必要的。我经常发现开发者控制台有时比报告更有用。 CSP 报告存在许多已知问题,内嵌内容报告就是其中之一。
-
@oreoshake 我想开发者控制台是指 Chrome 的控制台(我现在发现它非常有用),因为 Firefox 中的那个(我最初使用的)给我留下了很多猜测...