Standards are also helpless, and they are difficult to achieve
Secure by default.
In the latest W3C standard, HTTP cross-origin requests are implemented in this way,
Cross-origin Resource Sharing
To put it simply, the cross-origin target server must return a series of headers to control whether to agree to cross-origin.
These headers include:
- 4
Syntax
- 4.1
Access-Control-Allow-OriginHTTP Response Header
- 4.2
Access-Control-Max-AgeHTTP Response Header
- 4.3
Access-Control-Allow-CredentialsHTTP Response Header
- 4.4
Access-Control-Allow-MethodsHTTP Response Header
- 4.5
Access-Control-Allow-HeadersHTTP Response Header
- 4.6
OriginHTTP Request Header
- 4.7
Access-Control-Request-MethodHTTP Request Header
- 4.8
Access-Control-Request-HeadersHTTP Request Header
There are some in the request package and response package.
The most sensitive one isAccess-control-allow-Origin
This header is used in W3C standards to check whether the cross-origin request can be passed.(Access Control Check)
The cross-origin implementation process is roughly as follows:
SlaveHttp://www.a.com/test.htmlInitiate a cross-origin request,
The request address is:Http://www. B .com/test.php
IfServer BReturns the following header:
Access-control-allow-origin: http://www.a.com
Then, this cross-origin request from the http://www.a.com/test.html will be passed.
In this process, the request also carries the header:
Origin: http://www.a.com
However, what is terrible here is that the value of access-control-allow-origin can be a wildcard *
If it is *, you can receive requests from any source origin.
I can already imagine the terrible consequences of this feature being abused by programmers and used to create backdoors!
InFirefox 3.1 beta 2The packet capture is as follows:
Get http://www. B .com/test.php HTTP/1.1
HOST: www. B .com
User-Agent: Mozilla/5.0 (windows; U; Windows NT 5.1; ZH-CN; RV: 1.9.1b2) Gecko/20081201 Firefox/3.1b2 PAROS/3.2.13
Accept: text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8
Accept-language: ZH-CN, ZH; q = 0.5
Accept-charset: gb2312, UTF-8; q = 0.7, *; q = 0.7
Keep-alive: 300
Proxy-connection: keep-alive
Referer: http://www.a.com/test.html
Origin: http://www.a.com
Cache-control: Max-age = 0
HTTP/1.1 200 OK
Date: Thu, 15 Jan 2009 06:28:54 GMT
Server: Apache/2.0.63 (win32) PHP/5.2.6
X-powered-by: PHP/5.2.6
Access-control-allow-origin :*
Content-Length: 28
Content-Type: text/html
Cross Domain request test!
The two sections of code are roughly as follows:
Www.a.com/test.html:
<SCRIPT>
VaR client = new XMLHttpRequest ();
Client. Open ("get", "http://www. B .com/test.php ");
Client. onreadystatechange = function (){}
Client. Send (null );
</SCRIPT>
Www. B .com/test.php:
<? PHP
Header ("access-control-allow-origin :*");
?>
Cross Domain request test!
In addition to this header, you can also use other headers to control such as method and time. You can refer to the standard and do not go into details here.
For security reasons, cross-origin requests cannot access the document. Cookie object.
ForIE8 beta 2, Is throughXdomainrequestTo implement this cross-origin request
For example, the following code can be implemented:
VaR request = new xdomainrequest ();
Request. Open ("get", xdomainurl );
Request. Send ();
The other server is also required to return this header.
The IE developer published a small video today:
Http://ieblog.members.winisp.net/images/XdomainRequest-small.wmv
Currently, this cross-origin implementation requirement is supported.
Firefox 3.1 beta2
IE 8 beta2
It will take some time to become popular.
Finally, add a firefox3.1 cross-domain implementation instruction document:
Https://developer.mozilla.org/En/HTTP_access_control