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): keep a cookie named __proto__ in getCookies by luantaraschi · Pull Request #5663 · nodejs/undici

Conversation

@luantaraschi

@luantaraschi luantaraschi commented Aug 7, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This relates to...

No open issue. Found while reading lib/web/cookies/.

Rationale

getCookies() builds its result on a plain object literal:

const out = {}
for (const piece of cookie.split(';')) {
  const [name, ...value] = piece.split('=')
  out[name.trim()] = value.join('=')
}

__proto__ is a valid cookie name (it is a token per RFC 6265), but assigning it on a plain object reaches the Object.prototype setter instead of creating an own property. The setter only accepts an object or null, and the assigned value here is always a string, so it does nothing and the cookie is dropped:

const headers = new Headers()
headers.set('Cookie', '__proto__=foo; bar=baz')

getCookies(headers)              // { bar: 'baz' }, the first cookie is gone
getCookies(headers).__proto__    // Object.prototype, not the string 'foo'

The second line is the part that bothered me more than the missing key. getCookies is typed Record<string, string>, so a caller that indexes it by an attacker-influenced name gets an object back where the types promise a string.

There is no prototype pollution here: the setter refuses a string, so Object.prototype is untouched. The bug is silent data loss plus a broken type contract.

Changes

getCookies now builds its record with { __proto__: null }, which is already the pattern used in lib/core/util.js, lib/util/runtime-features.js, lib/web/eventsource/eventsource.js and lib/web/fetch/formdata.js.

The existing tests all use assert.deepEqual, which does not compare prototypes, so none of them needed changing. All 92 tests under test/cookie/ pass.

Features

N/A

Bug Fixes

A cookie named __proto__ is now returned by getCookies() like any other name.

Breaking Changes and Deprecations

The returned object no longer inherits from Object.prototype, so calling cookies.hasOwnProperty(name) on it stops working. Object.hasOwn(cookies, name) and name in cookies still work, as does every form of indexing and iteration.

Status

  • I have read and agreed to the Developer's Certificate of Origin
  • Tested
  • Benchmarked (optional)
  • Documented
  • Review ready
  • In review
  • Merge ready

Sorry, something went wrong.

Uh oh!

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

All reactions
@luantaraschi
fix(cookies): keep a cookie named __proto__ in getCookies
3d2b33b
getCookies built its result on a plain object literal, so assigning the
__proto__ key reached the Object.prototype setter instead of creating an
own property. The assigned value is a string, so the setter is a no-op
and the cookie is dropped from the returned record.

Reading that key back also returned Object.prototype, which breaks the
documented Record<string, string> contract.

Use a null-prototype object, as lib/ already does in six other places.
Copilot AI lite review requested due to automatic review settings August 7, 2026 16:34
Copilot AI reviewed Aug 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sorry, something went wrong.

Uh oh!

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

All reactions
mcollina
mcollina approved these changes Aug 7, 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

(However, I think this is a bad idea. We should throw hard when proto appears).

Sorry, something went wrong.

Uh oh!

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

All reactions
This was referenced Aug 8, 2026
fix(mock): keep a header named __proto__ in snapshots #5668
Closed
fix(cache): keep a header named __proto__ out of the prototype chain #5667
Closed
@luantaraschi

luantaraschi commented Aug 8, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I checked the three failing jobs, and none of them exercises this change, which only touches lib/web/cookies/.

  • The two Node 24 Ubuntu jobs fail in test/http2-request-never-settles.js. The same test failed on main in run 31085361670 on 6 August, before this branch existed.
  • The Node 22 macOS job times out in test/fetch/content-length.js at 180006 ms, matching the 180-second limit rather than an assertion failure.

On __proto__, I followed the behavior already used in two places:

  • b64e7e4, "fix: avoid prototype collisions in parseHeaders (fix: avoid prototype collisions in parseHeaders #4923)"
  • 90a1609, "fix: preserve response trailers that shadow Object.prototype"

Both preserve keys received from the wire with Object.defineProperty instead of rejecting them. This PR uses the same approach in getCookies.

__proto__ is also a valid cookie name under the token grammar in RFC 6265 section 4.1.1. Throwing from getCookies would therefore let an incoming cookie break its caller. If the project prefers rejecting this key, I think that policy should be applied consistently to all three parsing paths rather than only to cookies. I am happy to help with that as a separate change.

A rerun should be enough for this PR. I can rebase if you would prefer a fresh run that way.

All reactions

Sorry, something went wrong.

Uh oh!

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

@luantaraschi luantaraschi mentioned this pull request Aug 10, 2026
fix(h2): keep a request header named __proto__ #5669
Closed
3 of 7 tasks
metcoder95
metcoder95 approved these changes Aug 14, 2026
View reviewed changes
@metcoder95
Merge branch 'main' into fix/get-cookies-proto-key
90d7914
@luantaraschi luantaraschi mentioned this pull request Aug 14, 2026
fix: keep a header named __proto__ across features #5688
Merged
3 of 7 tasks
@luantaraschi

luantaraschi commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. One thing to flag, and it is on me: about a minute after you approved I merged main into the branch to get the old red run out of the way, and the new head now reports no checks at all.

I cannot start workflow runs in this repository myself, so it needs someone with write access to kick them off before this can land. Sorry for the extra step, the timing was clumsy.

All reactions

Sorry, something went wrong.

Uh oh!

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

@codecov-commenter

codecov-commenter commented Aug 15, 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 93.46%. Comparing base (692c02b) to head (90d7914).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5663   +/-   ##
=======================================
  Coverage   93.46%   93.46%           
=======================================
  Files         110      110           
  Lines       38777    38779    +2     
=======================================
+ Hits        36244    36246    +2     
  Misses       2533     2533           

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

@luantaraschi

luantaraschi commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

CI is red on two jobs, and neither failure comes from this change.

Node 26 on macOS failed in test/issue-5087.js. The test itself passed, then late activity after it ended surfaced read ECONNRESET, which the runner reported as a file level failure. Node 25 on ubuntu with WASM SIMD disabled failed in test/http2-request-never-settles.js. Neither file touches cookies, and Test unit runs borp -p "test/*.js", which does not cover test/cookie/*.js.

Locally on this branch that same step passes: 1510 tests, no failures (1506 passed, 4 skipped). npm run test:cookies passes 92 of 92.

The flakiness is not specific to this branch either. Of the last ten CI runs on main, six failed the Node 24 coverage job and one failed the same Node 25 WASM SIMD job. test/issue-5087.js still has no guard for late session errors, unlike the h2 tests hardened in #5674 and #5686.

I can rebase onto current main if a fresh run would help.

All reactions

Sorry, something went wrong.

Uh oh!

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

@luantaraschi luantaraschi mentioned this pull request Aug 17, 2026
test(h2): swallow late session errors in the issue-5087 timeout tests #5694
Closed
@mcollina
mcollina merged commit b73952a into nodejs:main Sep 4, 2026
36 of 38 checks passed

Uh oh!

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

@github-actions github-actions Bot mentioned this pull request Sep 14, 2026
[Release] v8.11.0 #5821
Closed
This was referenced Sep 21, 2026
[Release] v8.11.0 #5848
Closed
[Release] v8.11.0 #5849
Merged
@mrityunjay-pandey mrityunjay-pandey mentioned this pull request Oct 15, 2026
[v7.x] fix(cookies): backport #5663, #5808 and #5832 #6019
Merged
3 of 7 tasks
mcollina pushed a commit that referenced this pull request Oct 15, 2026
@mrityunjay-pandey @luantaraschi
@metcoder95 @NgoQuocViet2001 @xia-chao
[v7.x] fix(cookies): backport #5663, #5808 and #5832 (#6019)
7d60c7b
* fix(cookies): keep a cookie named __proto__ in getCookies (#5663)

getCookies built its result on a plain object literal, so assigning the
__proto__ key reached the Object.prototype setter instead of creating an
own property. The assigned value is a string, so the setter is a no-op
and the cookie is dropped from the returned record.

Reading that key back also returned Object.prototype, which breaks the
documented Record<string, string> contract.

Use a null-prototype object, as lib/ already does in six other places.

Co-authored-by: Carlos Fuentes <[email protected]>
(cherry picked from commit b73952a)

* fix(cookies): keep an Expires of 0 when serializing a cookie (#5808)

The Expires branch tested cookie.expires for truthiness, so a numeric 0 -- the
Unix epoch, and the canonical way to say "expire this cookie now" -- dropped
the attribute entirely. expires is typed Date | number, and the Max-Age check
directly above already tests the type rather than truthiness for the same
reason.

(cherry picked from commit 6933139)

* fix(cookies): ignore a numeric expires outside the Date range (#5832)

stringify guarded expires with a string comparison that only works for the
Date form:

    if (cookie.expires != null && cookie.expires.toString() !== 'Invalid Date')

A Date whose time value is NaN stringifies to "Invalid Date" and is skipped,
but a number never does: NaN.toString() is "NaN" and 1e16.toString() is
"10000000000000000". The guard therefore always passes for a number outside
the range representable by Date, and toIMFDate reads NaN/undefined from every
getter and splices those tokens into the header value:

    setCookie(headers, { name: 'Space', value: 'Cat', expires: 1e16 })
    // Space=Cat; Expires=undefined, undefined undefined NaN undefined:undefined:undefined GMT

The emitted value is not a valid IMF-fixdate. The Max-Age branch a few lines
above already tests the type rather than a stringified value.

Treat a number as absent only when it is not a valid time value, keeping the
existing Date behaviour. Name the upper bound so it is clear it is the largest
time value a Date can represent rather than a magic number.

Non-finite numbers reach stringify already coerced to 0 by the unsigned long
long converter in lib/web/cookies/index.js, so they keep serializing as the
epoch; that coercion is a separate concern.

Signed-off-by: Xia Chao <[email protected]>
Co-authored-by: Xia Chao <[email protected]>
(cherry picked from commit 78aa1a0)

---------

Signed-off-by: Xia Chao <[email protected]>
Co-authored-by: Luan Taraschi <[email protected]>
Co-authored-by: Carlos Fuentes <[email protected]>
Co-authored-by: Ngo Quoc Viet <[email protected]>
Co-authored-by: Xia Chao <[email protected]>
Co-authored-by: Xia Chao <[email protected]>
@github-actions github-actions Bot mentioned this pull request Oct 15, 2026
[Release] v7.30.1 #6022
Merged
This was referenced Oct 24, 2026
refactor: Bump undici from 6.27.0 to 6.29.1 and 7.28.0 to 7.30.1 parse-community/node-apn#226
Merged
refactor: Bump undici from 6.27.0 to 6.29.1 and 7.28.0 to 7.30.1 parse-community/Parse-SDK-dotNET#436
Merged
refactor: Bump undici from 6.27.0 to 6.29.1 and 7.28.0 to 7.30.1 parse-community/parse-server-example#947
Merged
refactor: Bump undici from 6.28.1 to 6.29.1, 7.29.1 to 7.30.1 and 7.30.0 to 7.30.1 parse-community/parse-server-sqs-mq-adapter#460
Merged
fix: Bump undici from 6.28.1 to 6.29.1 and 7.29.1 to 7.30.1 parse-community/parse-server-push-adapter#636
Merged
refactor: Bump undici from 6.28.1 to 6.29.1, 7.29.1 to 7.30.1 and 7.30.0 to 7.30.1 parse-community/parse-dashboard#3510
Merged
refactor: Bump undici from 7.24.6 to 7.30.1 parse-community/Parse-SDK-Flutter#1179
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@mcollina mcollina mcollina approved these changes
@metcoder95 metcoder95 metcoder95 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.

5 participants

@luantaraschi @codecov-commenter @mcollina @metcoder95
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.