CORS doesn't correctly enforce restrictions on headers across redirects
Categories
(Core :: Networking: HTTP, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox55 | --- | affected |
People
(Reporter: bzbarsky, Assigned: CuveeHsu)
References
(Blocks 1 open bug)
Details
(Whiteboard: [necko-next])
Comment 1•8 years ago
|
||
Comment 2•8 years ago
|
||
Comment 3•8 years ago
|
||
Reporter | ||
Comment 4•8 years ago
|
||
Comment 5•8 years ago
|
||
Comment 6•8 years ago
|
||
Comment 7•8 years ago
|
||
Updated•8 years ago
|
Comment 8•7 years ago
|
||
Comment 9•6 years ago
|
||
Assignee | ||
Updated•5 years ago
|
Reporter | ||
Comment 12•5 years ago
|
||
Hmm. It worries me that the patch in bug 1495880 doesn't actually address the issue that comment 0 describes. It's possible the tests are no longer triggering that issue, of course...
Assignee | ||
Comment 13•5 years ago
|
||
Okay, bug 1495880 is about the preflight, and this is about redirection.
Not sure the relationship between web-platform-tests/wpt#5070 and this bug.
On the other hand, it's not clear to me that why preflight causes the main request check it's upload body again, rather than keep it's original headers.
REOPEN for moving the redirection forward.
Assignee | ||
Comment 14•5 years ago
|
||
For Content-Type
, we copy in the stack.
mozilla::net::HttpBaseChannel::ExplicitSetUploadStream
mozilla::net::HttpBaseChannel::ConfigureReplacementChannel
mozilla::net::HttpBaseChannel::SetupReplacementChannel
IMO we're fine with Content-Type
.
We send OPTIONS
for POST
with 307 redirection.
For POST
to GET
redirection, we already have a spec change to strip the upload body related headers.
We have a special handling for Accept:
https://searchfox.org/mozilla-central/rev/0815480479c19646f9330377ffd8730515fca4ec/netwerk/protocol/http/HttpBaseChannel.cpp#3527-3535
We still suffered from copying headers one-by-one in necko side, but we're fine with the issue in comment.
Reporter | ||
Comment 15•5 years ago
|
||
mozilla::net::HttpBaseChannel::ExplicitSetUploadStream
Why are we reaching that? The whole point is that this is an issue when a redirect happens from a POST to a GET (so 303 or 307), hence the "redirect that doesn't involve preserving the method" bit. In that situation, why are we landing in ExplicitSetUploadStream
at all? I'd expect the config passed to ConfigureReplacementChannel
to have a null uploadStream
in this situation.
For POST to GET redirection, we already have a spec change to strip the upload body related headers.
Ah, interesting.
What about custom headers? Are those copied over for non-XHR fetches when a 303 or 307 happens?
Assignee | ||
Comment 16•5 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #15)
mozilla::net::HttpBaseChannel::ExplicitSetUploadStream
Why are we reaching that? The whole point is that this is an issue when a redirect happens from a POST to a GET (so 303 or 307), hence the "redirect that doesn't involve preserving the method" bit. In that situation, why are we landing in
ExplicitSetUploadStream
at all? I'd expect the config passed toConfigureReplacementChannel
to have a nulluploadStream
in this situation.
Oh, no. It reaches for POST->POST redirection. Sorry for confusing.
BTW 307/308 preserve method. 301/302 redirect from POST to GET. 303 redirects every method other than HEAD to GET.
see 4.4.11 https://fetch.spec.whatwg.org/#concept-http-redirect-fetch
For POST to GET redirection, we already have a spec change to strip the upload body related headers.
Ah, interesting.
What about custom headers? Are those copied over for non-XHR fetches when a 303 or 307 happens?
If you were talking about fetch()
, It copies.
I believes it's here: https://searchfox.org/mozilla-central/rev/0815480479c19646f9330377ffd8730515fca4ec/dom/fetch/FetchDriver.cpp#1311
Reporter | ||
Comment 17•5 years ago
|
||
Oh, sorry, I misread ShouldRewriteRedirectToGET. So yes, 301/302/303 are the relevant bits here.
If you were talking about fetch(), It copies.
Ah, manually, like XHR. I guess other APIs can't really set custom headers, so this might not be directly observable, apart from the CORS interaction.
Assignee | ||
Comment 18•5 years ago
|
||
To conclude,
we worry about headers are not copied for POST->GET redirection, but
(a) If method preserves, actually we copy Content-Type
and Content-Length
in necko side only and fetch#977 is going to make this to spec. (i.e., strip Content-Type
for POST->GET)
(b) Another major concerns is nsCORSListenerProxy::AsyncOnChannelRedirect could update the channels before XHR and fetch()
manually copies headers, but it should manipulate the origin-related headers, which is fine per comment 5 and bug 1240929 comment 19.
And we already copies headers for internal redirections https://searchfox.org/mozilla-central/rev/23d4bffcad365e68d2d45776017056b76ca9a968/netwerk/protocol/http/HttpBaseChannel.cpp#3646-3653
If we're fine with external redirections, it's less risky to mark as WORKSFORME.
What do you think, Boris?
Reporter | ||
Comment 19•5 years ago
|
||
and fetch#977 is going to make this to spec. (i.e., strip Content-Type for POST->GET)
I think this part addresses the original issue I ran into, which was around the lack of copying of Content-Type on POST->GET redirection and how that interacts with CORS.
So yes, given that spec change I agree this is worksforme.
Description
•