javascript - 在 Google Chrome 中调试 CSP 违规

标签 javascript security google-chrome tinymce content-security-policy

我在使用以下 Content-Security-Policy HTTP header 时尝试使用 TinyMCE:

X-WebKit-CSP: default-src 'self'; script-src 'self' 'unsafe-eval'; img-src *; media-src *; frame-src *; font-src *; style-src 'self' 'unsafe-inline'; report-uri /:reportcspviolation

我在工具 - JavaScript 控制台中收到以下错误:

Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
 about:blank:1
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
 test.xhtml:1
Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
 about:blank:1
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
 test.xhtml:1

但是,test.xhtml 中没有可执行的 JS 代码 因为它只使用外部 <script>使用给定的 CSP header 。 引用about:blank也同样无效

关于如何找出违反 CSP 的原因的任何想法?

Chrome 的内部 JS 调试器似乎无法识别来源。

此外,出于某种原因,Chrome 在“工具”-“开发人员工具”-“网络”中将 CSP 违规报告显示为“待定”,但检查要发送的数据不会提供任何其他信息。示例:

{"csp-report":{"document-uri":"about:blank","referrer":"url-of/test.xhtml","violated-directive":"script-src 'self' 'unsafe-eval'","original-policy":"default-src 'self'; script-src 'self' 'unsafe-eval'; img-src *; media-src *; frame-src *; font-src *; style-src 'self' 'unsafe-inline'; report-uri /:reportcspviolation"}}

我能够弄清楚错误消息是关于使用例如onclick TinyMCE 动态加载的一些 HTML 中的属性,但是要查找什么文件?另一个错误可能是一段 TinyMCE HTML,其中一些 href具有以 javascript: 开头的值但是如果没有 Chrome 的任何指示,那也很难找到。整个设置适用于 Firefox 13(使用相应的 CSP header )。

有没有办法让 Chrome 在每次违反 CSP 时抛出异常?

最佳答案

在您的网站上测试 CSP 时,请务必禁用所有 Chrome 扩展程序 - 例如,AdBlock 和 PhotoZoom 扩展程序都会将它们自己的内联样式添加到 DOM 中,这会触发违规(如果您有,则随后会点击 report-uri该功能已启用,其他扩展程序可能也会这样做。

关于javascript - 在 Google Chrome 中调试 CSP 违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11360557/

相关文章:

用于登录显示的 PHP 的 IF/Else

reactjs - Redux 开发工具和 React Native

css - 谷歌浏览器中的字体损坏

google-chrome - 检测另一个浏览器选项卡是否正在使用语音识别

javascript - 如何使用 JavaScript 查找日期数组中的日期交叉点/冲突

javascript - 从 socket.io 返回一个值到客户端

.net - 如何保持 .NET 程序逻辑(合理地)保密?

Git - 忽略配置文件

javascript - 为 dygraphs javascript 图表创建工具提示

javascript - 为什么 window.location.href 没有完成 $.post...?