在不违反 SOP 的情况下设置 document.domain

发布于 2024-11-02 17:38:51 字数 503 浏览 8 评论 0原文

我试图弄清楚在不违反 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无敌元气妹 2024-11-09 17:38:51

除非发生其他情况,否则设置 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 with document.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文