I'm trying to understand why cross-domain requests without credentials are not allowed (by default, without setting up a server to return the Access-Control-Allow-Origin header). When a request has credentials all is pretty straightforward - one can fulfill some malicious actions on your behalf on other sites, for example on Facebook, if you have logged in on it.
For example, the request
xhr = new XMLHttpRequest();
xhr.open('GET', 'http://www.google.com');
xhr.send();
produces the error (I executed it in Chrome's console from this site):
XMLHttpRequest cannot load http://www.google.com/. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://stackoverflow.com' is therefore not allowed
access.
So, the server must send an appropriate header (e.g Access-Control-Allow-Origin: * ) to this request can work.
This is just a simple request and no cookies are sent. What's the reason for such a restriction? What security issues might take place if such CORS will be allowed?
without credentials - without cookies:
default settings for XMLHTTPRequest is withCredentials = false
, so no cookies are sent in the request - link.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…