【发布时间】:2014-12-16 22:26:42
【问题描述】:
Gmail 刚刚更新了其内容安全政策:http://googleonlinesecurity.blogspot.com/2014/12/reject-unexpected-content-security.html
这会为我的 Chrome 扩展程序引发错误,该扩展程序增强了 gmail。需要明确的是,我的内容脚本正在加载另一个托管在我的服务器上的脚本。这允许快速部署。
Refused to load the script 'https://<domain-path>.js?' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://talkgadget.google.com/ https://www.googleapis.com/appsmarket/v2/installedApps/ https://www-gm-opensocial.googleusercontent.com/gadgets/js/ https://docs.google.com/static/doclist/client/js/ https://www.google.com/tools/feedback/ https://s.ytimg.com/yts/jsbin/ https://www.youtube.com/iframe_api https://ssl.google-analytics.com/ https://apis.google.com/_/scs/abc-static/ https://apis.google.com/js/ https://clients1.google.com/complete/ https://apis.google.com/_/scs/apps-static/_/js/ https://ssl.gstatic.com/inputtools/js/ https://ssl.gstatic.com/cloudsearch/static/o/js/ https://www.gstatic.com/feedback/js/ https://www.gstatic.com/common_sharing/static/client/js/ https://www.gstatic.com/og/_/js/".
这是我从内容脚本加载托管脚本的方式:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://<domain-path>.js';
(document.body || document.head || document.documentElement).appendChild(script);
有什么想法吗?
【问题讨论】:
-
显然您可以使用 chrome 扩展 webRequest 更改 csp 响应标头。这是一种解决方法。但是我不确定这是否是一个好习惯。
标签: javascript google-chrome google-chrome-extension content-security-policy