Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLHttpRequest: Content-Type can require a preflight #5070

Merged
merged 5 commits into from
Mar 9, 2017

Conversation

annevk
Copy link
Member

@annevk annevk commented Mar 8, 2017

Supersedes #4801.

@wpt-pr-bot wpt-pr-bot added the xhr label Mar 8, 2017
@wpt-pr-bot
Copy link
Collaborator

@annevk
Copy link
Member Author

annevk commented Mar 8, 2017

@bzbarsky you may want to review this since you last modified this test in https://bugzilla.mozilla.org/show_bug.cgi?id=1328761. I also think you may have introduced a same-origin policy violation in Firefox since you can't just preserve Content-Type when its value is not safelisted as per https://fetch.spec.whatwg.org/#cors-safelisted-request-header. I'm happy to file a bug by the way.

(As a side effect Chrome now passes all these tests and Safari only fails two.)

@ghost
Copy link

ghost commented Mar 8, 2017

View the complete job log.

Firefox (nightly channel)

Testing web-platform-tests at revision d94eee3f3d94c3bfa544ad41b53fa209a985f0f7
Using browser at version BuildID 20170306110339; SourceStamp 966464a68a2cb3ca1125808e34abb5c1d34e3797
Starting 10 test iterations

@ghost
Copy link

ghost commented Mar 8, 2017

View the complete job log.

Chrome (unstable channel)

Testing web-platform-tests at revision d94eee3f3d94c3bfa544ad41b53fa209a985f0f7

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 8, 2017

I also think you may have introduced a same-origin policy violation in Firefox since you can't just preserve Content-Type when its value is not safelisted

My change linked to above just preserved the "Content-Type not set" state across redirects, instead of converting it to "Content-Type set to empty string", which is what Firefox used to do before my change. It didn't change the behavior of any cases in which the header was set.

Looking at Firefox code, we use the concept at https://fetch.spec.whatwg.org/#cors-safelisted-request-header to decide whether to preflight or not. I'm not sure whether we use it for anything else. Bug report is probably a good idea. That said, I see nothing in the spec about special handling of these on redirect per se, just in terms of checking what the preflight response looks like, right?

}

if (typeof body == "string") {
} else if (typeof body == "string") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the else after return here and below?

var arr = Array.prototype.slice.call(body);
return { body: String.fromCharCode.apply(null, arr), type: "NO" }
} else {
return { body: "EXTRACT NOT IMPLEMENTED", type: "EXTRACT NOT IMPLEMENTED" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this long line instead of the more readable two lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use 100 columns.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I can revert these changes though, they are editorial only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, the wrapping of the body/type bits wasn't because it was too wide; it was just because it's more readable (for me at least) to have the different props on different lines.... I don't feel super-strongly about it, though.

if (client.readyState == 4) {
client.onreadystatechange = t.step_func(() => {
if (client.readyState == 4) {
if(!setExplicitType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after "if".

assert_equals(client.getResponseHeader("x-request-content-type"), expectedType);
assert_equals(client.getResponseHeader("x-request-data"), expectedBody);
} else {
// Content-Type is not safelisted by corsenabled.py -> network error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have a test for the case in which it is safelisted.

We should also have a test for the case in which it's not safelisted but one of the safe values was set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter is already covered by the text/plain example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an example that makes an explicit setRequestHeader with text/plain as the value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't. Per the standard they're equivalent, but I suppose it doesn't hurt to have both.

@annevk
Copy link
Member Author

annevk commented Mar 9, 2017

That said, I see nothing in the spec about special handling of these on redirect per se, just in terms of checking what the preflight response looks like, right?

Yeah, the problem is that Firefox doesn't appear to do a preflight or maybe it does a preflight, but does not require Content-Type to be listed in the response.

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

Hrm. Looking at the code some more, it really looks like this should work in Firefox; we're using one place both to decide that this header needs a preflight and that it's unsafe and needs whitelisting Please do get that bug filed!

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

Actually, I filed it. https://bugzilla.mozilla.org/show_bug.cgi?id=1345788

@annevk
Copy link
Member Author

annevk commented Mar 9, 2017

Thanks, I was planning on getting there, still working through all my GitHub backlog.

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

Yeah, I got sucked into debugging it, so figured I might as well file with the info I had. ;)

@annevk annevk force-pushed the annevk/xhr-content-type-cross-origin branch from e654de1 to 3d29fdd Compare March 9, 2017 11:26
@annevk
Copy link
Member Author

annevk commented Mar 9, 2017

I think I covered all bases now. I'll file a bug on WebKit once you approve this.

}
client.send(body)
})
}, document.title + " (" + name + ")")
}
redirect("301")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you change behavior for this call? It used to set the Content-Type header, but now no longer does. Is that purposeful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, because that made them all fail, but I'll add some more tests.

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

And in particular, we no longer have GET tests with explicit content-type in there now, right?

@annevk
Copy link
Member Author

annevk commented Mar 9, 2017

Okay, I covered some more ground.

@bzbarsky
Copy link
Contributor

bzbarsky commented Mar 9, 2017

Looks great, thanks!

@annevk annevk merged commit 98d5840 into master Mar 9, 2017
@annevk
Copy link
Member Author

annevk commented Mar 9, 2017

Filed https://bugs.webkit.org/show_bug.cgi?id=169420 on the WebKit failures.

@annevk annevk deleted the annevk/xhr-content-type-cross-origin branch March 9, 2017 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants