在不违反 SOP 的情况下设置 document.domain
我试图弄清楚在不违反 SOP 的情况下,从 iframe 加载内容时设置 document.domain='example.com'
是否有效。 在我的场景中,我在 www.example.com 上有一个 html 页面,它在 www.example.com/iframe (所有端口 80)上加载 iframe - 因此,据我了解,这里不需要设置 document.domain 属性。
在 FF3 中,从 iframe 流式传输的 javascript 代码不会执行,除非我在父页面和 iframe 上显式设置 document.domain
属性。在 FF4 中,这两种设置都不会执行。我也尝试过在主机名中使用 www 前缀 - 没有区别。 Firebug 显示,包含 标签完整内容的分块部分已被下载。
这是否意味着在不涉及子域或 xss 的情况下设置 document.domain
仍然有目的?
I'm trying to figure out whether setting document.domain='example.com'
serves purpose when loading content from iframes if the SOP wouldn't be violated anyway.
In my scenario I have a html page on www.example.com which loads an iframe on www.example.com/iframe (all port 80) - so, as I understand it, setting the document.domain property is unnecessary here.
In FF3, the javascript code streamed from the iframe does not execute though, unless I set the document.domain
property explicitly on both parent page and iframe. In FF4 it does not execute in either setting. I've also tried with the www prefix in the hostname - no difference. Firebug reveals that a chunked part containing the full contents of a <script>
tag was downloaded though.
Does this mean that setting document.domain
still has a purpose when there's no subdomains or xss involved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非发生其他情况,否则设置
document.domain
不应对您的情况产生影响。我建议您不要触摸
document.domain
并尝试找到问题的真正原因。干预document.domain
只会在通过 iframe 等进行 AJAX 或文件上传时导致麻烦,因为这些不一定会选择新的域后缀。但要回答的是,不,它除了在跨子域通信时放松 SOP 之外没有其他目的。
Setting
document.domain
should not have an effect in your case unless something else is happening.I suggest you do not touch
document.domain
and try to find the real reason for your problem. Meddling withdocument.domain
will only lead to trouble when doing AJAX or file uploads via iframes and such, as these will not necessarily have opted into the new domain suffix.But to answer, no, it does not have a purpose other than loosening up the SOP when communicating across sub domains.