使用 iframe sandbox 时的注意点

来源:互联网 发布:python 正无穷大 编辑:程序博客网 时间:2024/04/30 02:49

一、allow-scripts 允许执行js

二、allow-same-origin 同源,允许父子页面共享cookie, 互相操作.

三、当被嵌入的文档与主页面同源时,强烈建议不要同时使用 allow-scripts 和allow-same-origin ,否则的话将允许嵌入的文档通过代码删除 sandbox 属性。虽然你可以这么做,但是这样的话其安全性还不如不用sandbox。

四、使用src=”data:……”, srcdoc=”….” 直接设置iframe 内容时的区别:

1. src 的data:text/html是 Data URI, 长度不能超过32,7682. 同时使用时srcdoc优先级更高3. 当前 IE 不支持 srcdoc [浏览器支持](http://caniuse.com/#feat=iframe-srcdoc)4. srcdoc更安全

五、postMessage可用于父子窗口安全地传递消息

参考资料:
https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/iframe

http://stackoverflow.com/questions/19739001/which-is-the-difference-between-srcdoc-and-src-datatext-html-in-an

浏览器同源政策及其规避方法

https://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/

0 0
原创粉丝点击