firefox - Chrome 是否违反了内容安全政策?

标签 firefox google-chrome-extension content-security-policy content-script

我为 chrome 和 firefox 制作了一个浏览器扩展。 firefox one 是使用 Web Extension APIs 开发的因此这两个扩展中的代码差异很小。作为扩展中的一个重要功能,一些 HTML 元素通过内容脚本成为网页的一部分。这还涉及加载托管在某些服务器上并通过 https 提供的图像。现在,当扩展在 twitter 和 github 上运行时,这些图像在 chrome 中加载良好。但是,有趣的是,当相应的扩展在 twitter 和 github 上运行时,图像根本没有加载到 firefox 中。更有趣的是,twitter 在其响应 header 中设置的内容脚本策略禁止该图像加载,因此 firefox 的行为是正确的。所以,我的问题基本上是 Chrome 是否在这里违反了 CSP?

在此处附加 twitter 设置的 csp--

script-src 'nonce-j0GK1zjoBy82/ZWhR7gw+g==' https://connect.facebook.net https://cm.g.doubleclick.net https://ssl.google-analytics.com https://graph.facebook.com https://twitter.com 'unsafe-eval' https://.twimg.com https://api.twitter.com https://analytics.twitter.com https://publish.twitter.com https://ton.twitter.com https://syndication.twitter.com https://www.google.com https://t.tellapart.com https://platform.twitter.com https://www.google-analytics.com 'self'; frame-ancestors 'self'; font-src https://twitter.com https://.twimg.com data: https://ton.twitter.com https://fonts.gstatic.com https://maxcdn.bootstrapcdn.com https://netdna.bootstrapcdn.com 'self'; media-src https://twitter.com https://.twimg.com https://ton.twitter.com blob: 'self'; connect-src https://graph.facebook.com https://.giphy.com https://.twimg.com https://pay.twitter.com https://analytics.twitter.com https://media.riffsy.com https://upload.twitter.com https://api.mapbox.com 'self'; style-src https://fonts.googleapis.com https://twitter.com https://.twimg.com https://translate.googleapis.com https://ton.twitter.com 'unsafe-inline' https://platform.twitter.com https://maxcdn.bootstrapcdn.com https://netdna.bootstrapcdn.com 'self'; object-src https://twitter.com https://pbs.twimg.com; default-src 'self'; frame-src https://staticxx.facebook.com https://twitter.com https://.twimg.com https://player.vimeo.com https://pay.twitter.com https://www.facebook.com https://ton.twitter.com https://syndication.twitter.com https://vine.co twitter: https://www.youtube.com https://platform.twitter.com https://upload.twitter.com https://s-static.ak.facebook.com 'self' https://donate.twitter.com; img-src https://graph.facebook.com https://.giphy.com https://twitter.com https://.twimg.com data: https://fbcdn-profile-a.akamaihd.net https://www.facebook.com https://ton.twitter.com https://.fbcdn.net https://syndication.twitter.com https://media.riffsy.com https://www.google.com https://stats.g.doubleclick.net https://*.tiles.mapbox.com https://www.google-analytics.com blob: 'self'; report-uri https://twitter.com/i/csp_report?a=NVQWGYLXFVZXO2LGOQ%3D%3D%3D%3D%3D%3D&ro=false;



请注意这里的“img-src”。另一个困扰我的问题是该扩展程序在 list 文件中还指定了自己的内容脚本策略。这两项政策如何协同作用?

最佳答案

如果他们真的想要,扩展可以覆盖页面的 CSP,但假设没有这样的响应头手术,页面的 CSP 仍然主要受到尊重。
我最近回答了 CSP in extensions ,并将在此处部分复制它:

There are 3 CSPs at play in extensions:

  • content_security_policy directive only applies for extension's own pages (such as the background page). If not specified, it defaults to script-src 'self'; object-src 'self' and has some restrictions on how it can be modified.

  • Content script context is not subject to this CSP. unsafe-eval is unrestricted (since you can do executeScript with arbitrary code anyway), however, inline script and remote script restrictions just don't apply to content scripts, because:

  • Any script in the DOM of the page, be it inline or <script src="..."> tag is executed in the context of the page itself and is subject to the CSP of the page itself. There is precisely one exception, injecting a <script> /* code */ </script> in the page will bypass inline code restrictions for immediate execution.


请注意,所有这些都涵盖了脚本。我不确定图像如何受到影响。我不知道任何涵盖此内容的文档。
请注意,扩展通常会覆盖某些 Web 安全功能,例如 CORS。

关于firefox - Chrome 是否违反了内容安全政策?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37273306/

相关文章:

javascript - Cordova InAppBrowser executeScript回调

javascript - 在 Firefox 扩展的代码中使用 Firebug

security - 在 Firefox 中添加证书异常(exception)是否会告诉它信任证书、地址或两者的组合?

google-chrome - 源 map 可用于Chrome扩展程序吗?

javascript - SignalR 拒绝连接到 [url],因为它违反了以下内容安全策略指令

content-security-policy - 在哪里指定内容安全策略 (CSP) : on a backend or on a frontend?

ajax - FireFox 何时支持 websocket?

Javascript 返回月份为 9,其中 10

javascript - chrome.tabs.onUpdated.addListener - 立即报告changeInfo.status == 'complete'

google-chrome - 在 Google Chrome 上强制安装的扩展程序(GPO 不适用于某些扩展程序)(Flashcontrol)