"Refused to frame" 仅在 Chrome 中有 2 个深度 iFrame 错误
"Refused to frame" error with 2 deep iFrame only in Chrome
我有一个托管 iFrame 的网站,该 iFrame 在其中托管另一个 iFrame,因此 iFrame 有 2 个深度。当我在 Chrome 上 运行 时,出现以下错误并且最低级别的 iFrame 不显示,但中间层确实显示。当我使用 Firefox 访问它时,一切正常,控制台不记录任何错误。
Chrome 控制台错误:
Refused to frame 'site1' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' site1 site2 site3".
正如您从错误消息中看到的那样,我将链中的所有级别都引用为 header 中的框架祖先,因此我无法在此处列出更多站点。此外,如果我尝试在 Chrome 中打开中间网站而没有最上面的 parent,一切正常,显示最低级别的 iFrame。谁能就我可能遗漏的内容提供任何提示?
When I access it using Firefox, everything works and the console does not log any errors.
Firefox 在控制台中出现 bug with logging frame-ancestor
错误。
Chrome console error: Refused to frame 'site1' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' site1 site2 site3"
.
这很奇怪,因为 Chrome 肯定 allows nested iframe 在 frame-ancestors
指令中指定了上游 DOM 帧的所有 host-sources。
也许在您的“site1 site2 site3”中提供了 data:
来源?
或者一些嵌套的 iframe 发布 X-Frame-Options
header?
是的,frame-ancestors
指令很复杂而且有问题,但我认为你的问题中有一些隐藏的细节。
原来这都是我的错。我不理解 frame-ancestors 和 frame-src 之间的区别。我什至没有意识到有两套不同的价值观。一旦我通过使用 frame-ancestors 列出父域并使用 frame-src 列出子域来解决这个问题,一切都按应有的方式工作。
我有一个托管 iFrame 的网站,该 iFrame 在其中托管另一个 iFrame,因此 iFrame 有 2 个深度。当我在 Chrome 上 运行 时,出现以下错误并且最低级别的 iFrame 不显示,但中间层确实显示。当我使用 Firefox 访问它时,一切正常,控制台不记录任何错误。
Chrome 控制台错误:
Refused to frame 'site1' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' site1 site2 site3".
正如您从错误消息中看到的那样,我将链中的所有级别都引用为 header 中的框架祖先,因此我无法在此处列出更多站点。此外,如果我尝试在 Chrome 中打开中间网站而没有最上面的 parent,一切正常,显示最低级别的 iFrame。谁能就我可能遗漏的内容提供任何提示?
When I access it using Firefox, everything works and the console does not log any errors.
Firefox 在控制台中出现 bug with logging frame-ancestor
错误。
Chrome console error: Refused to frame 'site1' because an ancestor violates the following Content Security Policy directive:
"frame-ancestors 'self' site1 site2 site3"
.
这很奇怪,因为 Chrome 肯定 allows nested iframe 在 frame-ancestors
指令中指定了上游 DOM 帧的所有 host-sources。
也许在您的“site1 site2 site3”中提供了 data:
来源?
或者一些嵌套的 iframe 发布 X-Frame-Options
header?
是的,frame-ancestors
指令很复杂而且有问题,但我认为你的问题中有一些隐藏的细节。
原来这都是我的错。我不理解 frame-ancestors 和 frame-src 之间的区别。我什至没有意识到有两套不同的价值观。一旦我通过使用 frame-ancestors 列出父域并使用 frame-src 列出子域来解决这个问题,一切都按应有的方式工作。