如何让allow-scripts和allow-same-origin在iframe中共存?

问题描述 投票:0回答:1

所以我只想在 iframe 中沙箱一个 html 文件,只要有

allow-scripts
属性它就可以工作,但是一旦我添加
allow-same-origin
它就停止工作,因为:

关于沙盒的注意事项: 当嵌入文档与嵌入页面具有相同来源时,强烈建议不要同时使用 allow-scriptsallow-same-origin,因为这会让嵌入文档删除沙箱属性 — 使其不可用比根本不使用沙箱属性更安全。 如果攻击者可以在沙盒 iframe 之外显示内容,例如查看者在新选项卡中打开该框架,那么沙盒就没用了。此类内容也应从单独的来源提供,以限制潜在的损害。 Internet Explorer 9 及更早版本不支持沙箱属性。来自:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe

iframe代码:

<iframe src="index.html" sandbox='allow-scripts allow-same-origin'></frame>

我想要

allow-same-origin

因为我想在iframe中使用与index.html中相同的css。

html iframe firefox-addon sandbox firefox-addon-webextensions
1个回答
4
投票
将 iframe 内容托管在与父页面不同的源(即不同的域或子域)上。这将在使用

sandbox="allow-scripts allow-same-origin"

 时保持 iframe 的安全。

但无论哪种方式,CSS 都不会在 iframe 中继承。事实上,这就是 iframe 的全部目的。即使没有设置

allow-same-origin

,您也可以在两个页面中加载相同的 CSS 文件。

© www.soinside.com 2019 - 2024. All rights reserved.