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: keep a header named __proto__ across features by luantaraschi · Pull Request #5688 · nodejs/undici

Conversation

@luantaraschi

@luantaraschi luantaraschi commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

This relates to...

Supersedes #5666, #5667, #5668 and #5669. This is the consolidation you asked for in #5666 (comment) and confirmed in #5667 (comment): one util, used across the features. Thanks for the steer, it turned four near-identical diffs into one.

Rationale

Writing a header named __proto__ onto a plain object reaches the Object.prototype setter instead of creating a property. A string value is dropped without a trace. An array value replaces the accumulator's prototype, so the object loses its own methods.

parseHeaders in lib/core/util.js already guards that with Object.defineProperty. Four other accumulators did not, and each of the superseded PRs carried its own copy of the guard. Three of them had the identical setHeader function written out three times, which is what you spotted.

Changes

The guard becomes setHeader in lib/core/util.js, exported next to parseHeaders, and the four sites call it:

  • lib/web/fetch/headers.js, the entries object built from the headers list
  • lib/util/cache.js, appendHeader and makeDeduplicationKey
  • lib/mock/snapshot-utils.js and lib/mock/snapshot-recorder.js, header normalizing and filtering
  • lib/dispatcher/client-h2.js, buildRequestHeaders

Three of those read a header back before writing it, so they now check with Object.hasOwn. A plain read resolves __proto__ through the prototype chain instead of reporting the header as absent, and that is what made two different requests share a deduplication key.

Two notes on scope, both easy to change if you see it differently:

parseHeaders keeps its inline guard rather than calling the util. It runs once per header on every response, so routing it through a function call is a hot path change this PR does not need to make. Happy to fold it in if you would rather have a single caller shape everywhere.

#5663 is not part of this and stays as it is. It gives getCookies a null prototype accumulator, so there is no header write to route through the util, and it builds a cookie record rather than a header record.

Features

N/A

Bug Fixes

A header named __proto__ survives the fetch Headers list, the cache key and deduplication key, the mock snapshot recorder, and the HTTP/2 request header builder, instead of being dropped or replacing the accumulator's prototype.

Breaking Changes and Deprecations

None. setHeader is a new export on lib/core/util.js, nothing else changed shape.

Testing

Five new tests, one per site plus the deduplication key collision. Each of them fails on main and passes here:

test/prototype-headers.js                pass=2 fail=2   (fetch, h2)
test/cache-interceptor/cache-utils.js    pass=11 fail=1
test/snapshot-recorder.js                pass=14 fail=1
test/interceptors/deduplicate.js         pass=34 fail=1

With the change, on Node 22.20.0 on Windows: test/prototype-headers.js 4 passing, test/cache-interceptor 77 passing, test/interceptors/deduplicate.js 35 passing, test/snapshot-recorder.js 15, test/snapshot-testing.js 32, test/snapshot-redirect-interceptor.js 1, test/fetch/headers.js 66, test/util.js 46 passing with 1 skipped, and every test/http2-*.js file green including http2-request-never-settles.js. eslint is clean.

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: keep a header named __proto__ across features
04dc39d
Writing a header named `__proto__` onto a plain object reaches the
Object.prototype setter instead of creating a property. A string value is
dropped without a trace, and an array value replaces the accumulator's
prototype, which takes every method of that object with it.

`parseHeaders` in lib/core/util.js already guarded the case with
Object.defineProperty. That guard becomes an exported `setHeader` util and the
four remaining accumulators use it: the entries object of the fetch Headers
list, the cache key and deduplication key builders, the mock snapshot header
normalizers, and the HTTP/2 request header builder.

The three accumulators that also read a header back before writing now check
with Object.hasOwn, because a plain read resolves `__proto__` through the
prototype chain rather than reporting the header as absent.
This was referenced Aug 14, 2026
fix(fetch): keep a request header named __proto__ #5666
Closed
fix(cache): keep a header named __proto__ out of the prototype chain #5667
Closed
fix(mock): keep a header named __proto__ in snapshots #5668
Closed
fix(h2): keep a request header named __proto__ #5669
Closed
@codecov-commenter

codecov-commenter commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.03922% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.46%. Comparing base (8f9cc1d) to head (04dc39d).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
lib/mock/snapshot-utils.js 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5688   +/-   ##
=======================================
  Coverage   93.46%   93.46%           
=======================================
  Files         110      110           
  Lines       38777    38812   +35     
=======================================
+ Hits        36241    36275   +34     
- Misses       2536     2537    +1     

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

metcoder95
metcoder95 approved these changes Aug 25, 2026
View reviewed changes
mcollina
mcollina approved these changes Sep 25, 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
@mcollina
mcollina merged commit 7bc9dd6 into nodejs:main Sep 25, 2026
38 checks passed

Uh oh!

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

@pg4m9kpmcd-spec

This comment was marked as spam.

Sign in to view
@github-actions github-actions Bot mentioned this pull request Oct 14, 2026
[Release] v8.12.0 #6008
Merged
@GiHoon1123 GiHoon1123 mentioned this pull request Oct 27, 2026
feat(util): expose request header normalization #5780
Closed
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
@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 @pg4m9kpmcd-spec @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.