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

Do redirects copy the headers from the initial requests #553

Closed
bichhawat opened this issue Jun 15, 2017 · 12 comments
Closed

Do redirects copy the headers from the initial requests #553

bichhawat opened this issue Jun 15, 2017 · 12 comments

Comments

@bichhawat
Copy link

I might be missing something in the spec, but it seems to me that there is no description of how the headers from the initial request whose response is a redirect are handled when creating a redirect request. Are the headers copied over or is the header list empty when forwarding the request to the redirect URL

@jdm
Copy link
Member

jdm commented Jun 15, 2017

There's a note near the beginning of https://fetch.spec.whatwg.org/#concept-http-network-or-cache-fetch by step 3.4 that makes clear that the same initial request object is used as the base for each subsequent request.

@bichhawat
Copy link
Author

Thanks for the quick response. I understand that it copies the object as such but are the headers retained if the new request does not have relevant headers, i.e., if the httpRequest object does not have relevant data for appending say a Origin header, does the header from the previous request stay or is removed.

@jdm
Copy link
Member

jdm commented Jun 15, 2017

I don't understand the question. The httpRequest object is a copy of the request, including all of its headers. When a redirect is processed later (in step 5 of https://fetch.spec.whatwg.org/#concept-http-fetch) we use the original request object, not the copy that was used in http-network-or-cache-fetch.

@wanderview
Copy link
Member

wanderview commented Jun 15, 2017

The effect should be that headers set explicitly on the Request objects propagate across redirects, but things set by the browser like Origin do not.

Edit: Well some headers set by the browser should not propagate across redirects by default.

@annevk
Copy link
Member

annevk commented Jun 22, 2017

@wanderview are you pointing out an issue in your "Edit:" remark? I think everything is fine here?

@wanderview
Copy link
Member

I think its fine.

@annevk
Copy link
Member

annevk commented Jun 22, 2017

@bichhawat, if anything is still unclear please don't hesitate to ask further clarifying questions. If you have suggestions for how to make the Fetch Standard clearer with regards to this those are welcome too. Thanks!

@annevk annevk closed this as completed Jun 22, 2017
@bichhawat
Copy link
Author

bichhawat commented Jul 3, 2017 via email

@jdm
Copy link
Member

jdm commented Jul 3, 2017

The cookie header (for example) is set during the http-network-or-cache algorithm. The request object that has the cookie header added to it is a copy of the initial request (step 3). If a redirect occurs, the request object that is used as the base of the copy for the next request does not have the header present.

@bichhawat
Copy link
Author

Oh, I misunderstood the request object to be the original request sent with all the information. Thanks a lot for clearing it up.

@ptoomey3
Copy link

Stumbled upon this thread and had a question about this as it relates to things like an Authorization header. In talking to a developer I work with, they noticed that it appeared the the authorization header is sent in the redirect request. That seems unexpected/risky since the redirect is to another domain. Is that expected behavior?

@annevk
Copy link
Member

annevk commented Oct 1, 2019

Yes, there are no exceptions. (Though see #609 for POST -> GET.)

(It's also not clear to me we could compatibly change that at this point.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants