简体   繁体   English

为什么 IE XDomainRequest 不发送 Referer 标头

[英]Why IE XDomainRequest does not send Referer header

When I am doing CORS in IE via XDomainRequest object, the Referer HTTP header is not being sent.当我通过 XDomainRequest 对象在 IE 中执行 CORS 时,不会发送 Referer HTTP 标头。 Is there any official documentatation covering this?是否有任何官方文档涵盖这一点? I fully understand, that relying on Referer HTTP header is basicaly wrong idea, however without hard evidence I am stuck here, and not able to prove our architect wrong.我完全理解,依赖 Referer HTTP 标头基本上是错误的想法,但是没有确凿的证据我被困在这里,并且无法证明我们的架构师是错误的。

Example dump:示例转储:

IE Request IE 请求

GET http://example.com/some/url HTTP/1.1
Accept: */*
Origin: http://another.domain.com
Accept-Language: sk-SK
UA-CPU: AMD64
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)
Host: example.com
Connection: Keep-Alive
Pragma: no-cache

Chrome Request铬请求

GET http://example.com/some/url HTTP/1.1
Host: example.com
Connection: keep-alive
Origin: http://another.domain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36
Accept: */*
Referer: http://another.domain.com/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: sk-SK,sk;q=0.8,cs;q=0.6,en-US;q=0.4,en;q=0.2

Eric Law (former IE program manager) answered this in his blog post, as expected limitation comming back from IE8 times: Eric Law(前 IE 项目经理)在他的博客文章中回答了这个问题,正如预期的那样,限制从 IE8 时代回来了:

we wanted to ensure that the XDomainRequest object would not allow an attacker to issue a request that a HTML Form could not issue.我们希望确保 XDomainRequest 对象不会允许攻击者发出 HTML 表单无法发出的请求。 This is important because the Access-Control-Allow-Origin header isn't available until after the response is returned, so there's no way to tell before the request is issued whether or not the server is willing to accept cross-domain HTTP requests.这很重要,因为 Access-Control-Allow-Origin 标头在返回响应之后才可用,因此在发出请求之前无法判断服务器是否愿意接受跨域 HTTP 请求。 Without these restrictions, a “Fire and Forget” CSRF attack could take place against a legacy server, even if the server doesn't return the Access-Control-Allow-Origin header如果没有这些限制,即使服务器不返回 Access-Control-Allow-Origin 标头,也可能对旧服务器进行“即发即弃”CSRF 攻击

http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

Cross-domain requests ("XDRs") are anonymous to protect user data.跨域请求(“XDR”)是匿名的,以保护用户数据。 This means that servers cannot easily determine who is requesting data.这意味着服务器无法轻松确定谁在请求数据。 To protect user privacy, respond with cross-domain data that is neither sensitive nor personally identifiable.为保护用户隐私,请使用既不敏感也不可识别个人身份的跨域数据进行响应。 To help prevent intranet data from being leaked to malicious Internet sites, we discourage intranet sites from making XDR data available.为了帮助防止 Intranet 数据泄露到恶意 Internet 站点,我们不鼓励 Intranet 站点提供 XDR 数据。 So the IE some times prevent XDomainRequest object due to security resons.因此,IE 有时会出于安全原因阻止 XDomainRequest 对象。

According to Microsoft's own page, you can use this new object to avoid this problem:根据微软自己的页面,你可以使用这个新对象来避免这个问题:

/ / 1. Create XDR object
XDomainRequest xdr = new ();

/ / 2. Open the connection to the server using the POST method
xdr.open ("POST", "http://www.example.com/xdr.txt");

/ / 3. We send information to the server
xdr.send ("data to be processed");

According to W3C, you can use this根据 W3C,你可以使用这个

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.example.com/.../datos.php", true);
xhr.onreadystatechange = function(){
  if ( xhr.readyState == 4 ) {
    if ( xhr.status == 200 ) {
      document.body.innerHTML = "Reply: " + xhr.responseText;
    } else {
      document.body.innerHTML = "ERROR";
    }
  }
};
xhr.send(null);

There is also a library for IE8 and IE9, to avoid this problem, but you should use jquery Ajax https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest还有一个 IE8 和 IE9 的库,以避免这个问题,但你应该使用 jquery Ajax https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM