I know this has been asked before in various forms, but I can't seem to get around the problem. I have tried using both jQuery and the native JS API to make the Ajax requests.
My situation is the following (see attached diagram):
Before anybody starts a lecture on cross-domain requests let me state a couple of things:
Access-Control-Allow-Origin
header in the response (and I am using Chrome and Firefox, both of which support CORS)So, why, why, why doesn't the browser pass on the cookie when making the HTTPS Ajax call? Any ideas? I am about to lose my mind...
+-----------+ HTTP Request +-----------+ |Browser |+---------------->|Server | +-----------+ +-----------+ HTTP Response <----------------+ Set-cookie Ajax HTTP Req. +----------------> Cookie (OK) HTTP Response <----------------+ Set-cookie (OK) Ajax HTTPS Req. +----------------> No Cookie (!!!)
If I navigate to the url with Chrome I'm able to get the response. I see no reason why it shouldn't work work over an ajax request. It's looks like a cross-origin issue, not HTTPS. Whatever code you've used, you should provide that with some context on the URL in relation to the page/site it's running in.
AJAX calls only send Cookies if the url you're calling is on the same domain as your calling script.
An AJAX request is a request made by an AJAX application. Typically, it is an HTTP request made by (browser-resident) Javascript that uses XML to encode the request data and/or response data.
There is nothing inherently insecure about AJAX, for the most part it is susceptible to most of the same threats and attacks as regular webpages. However, there are also a few attacks that are AJAX-specific, but again it depends on how you code it.
Ok, found the solution to the cookie problem.
See XHR specs, jQuery docs and StackOverflow.
The solution to have the cookies sent when switching protocol and/or subdomain is to set the withCredentials
property to true
.
E.g. (using jQuery)
$.ajax( { /* Setup the call */ xhrFields: { withCredentials: true } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With