GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(cookies): do not serialize a finite maxAge outside the long long range by waw666waw666 · Pull Request #6244 · nodejs/undici

Conversation

@waw666waw666

@waw666waw666 waw666waw666 commented Nov 21, 2026

Copy link
Copy Markdown

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 fix(cookies): ignore finite numeric expires that wrap in unsigned long long #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 setCookie turns finite out-of-range expires values into a Unix-epoch expiry #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
  • Tested
  • Benchmarked (optional)
  • Documented
  • Review ready
  • In review
  • Merge ready

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@waw666waw666
fix(cookies): do not serialize a finite maxAge outside the long long …
c54f687
…range

Signed-off-by: waw666waw666 <[email protected]>
mcollina
mcollina approved these changes Nov 22, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@codecov-commenter

codecov-commenter commented Nov 22, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.73%. Comparing base (6b22aba) to head (c54f687).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6244      +/-   ##
==========================================
+ Coverage   91.72%   91.73%   +0.01%     
==========================================
  Files         113      113              
  Lines       44835    44861      +26     
==========================================
+ Hits        41124    41155      +31     
+ Misses       3711     3706       -5     

☔ 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This branch has not been deployed

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

Reviewers

@mcollina mcollina mcollina approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@waw666waw666 @codecov-commenter @mcollina
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.