Skip to content

fix: avoid unbounded recursion in Set-Cookie attribute parser - #5757

Merged
mcollina merged 1 commit into
nodejs:mainfrom
mcollina:fix/set-cookie-recursion
Sep 2, 2026
Merged

fix: avoid unbounded recursion in Set-Cookie attribute parser#5757
mcollina merged 1 commit into
nodejs:mainfrom
mcollina:fix/set-cookie-recursion

Conversation

@mcollina

@mcollina mcollina commented Sep 2, 2026

Copy link
Copy Markdown
Member

What changed

parseUnparsedAttributes in lib/web/cookies/parse.js recursed once per Set-Cookie attribute with no depth bound. A single response header of the form a=b;;;;... overflowed the stack and threw an uncaught RangeError out of getSetCookies.

This converts the algorithm to an iterative loop, threading cookieAttributeList through each iteration exactly as the recursion did. No behavior change; the parser no longer grows the stack per attribute.

Verification

  • The repro 'a=b' + ';'.repeat(5000) now parses successfully instead of throwing RangeError: Maximum call stack size exceeded.
  • End-to-end against a real server: 2000 and 5000 semicolons parse fine; larger payloads fail at the header-size limit, not the parser.
  • Added a regression test in test/cookie/cookies.js.
  • Full cookie test suite passes and lint is clean.

parseUnparsedAttributes recursed once per Set-Cookie attribute with no
depth bound, so a response header of the form 'a=b;;;;...' overflowed the
stack and threw an uncaught RangeError. Convert the algorithm to an
iterative loop, threading cookieAttributeList through each iteration as
before.
@codecov-commenter

codecov-commenter commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.46%. Comparing base (ede2a74) to head (7b626dd).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
lib/web/cookies/parse.js 96.66% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5757   +/-   ##
=======================================
  Coverage   93.46%   93.46%           
=======================================
  Files         110      110           
  Lines       38939    38940    +1     
=======================================
+ Hits        36394    36397    +3     
+ Misses       2545     2543    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina
mcollina merged commit d43e421 into nodejs:main Sep 2, 2026
36 of 38 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 4, 2026
@tractorcow

Copy link
Copy Markdown

Hello, could this fix perhaps be back-ported to v6 / v7 as well please?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants