mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #295] bug: Set-Cookie headers flattened in prod-server.ts response merging #71
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#71
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @southpolesteve on GitHub (Mar 6, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/295
Problem
In
prod-server.tsaround line 944-945, middleware headers are merged into the final response using aRecord<string, string>pattern:Headers.forEach()iterates Set-Cookie values as combined comma-separated strings (viaHeaders.get()semantics), or as individual entries depending on the runtime. Either way, theRecord<string, string>target loses multiple Set-Cookie values:forEachyields per-entry, the last Set-Cookie wins (previous ones overwritten)forEachyields the comma-joined string, the result is a single corrupted Set-Cookie (cookie values withExpires=dates contain commas, so comma-joining breaks parsing)The resulting
sendCompressedcall passes this flattened object towriteHead, which can't reconstruct the original multiple Set-Cookie headers.Context
This is a pre-existing bug, surfaced during review of #281 (which correctly uses
responseHeaders.append("set-cookie", ...)inrenderPage). Now that gSSP can set cookies viares.setHeader("set-cookie", ...), this flattening inprod-server.tsbecomes more likely to hit in practice.Fix
Use
Headers.getSetCookie()(available in Node 20+, Cloudflare Workers, Deno) to preserve array-valued Set-Cookie headers, or switchresponseHeadersto use theHeadersAPI throughout instead of a plain object.Discovered by
Flagged by bigbonk in https://github.com/cloudflare/vinext/pull/281#issuecomment-4009074461