admin管理员组文章数量:1434929
I am using an iFrame to contain an external html source .html
<iframe src=“.html" scrolling="no" style="overflow: hidden; height: 700px;"></iframe>
But good/main.html
imports and executes the following javascript
.js
.js
.js
Is there a way to prevent good/main.html
importing and executing bad/c.js
? More specifically, prevent any resource that does not have the same domain as ?
I tried sandboxing the iFrame
<iframe sandbox=“allow-same-origin allow-scripts” src=“.html” scrolling="no" style="overflow: hidden; height: 700px;"></iframe>
But it still imports and executes the .js
Is there a way to prevent the source from importing and executing any external js?
I read about CSPs on iFrames, but I am unsure of it’s usage.
I am using an iFrame to contain an external html source https://good./main.html
<iframe src=“https://good./main.html" scrolling="no" style="overflow: hidden; height: 700px;"></iframe>
But good./main.html
imports and executes the following javascript
https://good./a.js
https://good./b.js
https://bad./c.js
Is there a way to prevent good./main.html
importing and executing bad./c.js
? More specifically, prevent any resource that does not have the same domain as https://good.
?
I tried sandboxing the iFrame
<iframe sandbox=“allow-same-origin allow-scripts” src=“https://good./main.html” scrolling="no" style="overflow: hidden; height: 700px;"></iframe>
But it still imports and executes the https://bad./c.js
Is there a way to prevent the source from importing and executing any external js?
I read about CSPs on iFrames, but I am unsure of it’s usage.
Share Improve this question edited May 30, 2019 at 14:50 RPT asked May 30, 2019 at 12:05 RPTRPT 7482 gold badges13 silver badges30 bronze badges 01 Answer
Reset to default 6Broadly speaking, you can't. Iframes have their own CSP and you can't pass a policy in from the parent page.
That said, the "csp" attribute of the iframe element, that you link to in the question, somewhat allows this. It allows you to request that the iframe source apply the CSP that you set in the "csp" attribute; but you can't enforce it, merely ask. So you can theoretically do:
<iframe csp="default-src 'none';" ...>
The source of the iframe may or may not implement the CSP you request.
Note this is brand new and is (reportedly) only supported in Chrome and Opera.
本文标签: javascriptHow to use CSPs on iFramesStack Overflow
版权声明:本文标题:javascript - How to use CSPs on iFrames - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745626928a2667028.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论