-
Notifications
You must be signed in to change notification settings - Fork 341
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
Use request's current url as base URL in redirects #633
Conversation
LGTM. Is this covered by existing WPT tests? I think it probably is. |
I'm not sure about the various scenarios involving service workers. |
FWIW, looks like a good fix to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@jakearchibald do you happen to know if we have opaqueredirect tets? |
FWIW, we check opaqueredirect in a number of WPT tests: https://searchfox.org/mozilla-central/source/testing/web-platform/tests/service-workers/service-worker/fetch-event-redirect.https.html Not sure if they cover all cases for this PR, though. |
There is also a fetch API test here: |
To test this I think what we need is this:
Does that make sense? If someone could do this for me that'd be great, if not I'll have to sort out how to set up HTTPS testing and how to write service worker tests. |
As per whatwg/fetch#633 (comment) except using global state instead of the cache API. (Improvements welcome!)
So I think with this change we end up doing what I think is the correct thing for opaque redirects, but it doesn't quite work for synthetic redirects not created through const res = new Response(null, { status: 302 });
res.headers.append("Location", "something-relative"); In order to make this work we'd have to parse the But maybe we should live with that inconsistency? Not entirely sure how to fix it. |
So there's basically four types of redirect responses:
1 is different from 2 because 1 always has an absolute URL and therefore always goes to the same URL. This PR as it stands ensures 3 and 4 always go to the same URL. This does not match Chrome and Firefox, but does match Safari. Given https://fetch.spec.whatwg.org/#atomic-http-redirect-handling it seems good to me that the client side cannot fiddle with the intent of the server, even if it was weakly stated (with a relative URL) and therefore I'd argue we align with Safari. One approach we could take here is that 2 becomes a network error or "not a redirect" (just a response that happens to look like one). This would be easy to accomplish using the https://fetch.spec.whatwg.org/#concept-response-location-url field and setting it for 1. I quite like that idea, but I'd like to solicit feedback on that from you all first. (An alternative is that 2 remains an oddball redirect response whose location varies on who requests it, but that seems a little less clean.) |
Could we allow (2), but make it throw if the Location URL is relative? |
@wanderview the response remains mutable, so that won't work. We could maybe do something like that when first handling such a response, but it'll be rather special. |
b5d9ad4
to
7922b6c
Compare
Arguably even nicer would be throwing a RangeError when constructing a Response with a 3xx status. Is that unrealistic? If it is, how realistic is returning a network error for some of them? |
@wanderview @jakearchibald @yutakahirano @ricea @youennf thoughts on the above? |
As per whatwg/fetch#633 (comment) except using global state instead of the cache API. (Improvements welcome!)
Haven't we promoted |
Yeah, that is correct. |
I don't think we should prevent users creating redirects with In the |
If there were no backward-compatibility issues, would we want to disallow a user-created redirect response with a relative location at 3-3 in https://fetch.spec.whatwg.org/#http-fetch? |
@yutakahirano I think that would be the most conservative solution that solves the stated problem. I think the ideal solution is not allowing the creation of such responses in the first place, but that's far less likely to be compatible. |
@jakearchibald I guess, but it does create a rather weird special case that we'll likely have to take into consideration forever and ever when it comes to redirects. I'm worried that it'll trip us up somehow. |
As the response's url list is not set at this point using that doesn not work. We could potentially set it earlier, but that brings along other complications that this setup avoid. This also returns opaque redirect responses earlier, to avoid having them processed twice, which was simply wrong (and would become extra wrong here). Fixes #631.
7922b6c
to
0ae5dca
Compare
Anyone any further thoughts here? It'd be nice to resolve this. |
As per whatwg/fetch#633 (comment) except using global state instead of the cache API. (Improvements welcome!)
It does not need to be stored on a response and therefore resulted in confusion. Also clarify that synthetic responses need to have an absolute URL in the Location header field value (Response.redirect() does this automatically). Corresponding HTML PR: TODO. Tests: TODO. Closes #631, closes #633, closes #958, and closes #1146. (Some of these can be closed due to #1030 making response's URL no longer null for network responses.)
It does not need to be stored on a response and therefore resulted in confusion. Also clarify that synthetic responses need to have an absolute URL in the Location header field value (Response.redirect() does this automatically). Corresponding HTML PR: TODO. Tests: TODO. Closes #631, closes #633, closes #958, and closes #1146. (Some of these can be closed due to #1030 making response's URL no longer null for network responses.)
It does not need to be stored on a response and therefore resulted in confusion. Also clarify that synthetic responses need to have an absolute URL in the Location header field value (Response.redirect() does this automatically). Corresponding HTML PR: whatwg/html#6340. Tests: https://chromium-review.googlesource.com/c/chromium/src/+/2665871. Closes #631, closes #633, closes #958, closes #1146, and closes web-platform-tests/wpt#10449. (Some of these can be closed due to #1030 making response's URL no longer null for network responses.)
As the response's url list is not set at this point using that doesn not work. We could potentially set it earlier, but that brings along other complications that this setup avoid.
This also returns opaque redirect responses earlier, to avoid having them processed twice, which was simply wrong (and would become extra wrong here).
Fixes #631.
Preview | Diff