← Back to Pull requests

fix(cookies): do not serialize a finite maxAge outside the long long range #6244

Open
unknown opened this pull request with 331 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 21, 2026 20:31 UTC
Author

This relates to...

Relates to #5832 and #6123, which fixed the same class of problem for the expires field of the same Cookie dictionary. No open issue covers maxAge; this was found by auditing the remaining numeric field after those fixes.

Rationale

The maxAge member of the Cookie dictionary is converted with the WebIDL long long converter, which wraps finite numbers modulo 2^64. A finite maxAge outside the long long range therefore serializes as an unrelated value:

import { Headers, setCookie } from 'undici'

const headers = new Headers()
setCookie(headers, { name: 'session', value: 'value', maxAge: 2 ** 64 })
headers.get('set-cookie')
// 'session=value; Max-Age=0'  -- the cookie is deleted immediately

2 64 + 2 32 becomes Max-Age=4294967296, and 2 63 wraps to a negative value that only throws by accident. As with expires in #6123, an out-of-range finite value must not become a different, valid-looking value through integer wraparound.

Changes

Bug Fixes

  • setCookie: a finite maxAge outside the range of the WebIDL long long conversion (value < -(2 63) || value >= 2 63) is now dropped in the Cookie dictionary converter, before the conversion can wrap it, so no Max-Age attribute is serialized. This mirrors the guard #6124 added for numeric expires. In-range behavior is unchanged, including fractional truncation by the WebIDL conversion and the existing Invalid cookie max-age error 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-Age value.

    Status

  • I have read and agreed to the [Developer's Certificate of Origin][cert]

  • Tested

  • Benchmarked (optional)

  • Documented

  • Review ready

  • In review

  • Merge ready
  • [cert]: https://github.com/nodejs/undici/blob/main/CONTRIBUTING.md#developers-certificate-of-origin

    Tests

    New cases in test/cookie/cookies.js (in the Cookie Set test, next to the existing out-of-range expires cases): 2 63, 2 64, 2 64 + 2 32, Number.MAX_VALUE, -Number.MAX_VALUE and -(2 64) serialize without a Max-Age attribute, and 2 ** 62 still 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, the Cookie Set test) and everything else is unchanged.

  • npx eslint lib/web/cookies/index.js test/cookie/cookies.js: clean.
  • Diff: 331 lines (+248 / -83) across 4 files Reviewer: mcollina Review duration: 1449m
    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
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.4% · Safe to merge
    22.4%
    Repository