-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Set-Cookie headers are concatenated, and are not working correctly #9874
Comments
@lilnasy There is a newer |
@matthewp Luckily, it was backported to 18 exactly in our minimum supported version, 18.14.1. Where would we use it? |
Have any of you been able to replicate the issue? Set-Cookie worked as expected back in Astro 3. Stackblitz is not a good place to test cookies as there is no way to inspect them as far as I am aware. I have looked at the code, and I also thought it might be the culprit. I am not too familiar with https://nodejs.org/api/http.html#messageheaders
For some reason, the set-cookie header is joined with Looking at the Hono node-server implementation, where I had no issues. https://github.com/honojs/node-server/blob/main/src/utils.ts#L44 It is the same, just that he does not use the https://github.com/withastro/astro/blob/main/packages/astro/src/core/app/node.ts#L100 It is only used here, and the headers are not changed. So everything looks ok. I have no clue what is causing this. This bug is very weird... |
I also want to preface. Set-Cookie is one of the exceptions, where HTTP requires you send multiple headers. https://www.rfc-editor.org/rfc/rfc9110.html#name-field-order
|
The code you linked does work the way you describe if you look at the implementation of It is possible dev doesn't special-case "Set-Cookie" to create an array. Edit: that seems to be the problem - it special-cases but then concatenates the array anyway: |
@TorbjornHoltmon Yes, we are very aware of this issue and it's caused us a lot of pain in the past. The tldr is that the @lilnasy The code for this in dev is here: astro/packages/astro/src/vite-plugin-astro-server/response.ts Lines 59 to 75 in 70ae19d
As you can see, we do check for @TorbjornHoltmon In general I'd advise using |
Nice work finding it lilnasy! The Astro cookie API is great! But as lilnasy said, Astro is very much WinterCG compliant. This makes it possible for us to to use primitives and integrate other amazing projects that are also WinterCG compliant. In this case, it was AuthJS, which removes and sets cookies with Set-Cookie on its callback routes. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Set cookie headers seem to be set incorrectly.
Will give me:
This will only set the first
my-other-cookie
as the second cookie is concatenated with a comma and is invalid.I tested with a simple Hono API using Vite, and set-cookie worked correctly. So I am assuming this is an Astro problem.
There are no issues when hosting on Cloudflare pages, which makes me think this is an issue with the node dev server.
What's the expected result?
Set-Cookie headers must not be concatenated
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-cgewux?file=src%2Fpages%2Fcookie-endpoint.ts
Participation
The text was updated successfully, but these errors were encountered: