Repository navigation
fix: copy a set-cookie array passed to reply.header instead of storing it - #7068
Merged
Merged
Conversation
…g it
reply.header('set-cookie', value) stored the caller's array as is, and
every later set-cookie call pushed into that same array. When the array
was a shared value, such as a module-level default, it grew by one entry
on each request, and responses carried more and more duplicate cookies.
The string branch already copies into a fresh array before pushing.
Store a copy of the array so later pushes stay local to the reply.
Signed-off-by: Fadi Romdhan <[email protected]>
gurgunday
approved these changes
Oct 3, 2026
gurgunday
left a comment
Member
There was a problem hiding this comment.
lgtm
yeah this does seem like a problem to me
metcoder95
approved these changes
Oct 8, 2026
Tony133
added a commit
that referenced
this pull request
Oct 12, 2026
…stead of storing it (#7087) Backport 5c081d4 from #7068. Signed-off-by: Fadi Romdhan <[email protected]> Co-authored-by: fadi romdhan <[email protected]> Co-authored-by: Fadi Romdhan <[email protected]> Co-authored-by: Antonio Tripodi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
reply.header('set-cookie', value)storesvaluein the reply's header map. Whenvalueis an array, the array object itself is stored, and every subsequentset-cookiecall on the reply pushes into it (lib/reply.js, theArray.prototype.push.apply/.pushbranch). The string case already copies into a fresh array before pushing, so only the array case leaks the caller's object.If the array is shared, for example a module-level default, it grows by one entry on every request, and responses carry more and more duplicate cookies:
reply.headers({ 'set-cookie': defaults })goes through the same path.This PR stores a copy of the array, so later pushes stay local to the reply.
Checklist
npm run testandnpm run benchmark—test/internals/reply.test.js86/86 with the change; the new testreply.header does not mutate a set-cookie array passed by the callerfails onmain(the second response carriesb=2twice and the caller's array has grown) and passes with this change.eslintis clean.