javascript 带有“允许同源”标志错误的 iframe 沙箱
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30183320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Iframe sandboxing with 'allow-same-origin' flag error
提问by hshantanu
Can someone please provide me more information on this error and how 'allow-same-origin' flag works? I am getting following error in Chrome for iframe Sandboxing:
有人可以向我提供有关此错误的更多信息以及“允许同源”标志的工作原理吗?我在 Chrome for iframe Sandboxing 中遇到以下错误:
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Sandbox access violation: Blocked a frame at "http://192.168.0.169" from accessing a frame at "http://192.168.0.169". The frame being accessed is sandboxed and lacks the "allow-same-origin" flag.
未捕获的SecurityError:未能读取从“HTMLIFrameElement”的“contentDocument”属性:沙盒访问冲突:在“阻止帧http://192.168.0.169”从“访问帧http://192.168.0.169”。被访问的框架是沙盒的,没有“允许同源”标志。
I am little confused as why I would need 'allow-same-origin' flag when frame from 192.168.0.169 is accessing another frame from same ip address. Thank you very much.
当来自 192.168.0.169 的帧正在访问来自相同 IP 地址的另一个帧时,为什么我需要“允许相同来源”标志,我有点困惑。非常感谢你。
回答by MoLow
You probably have a sandbox attribute in your iframe:
您的 iframe 中可能有一个沙箱属性:
The sandbox attribute enables an extra set of restrictions for the content in the iframe, and it is a whitelist of enabled permissions,
sandbox 属性为 iframe 中的内容启用一组额外的限制,它是一个启用权限的白名单,
so You could either remove the attribute, or edit it to fit the permissions You need.
所以您可以删除该属性,也可以对其进行编辑以适应您需要的权限。
optional permissions could be found here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
可在此处找到可选权限:https: //developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
and some more info here: http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/
以及更多信息:http: //www.html5rocks.com/en/tutorials/security/sandboxed-iframes/