Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在iFrame上使用CSP_Javascript_Html_Css_Sandbox_Content Security Policy - Fatal编程技术网

Javascript 如何在iFrame上使用CSP

Javascript 如何在iFrame上使用CSP,javascript,html,css,sandbox,content-security-policy,Javascript,Html,Css,Sandbox,Content Security Policy,我使用iFrame来包含外部html源代码https://good.com/main.html <iframe src=“https://good.com/main.html" scrolling="no" style="overflow: hidden; height: 700px;"></iframe> 有没有办法阻止good.com/main.html导入和执行bad.com/c.js?更具体地说,防止任何与https://good.com 我试着用沙箱把iFra

我使用iFrame来包含外部html源代码
https://good.com/main.html

<iframe src=“https://good.com/main.html" scrolling="no" style="overflow: hidden; height: 700px;"></iframe>
有没有办法阻止
good.com/main.html
导入和执行
bad.com/c.js
?更具体地说,防止任何与
https://good.com

我试着用沙箱把iFrame装起来

<iframe sandbox=“allow-same-origin allow-scripts” src=“https://good.com/main.html” scrolling="no" style="overflow: hidden; height: 700px;"></iframe>

但它仍然导入并执行
https://bad.com/c.js

有没有办法防止源代码导入和执行任何外部js


我读过,但我不确定它的用法。

广义上说,你不能。iFrame有自己的CSP,您无法从父页面传入策略

也就是说,您在问题中链接到的iframe元素的“csp”属性在某种程度上允许这样做。它允许您请求iframe源应用您在“CSP”属性中设置的CSP;但是你不能强制执行它,仅仅要求。所以理论上你可以做:

iframe的源可能实现也可能不实现您请求的CSP


注意,这是全新的,而且(据报道)仅在Chrome和Opera中受支持。

有没有办法在现有的iFrame和沙盒上构建一个包装器来实现这一点?我想您可以使用cUrl获取页面内容,并直接在您自己的页面上输出内容。值得一试
<iframe sandbox=“allow-same-origin allow-scripts” src=“https://good.com/main.html” scrolling="no" style="overflow: hidden; height: 700px;"></iframe>