我认为这是规范的只是一个简单的误解。不过,我在将脚本包含在受沙箱保护的iFrame中时遇到了问题。具体来说,我正在处理的代码如下。的iFrame沙盒与内容安全策略
在的top.html:
<iframe src="framed.html" sandbox="allow-scripts"></iframe>
在framed.html
...
<head>
<meta http-equiv="Content-Security-Policy" content="script-src example.com">
<script src="http://example.com/script.js"></script>
</head>
...
当运行在Chrome这个文件,它给我的错误:
Refused to load the script ' http://example.com/script.js ' because it violates the following Content Security Policy directive: "script-src localhost:9000".
为什么阻止脚本加载?我知道如果没有allow-same-origin
,iFrame会得到一个完全独一无二的来源,它不等于任何其他来源。因此,script-src 'self'
将无法正常工作。但是,我正尝试从CSP中显式调用的源中加载脚本。思考?
更新:创建JSFiddle展示此问题。
这是与Firefox相同 – mems