内容安全策略框架-祖先

use*_*836 10 security iframe mozilla frame content-security-policy

我正在尝试将内容加载到 IFrame 中,因此我实现了 Content-Security-Policy 标头:Content-Security-Policy:frame-ancestors http://*.example.com/abc.html。

当我将标头指定为 Content-Security-Policy:frame-ancestors http://*.example.com/ 时,我可以在 iframe 上加载内容。

但是当我将标题更改为:Content-Security-Policy:frame-ancestors self http://*.example.com/abc.html。然后 iframe 上的内容第一次加载,但当我刷新网页时出现以下错误

拒绝在框架中显示“https://...”,因为祖先违反了以下内容安全策略指令:frame-ancestors self http://*.example.com/abc.html。

谁能告诉我为什么刷新页面时会出错。框架祖先还考虑完整的 url (http:// .example.com/abc.html) 还是只考虑主机名,如 http:// .example.com?

gra*_*nty 8

Chrome 浏览器有一个错误- 它不支持frame-ancestors指令中的路径。Safari 也存在同样的错误,并且只有 Firefox 支持此指令中的路径。

因此,您必须使用主机源frame-ancestors来代替。 对于其他指令,您可以使用路径和文件名。http://.example.com/abc.htmlhttp://.example.com

  • 这是一个错误,因为 CSP 规范定义了 [主机源,包括路径](https://www.w3.org/TR/CSP3/#grammardef-host-source) 以及方案、端口号和文件名。另请注意,根据规范,“frame-ancestors”不支持通配符“*”,但在现实生活中它支持它。因此,规范并不总是最终的真相——浏览器可以用自己的方式解释它。 (3认同)