使用 iframe sandbox 时的注意点

一、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,768
2. 同时使用时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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值