【发布时间】:2017-02-03 04:57:03
【问题描述】:
我正在为 Shopify CMS 开发一个插件。这个插件使用 webcomponents.js 通过
加载 Polymer 脚本script.src = "data:text/javascript;charset=utf-8," + encodeURIComponent(scriptContent);
webcomponentsjs/src/HTMLImports/parser.js line 307
在 FireFox 中出现以下错误:
Content Security Policy: The page’s settings blocked the loading of a resource at data:text/javascript;charset=utf-8,/**script code*/(“script-src https://domainurl https://* 'unsafe-inline' 'unsafe-eval'”)
原始内容安全策略标头(我无法在服务器上更改此标头,因为 Shopify 是托管平台,我对其没有任何控制权)
Content-Security-Policy:
default-src 'self' https://*;
child-src 'self' https://* blob: data:;
connect-src 'self' https://* wss://*;
font-src 'self' https://* blob: data:;
img-src 'self' https://* blob: data:;
media-src'self' https://* blob: data:;
object-src 'self' https://* blob: data:;
script-src 'self' https://* 'unsafe-inline' 'unsafe-eval';
style-src 'self' https://* 'unsafe-inline';
我正在尝试通过元标记重载此标头
<meta http-equiv="Content-Security-Policy" content="
default-src * data: 'unsafe-inline' 'unsafe-eval';
script-src * data: 'unsafe-inline' 'unsafe-eval';
" />
是否可以通过元标记重载标头值?
【问题讨论】:
-
你试过了吗?
-
不,多个 CSP 总是组合在一起以获得更多限制。 w3.org/TR/CSP2/#enforcing-multiple-policies
-
是的。但我认为我做错了什么。是否可以重载标头值?我在一个页面上找不到任何关于 http 标头和元标记行为的信息。
-
查看更多上下文代码会很有用,特别是
script.src = "data:text/javascript;charset=utf-8," + encodeURIComponent(scriptContent);所在的整个块。也许有更好的方法来导入代码,也许您只需将所有脚本放在另一个 .js 文件中并将其加载到脚本标签中,而不是直接在页面上运行script.src的东西 -
AllTheTime,我已经更新了帖子和附加链接:github.com/webcomponents/webcomponentsjs/blob/…
标签: javascript firefox shopify web-component content-security-policy