我正在开发一个 Chrome 插件,其中从多个域加载外部脚本。我已经查看了有关如何允许这些域的文档和一些教程。
我检查过的文档:
- http://developer.chrome.com/extensions/contentSecurityPolicy.html
- http://www.html5rocks.com/en/tutorials/security/content-security-policy/
- http://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#syntax
一切都是一样的,我在manifest.json中创建了这个规则:
{
// .. general settings
"content_security_policy": "script-src 'self' https://ajax.googleapis.com http://mysite.com; object-src 'self'"
}
对此 Chrome 做出以下响应:
Could not load extension from '/Users/itarato/Desktop/DRC Tutorial Client'.
Invalid value for 'content_security_policy': Both 'script-src' and 'object-src' directives must be specified (either explicitly, or implicitly via 'default-src'), and both must whitelist only secure resources.
You may include any of the following sources: "'self'", "'unsafe-eval'", "http://127.0.0.1", "http://localhost", or any "https://" or "chrome-extension://" origin.
For more information, see http://developer.chrome.com/extensions/contentSecurityPolicy.html
当然,我尝试了几种组合,但都失败了。仅当我仅使用一个域时它才有效。我怎样才能添加更多?
最佳答案
您的语法很好,问题是您的 http://mysite.com
源不安全。 Chrome 错误消息中的“仅将安全资源列入白名单”部分指的是这一点。您需要使用 https://mysite.com
。
关于google-chrome-extension - 如何在 Chrome 插件中将多个域添加到 content_security_policy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12822974/