XDomainRequest 可以与 SSL 一起使用吗?

发布于 2024-09-04 23:34:03 字数 933 浏览 4 评论 0 原文

我有在 IE8 中使用 Microsoft 的 XDomainRequest 对象的代码。代码如下所示:

var url = "http://<host>/api/acquire?<query string>";  
var xdr = new XDomainRequest();  
xdr.onload = function(){  
    $.("#identifier").text(xdr.responseText);  
};  
xdr.open("GET", url);  
xdr.send();  

当“url”中的方案为“http://”时,该命令可以正常工作。然而,当方案是“https://”时,IE8 会给我一个“访问被拒绝”的 JavaScript 错误。这两种方案在 FF 3.6.3 中都可以正常工作,当然,我使用的是 XmlHttpRequest。对于这两种浏览器,我都遵守 W3C 访问控制。 “http://”对于两种浏览器都可以跨源工作。所以问题出在 IE8、XDomainRequest 和 SSL 上。

SSL 证书不是问题。如果我在 IE8 的地址栏中输入 https://>/,其中 >与上面的“url”相同,页面加载正常。

所以我们有以下内容:
- 直接从浏览器点击 https://>/ 效果很好;
- 点击 https://>/api/acquire?>不允许通过 XDomainRequest。

能做到吗?我遗漏了什么吗?

I have code that uses Microsoft's XDomainRequest object in IE8. The code looks like this:

var url = "http://<host>/api/acquire?<query string>";  
var xdr = new XDomainRequest();  
xdr.onload = function(){  
    $.("#identifier").text(xdr.responseText);  
};  
xdr.open("GET", url);  
xdr.send();  

When the scheme in "url" is "http://" the command works fine. However, when the scheme is "https://" IE8 gives me an "Access denied" JavaScript error. Both schemes work fine in FF 3.6.3, where I am, of course, using XmlHttpRequest. With both browsers I am complying with W3C Access Control. "http://" works cross origin for both browsers. So the problem is with IE8, XDomainRequest, and SSL.

The SSL certificate is not the problem. If I type https://<host>/ into the address bar of IE8, where <host> is the same as in "url" above, the page loads fine.

So we have the following:
- hitting https://<host>/ directly from the browser works fine;
- hitting https://<host>/api/acquire?<query string> via XDomainRequest is not allowed.

Can it be done? Am I leaving something out?

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

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

发布评论

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

评论(1

美羊羊 2024-09-11 23:34:03

显然,答案就在这里: 链接

此页面上的第 7 点表示:“请求必须针对与托管页面相同的方案。”

以下是第 7 点的一些支持文字:

“我们的目的绝对是阻止 HTTPS 页面
XDomainRequests 用于基于 HTTP 的资源,因为该场景呈现了
许多开发人员和大多数用户都面临的混合内容安全威胁
没看懂。

但是,这个限制过于宽泛,因为它阻止了 HTTP
发出针对 HTTPS 页面的 XDomainRequests 的页面。虽然它是
确实,HTTP 页面本身可能已被泄露,但没有
应禁止其接收公共资源的理由
安全地。”

看来,我原来问题的答案是:是,如果托管页面可以使用“https://”方案;否,如果不能。

Apparently, the answer is here: Link

Point 7 on this page says, "Requests must be targeted to the same scheme as the hosting page."

Here is some of the supporting text for point 7:

"It was definitely our intent to prevent HTTPS pages from making
XDomainRequests for HTTP-based resources, as that scenario presents a
Mixed Content Security Threat which many developers and most users do
not understand.

However, this restriction is overly broad, because it prevents HTTP
pages from issuing XDomainRequests targeted to HTTPS pages. While it’s
true that the HTTP page itself may have been compromised, there’s no
reason that it should be forbidden from receiving public resources
securely."

It would appear at present that the answer to my original question is: YES, if the hosting page can use the "https://" scheme; NO, if it cannot.

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