从服务器 A 迁移到 B 后,Opera 11.01 出现 JS 安全问题

发布于 2024-10-28 19:15:44 字数 960 浏览 4 评论 0原文

我有一个带有 iFrame 的外部 HTML 文档 (subdomain1.server-a.de) 和一个内部 HTML 文档 (subdomain2.server-a.de)。内部脚本应发送 &接收对 subdomain2.server-a.de 的 AJAX 请求。我已将两个文档的 document.domain-value 设置为“server-a.de” - 到目前为止,效果很好,在所有测试的浏览器(FF/Chrome/Opera)中运行良好。现在,我将脚本移至具有相同子域的 server-b.de,并将两个文档上的 document.domain 设置为“server-b.de”。这在 FF 和 Chrome 中仍然有效,但当尝试从外部文档调用我的 AJAX 函数时,Opera 给了我一个“安全错误:试图读取受保护的变量:xy”。

到目前为止我的结论是:我不能违反相同的域策略,因为这样 FF 和 Chrome 也不会从外部与内部文档进行通信。我还尝试了 Focus with Cross-domain Ajax in Opera 使用间隔函数,同样的问题。

预先非常感谢您的每一个提示。

更新:我已经为此建立了一个测试站点。如果您访问此网站,您会发现,它甚至可以与 Opera 一起使用(一个对话框)几秒钟后会弹出“测试已调用”)。现在,如果您将外部框架文件“operatest.html”和 jquery 复制到另一台服务器 - 所以它必须在我的情况下工作 - 您会看到,FF 和 Chrome 没有问题,但 Opera 有。

Opera 是否会比较服务器详细信息以履行同源策略?或者如果两个子域的 IP 地址不匹配,它会拒绝访问吗?

I have a outer HTML-document (subdomain1.server-a.de) with an iFrame and inner HTML-document (subdomain2.server-a.de). The inner script should send & receive AJAX-requests to subdomain2.server-a.de. I've set the document.domain-value for both documents to "server-a.de" - so far, so good, works well in all tested browsers (FF/Chrome/Opera). Now I move the scripts to server-b.de with same subdomains and set the document.domain on both documents to "server-b.de". That still works in FF and Chrome, but Opera gives me a "Security error: attempted to read protected variable: xy" when trying to call my AJAX function from the outer document.

My conclusion so far: I can't violate the same domain policy, because then FF and Chrome wouldn't communicate with the inner document from outside either. I've also tried the solution from Focus with Cross-domain Ajax in Opera with the interval function, same issue.

Thanks a lot in advance for every hint.

UPDATE: I have set up a testing site for this. If you go to this site, you'll see, it works even with Opera (a dialog pops up with "Test called" after a few seconds). Now, if you copy the outer frame files "operatest.html" and jquery to another server - so it has to work in my case - you'll see, that FF and Chrome don't have a problem, but Opera has.

Is Opera comparing server details in order to fulfill the same origin policy? Or will it deny access, if ip adresses of both subdomains don't match?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

柠檬色的秋千 2024-11-04 19:15:44

听起来可能是一个计时问题,即外部文档尝试在内部文档运行设置 document.domain 的脚本之前发起请求?或者也许 Opera 已经缓存了 IFRAME 内容,而您最初加载的版本中 IFRAME 内的脚本是错误的并且没有正确设置 document.domain?

Sounds like it might be a timing issue, i.e. the outer document tries to initiate the request before the inner document has run the script that sets document.domain?? Or perhaps Opera has cached the IFRAME contents and you initially loaded a version where the script inside the IFRAME was wrong and didn't set document.domain correctly?

七度光 2024-11-04 19:15:44

我建议您忘记 document.domain 方法并使用 window.postMessage() (又名 HTML5 风格的跨文档消息传递)。
http://www.whatwg.org /specs/web-apps/current-work/multipage/comms.html#web-messaging

I suggest you forget the document.domain approach and use window.postMessage() (AKA HTML5-style cross-document messaging) instead.
http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#web-messaging

哀由 2024-11-04 19:15:44

在不同子域上的父级和 iframe 之间的 JS 调用也存在同样荒谬的问题 - 在任何地方都可以工作,但在 Opera 下失败并出现上述错误。

删除 ~/.opera 文件夹(Linux 中的 Opera 设置文件夹)解决了这个问题,以及另一个非常奇怪的问题。

干杯。

Had the same absurd issue with JS calls between parent and an iframe on a different subdomain - worked everywhere, but failed under Opera with the above mentioned error.

Removing ~/.opera folder (Opera settings folder in Linux) solved this, and another one very weird problem.

Cheers.

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