在 JavaScript 中跟踪安全策略权限
Tracing security policy permissions in JavaScript
尽管设置了以下标头:
Access-Control-Allow-Origin: *
Content-Security-Policy: default-src 'self' 'unsafe-inline' *.speech.is http://bits.speech.is https://bits.speech.is http://speech.is
JavaScript 仍然阻止我访问 iframe.contentWindow.document:
Error: Permission denied to access property 'document'
从火狐控制台speech.contentWindow.document
后在http://bits.speech.is
.Chrome给出了更冗长但仍然神秘的东西:
SecurityError: Blocked a frame with origin "http://bits.speech.is" from accessing a frame with origin "http://208.113.212.187". Protocols, domains, and ports must match.
code: 18
message: "Blocked a frame with origin "http://bits.speech.is" from accessing a frame with origin "http://208.113.212.187". Protocols, domains, and ports must match."
name: "SecurityError"
stack: "Error: Blocked a frame with origin "http://bits.speech.is" from accessing a frame with origin "http://208.113.212.187". Protocols, domains, and ports must match.↵ at <anonymous>:2:21↵ at Object.InjectedScript._evaluateOn (<anonymous>:580:39)↵ at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)↵ at Object.InjectedScript.evaluate (<anonymous>:458:21)"
有没有办法跟踪此安全策略的设置位置? 如何弄清楚我还错过了什么?
我能够找到的微调CSP的最佳方法是以下两者的结合:
- 查看浏览器控制台
- 将 CSP 配置为发送的 CSP 报告,因为它们有时包含更多详细信息,可以控制台消息
对于后者,您需要将report-uri
添加到CSP标头中,我使用 http://cspbuilder.info/唯一的URL作为报告收集器。您还可以设置Content-Security-Policy-Report-Only
变体,直到它开始工作。
如果您编写正在使用的浏览器,也会有所帮助。该消息看起来不像来自Chrome的CSP违规错误 - 它们比这个更详细,而且非常有用。
相关文章:
- 内容安全策略:页面's设置阻止加载资源
- 导致内容安全策略(CSP)冲突错误的本地jquery.js文件
- 旋转木马;启用内容安全策略时无法工作
- Extjs、Chrome扩展和内容安全策略
- 内容安全策略指令:;脚本src'self'blob:文件系统:chrome扩展资源:“;获取是否时
- 内容安全策略:无法在Chrome扩展中加载Google API
- 手动加载JQuery而不触发内容安全策略
- chrome扩展的内容安全策略问题
- WebGL CORS:试图突破用户代理的安全策略
- 在 JavaScript 中跟踪安全策略权限
- 如何打破内容安全策略
- 内容安全策略 + 表单插件
- 跨站点 XMLHttpRequest 内容安全策略指令解决方法
- 内容安全策略阻止对 *://www.google.com/recaptcha/api 的请求
- 如何检测内容安全策略 (CSP)
- 内容安全策略不从本地主机加载文件
- 如何在浏览器 JS 控制台中包含脚本时覆盖内容安全策略
- 内容安全策略指令:“script-src 'self' 'unsafe-eval'”
- 如何在 Netbeans 轻型 Web 服务器中指定内容安全策略
- Chrome 扩展程序“拒绝加载脚本,因为它违反了以下内容安全策略指令”