首页 > 解决方案 > 有没有办法在我的网站的 Content-Security-Policy 中包含一个 firefox 扩展弹出窗口?

问题描述

我想在 Firefox 扩展的弹出窗口中嵌入 iframe,但我得到“ Firefox 无法打开此页面 - 为了保护您的安全,如果其他站点嵌入了该页面,www.example.com将不允许 Firefox 显示该页面。 ",这是因为站点 example.com 已经配置 Content-Security-Policyframe-ancestors 'self'. 我可以将其更改为,frame-ancestors *但我想要不那么广泛的内容。

标签: firefox-addoncontent-security-policyfirefox-addon-webextensions

解决方案


这取决于您的弹出窗口的来源(在<iframe src=或 中指定的内容<iframe srcdoc=
一些来源是 CSP 规定的主题,另一些则不是。例如,供应商的方案(如moz-extension:/ )chrome:应该绕过 CSP。

'self' 标记也可能非常阴险:

,----------------- parent HTTP://example.com --------------------,
|                                                                |
|  * Host-source is HTTP://example.com with the HTTP: scheme     |
|                                                                |
|  <iframe src='HTTPS://example.com'>                            |
|   Content-Security-Policy: frame-ancestors 'self'              |
|                                                                |
|    * 'self' would be substituted by HTTPS://example.com, it    |
|     means that you actually have the header:                   |
|   Content-Security-Policy: frame-ancestors HTTPS://example.com |
|     therefore it will block embedding into parent with         |
|     HTTP://example.com because of schemes mismatch             |
|     (HTTP: !== HTTPS:)                                         |
|                                                                |
|  <iframe>                                                      |
|________________________________________________________________|

但相反的情况(使用 HTTPS: 的父级和使用 HTTP: 的 iframe)不会在 CSP3 浏览器中导致问题(但会在 CSP2 浏览器中导致)。


推荐阅读