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(mock): keep a header named __proto__ in snapshots by luantaraschi · Pull Request #5668 · nodejs/undici

Conversation

@luantaraschi

@luantaraschi luantaraschi commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

This relates to...

I raised this in a comment on #5667 and offered to send it separately. Sending it now that #5663 was approved, since it is the same guard on a subsystem where the consequence is different.

Rationale

Three places in the snapshot mock build a plain object keyed by header name and assign into it:

  • normalizeHeaders in lib/mock/snapshot-utils.js, both the array and the object branch
  • filterHeadersForMatching and filterHeadersForStorage in lib/mock/snapshot-recorder.js

__proto__ is a valid header name, and assigning it on a plain object reaches the Object.prototype setter instead of creating an own property. The value is a string, so the setter does nothing and the header is dropped.

It does not stop at a lost header. formatRequestKey feeds those headers to createRequestHash, which walks Object.keys(...).sort(), so two different requests produce one snapshot key:

const filters = createHeaderFilters({})
const a = formatRequestKey({ origin, path, method: 'GET',
  headers: JSON.parse('{"__proto__":"a","x-real":"same"}') }, filters)
const b = formatRequestKey({ origin, path, method: 'GET',
  headers: { 'x-real': 'same' } }, filters)

createRequestHash(a) === createRequestHash(b)   // true

In record mode the two collapse into one entry, and in playback the recorded response for one is served for the other. JSON.parse is the everyday way an own __proto__ key shows up, which is exactly how snapshots arrive from disk.

There is no Object.prototype pollution: the setter refuses a string, so the global prototype is untouched.

Changes

A setHeader helper in snapshot-utils.js writes the __proto__ key with Object.defineProperty, the guard parseHeaders already uses in lib/core/util.js. It is exported and used by all three writers.

The object stays plain rather than switching to a null prototype, because it is serialized into snapshot files and handed back to user code.

After the change the same pair hashes differently and the header survives:

headers stored: {"__proto__":"a","x-real":"same"}
hashes equal:   false

One test in test/snapshot-recorder.js, next to the existing formatRequestKey tests.

test/snapshot*.js 48 passing, test/mock*.js 339 passing, lint clean.

Features

N/A

Bug Fixes

A header named __proto__ is no longer dropped from a recorded snapshot and no longer makes two different requests share a snapshot key.

Breaking Changes and Deprecations

None.

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(mock): keep a header named __proto__ in snapshots
0f05f25
normalizeHeaders and both header filters assigned into a plain object, so the
__proto__ key reached the Object.prototype setter and the header was dropped.
formatRequestKey feeds those headers to createRequestHash, so two requests
differing only by that header produced the same snapshot key: one entry in
record mode, the wrong response in playback.

Writes now go through a setHeader helper using Object.defineProperty, the
guard parseHeaders already uses.
Copilot AI lite review requested due to automatic review settings August 8, 2026 02:38
Copilot AI reviewed Aug 8, 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
This was referenced Aug 8, 2026
fix(cache): keep a header named __proto__ out of the prototype chain #5667
Closed
fix: keep a header named __proto__ across features #5688
Merged
@luantaraschi

luantaraschi commented Aug 14, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Folded into #5688, where the guard lives once as setHeader in lib/core/util.js instead of being written out per feature. The snapshot fix and its test moved over unchanged.

Closing this one so your queue stays readable. Happy to reopen it if you would rather look at this site on its own.

All reactions

Sorry, something went wrong.

Uh oh!

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

@luantaraschi luantaraschi closed this Aug 14, 2026
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

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.

2 participants

@luantaraschi
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.