jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.13k stars 270 forks source link

IE8 Invalid Argument error - empty string Master and Slave cookies #180

Closed jessechk closed 8 years ago

jessechk commented 8 years ago

First of all, thanks for the great plugin, it makes working with old IE a little less miserable!

I ran into an issue with IE8 where I'm getting an Invalid Argument error in the IE console. This happens on line 477 of xdomain.js. I looked inside the request.headers array, and it seems that there are entries Master-Cookie: "", and Slave-Cookie: "". IE8 seems to be rejecting adding an empty string as a header value in xhr.setRequestHeader.

screen

I can't seem to reproduce this error on a standalone page, it only happens when I load a page from my WordPress project. I think the difference is that WP loads some cookies on the page. I don't need these cookies to be sent along with any requests however.

I tried setting xdomain.cookies = {master: null, slave: null}; but Master-Cookie: "" and Slave-Cookie: "" are still in the headers, which causes IE8 to crash the script.

I was able to fix this myself by changing line 447 from xhr.setRequestHeader(header, value); to if (value != "") xhr.setRequestHeader(header, value);

I'm not sure if there's a way to get rid of these empty headers in the first place.

jessechk commented 8 years ago

Ok, this seems to be part of your xhook library, perhaps I should move the issue there?

jpillora commented 8 years ago

Thanks for the report @jessechk

I just checked and sending:

var x = new XMLHttpRequest(); x.open("GET", "/"); x.setRequestHeader("Foo",""); x.send();

In chrome, sends an empty "Foo" header to the server, so it seems we need need to disallow it only in IE.

We'll need to determine which versions of IE don't support empty header values then we can put that if statement in.

If you could run that snippet in different versions of IE and report which versions error that would be great, otherwise I can look into it into next week

Edit: firefox seems to allow it (doesnt throw), though prevents it from actually going to the server https://bugzilla.mozilla.org/show_bug.cgi?id=929760

jessechk commented 8 years ago

I've tested IE 8-11 and none of them throw an error on that snippet. The error does trigger when the Foo value is an empty string in almost all browsers, however. I thought it might have to do with using $http in AngularJS - I created standalone tests and none of them seem to have an issue. This might be IE's JS engine being misleading about where the error really is. I'll do some more testing next week, but you can close this issue if you want.

jpillora commented 8 years ago

Ah right, my mistake - its the header name, not the value causing the issue – yep that should be disallowed

On Sat, Jan 30, 2016 at 2:19 PM Jesse Hoek notifications@github.com wrote:

I've tested IE 8-11 and none of them throw an error on that snippet. The error does trigger when the Foo value is an empty string in almost all browsers, however. I thought it might have to do with using $http in AngularJS - I created standalone tests and none of them seem to have an issue. This might be IE's JS engine being misleading about where the error really is. I'll do some more testing next week, but you can close this issue if you want.

— Reply to this email directly or view it on GitHub https://github.com/jpillora/xdomain/issues/180#issuecomment-177056031.

hyeonjames commented 7 years ago

I had same problem but I solved I added "document.cookie = '_a=3'" to my slave html (proxy.html) because in my case, Slave-Cookie was empty string and Master-Cookie was not.

I guess Empty string value is disallowed in IE8.