fix(cookies): do not serialize a finite maxAge outside the long long range #6244
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 331 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.347
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #6244"
general
weight: 0.35
mcollina
This relates to...
Relates to #5832 and #6123, which fixed the same class of problem for the
expiresfield of the same Cookie dictionary. No open issue coversmaxAge; this was found by auditing the remaining numeric field after those fixes.Rationale
The
maxAgemember of the Cookie dictionary is converted with the WebIDLlong longconverter, which wraps finite numbers modulo 2^64. A finitemaxAgeoutside the long long range therefore serializes as an unrelated value:2 64 + 2 32becomesMax-Age=4294967296, and2 63wraps to a negative value that only throws by accident. As withexpiresin #6123, an out-of-range finite value must not become a different, valid-looking value through integer wraparound.Changes
Bug Fixes
setCookie: a finitemaxAgeoutside the range of the WebIDLlong longconversion (value < -(2 63) || value >= 2 63) is now dropped in the Cookie dictionary converter, before the conversion can wrap it, so noMax-Ageattribute is serialized. This mirrors the guard #6124 added for numericexpires. In-range behavior is unchanged, including fractional truncation by the WebIDL conversion and the existingInvalid cookie max-ageerror for negative values. Non-finite values are intentionally out of scope, matching the scoping of #6123: they are still coerced to 0 by the WebIDL converter.Breaking Changes and Deprecations
N/A. The only behavior change is for inputs that previously produced an arbitrary wrapped
Max-Agevalue.Status
[cert]: https://github.com/nodejs/undici/blob/main/CONTRIBUTING.md#developers-certificate-of-origin
Tests
New cases in
test/cookie/cookies.js(in theCookie Settest, next to the existing out-of-rangeexpirescases):2 63,2 64,2 64 + 2 32,Number.MAX_VALUE,-Number.MAX_VALUEand-(2 64)serialize without aMax-Ageattribute, and2 ** 62still serializes as-is.npm run test:cookies: 93 pass / 0 fail with this change; on the base commit the new assertions fail (92 pass / 1 fail, theCookie Settest) and everything else is unchanged.npx eslint lib/web/cookies/index.js test/cookie/cookies.js: clean.