-
Notifications
You must be signed in to change notification settings - Fork 572
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
Undici strips out set-cookie headers, even when "credentials: 'include'" is set #1262
Comments
Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
I would like to create a pull request, but I'm going to need some help first with deciding how to handle this.
This leads me to wonder how best to make @mcollina: Do you have a suggestion for how to provide In general it feels like it could be helpful to have a context object that includes the |
Isn't it enough to just literally follow the steps in the spec?
|
🤔 That mentions setting the |
@hansede I think we first need to understand the specification and how it imagines your use case to work. |
Here is the relevant part https://github.com/nodejs/undici/blob/main/lib/fetch/index.js#L1850-L1858 |
Perhaps the relevant portion of the spec would be: If includeCredentials is true and the user agent is not configured to block cookies for request (see section 7 of [COOKIES]), then run the "set-cookie-string" parsing algorithm (see section 5.2 of [COOKIES]) on the value of each header whose name is a byte-case-insensitive match for |
I think we already fixed this. Can someone confirm? |
Lines 1806 to 1811 in 5478cdd
|
You are right. PR welcome! |
Cookie parsing compliant with the rfc linked is done with #1441. I'll probably strip out that implementation into a new PR to use for this issue. edit: I found the issue and will make a PR soon to fix this. Didn't need to parse cookies. |
#1454 was reverted following @ronag's comment:
I don't think there is a spec to follow here though. The spec (referring to 4.7.17.3 of the fetch standard, which leads us 5.2 of RFC 6265) is clearly written for browsers; it assumes that the user agent has a cookie store, which obviously makes no sense for a server that can handle requests from multiple users. I gather from @KhafraDev that there's a proposal to add Other implementations have chosen differently. This URL returns a
In the absence of a usable spec, I would argue that following the behaviour that a majority of implementations have agreed upon (and that users expect, as evidenced by the Miniflare issue among others) is the prudent course of action. (Even though |
I believe this is a bug that has nothing to do with cookie parsing (etc.) and #1454 presents a valid solution, just need to see what ronag thinks now. 😄 |
I'm ok with following cloudflare and deno. But if we land this change I would like that:
I think a clear motivation is what was primarly missing from the PR. Similar to #1262 (comment). |
I would assume that no other platform besides undici actually does this filtering, especially since all the other platforms seem to work without an issue (that I could find) mentioning |
Bug Description
Undici strips out
set-cookie
headers, which is expected per thefetch
API spec. What is not expected though is that theset-cookie
headers are stripped out in the presence of{ credentials: 'include' }
in afetch
request. Here is the relevant portion of thefetch
API spec:https://fetch.spec.whatwg.org/#example-cors-with-credentials
Reproducible By
server.js
client.js
With the server script running, the client script returns:
Expected Behavior
In the presence of
{ credentials: 'include' }
I would expectset-cookie
headers to not be stripped from the response. The expected output of the client script should be:Environment
Mac OS 12.2.1
Node v16.13.1
Additional context
There is a
TODO
in Undici'sfetch
code where this behavior should be implemented:https://github.com/nodejs/undici/blob/main/lib/fetch/index.js#L1369-L1375
The text was updated successfully, but these errors were encountered: