fix: keep a header named __proto__ across features - #5688
Open
luantaraschi wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 theObject.prototypesetter 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.parseHeadersinlib/core/util.jsalready guards that withObject.defineProperty. Four other accumulators did not, and each of the superseded PRs carried its own copy of the guard. Three of them had the identicalsetHeaderfunction written out three times, which is what you spotted.Changes
The guard becomes
setHeaderinlib/core/util.js, exported next toparseHeaders, and the four sites call it:lib/web/fetch/headers.js, the entries object built from the headers listlib/util/cache.js,appendHeaderandmakeDeduplicationKeylib/mock/snapshot-utils.jsandlib/mock/snapshot-recorder.js, header normalizing and filteringlib/dispatcher/client-h2.js,buildRequestHeadersThree 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:
parseHeaderskeeps 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
getCookiesa 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 fetchHeaderslist, 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.
setHeaderis a new export onlib/core/util.js, nothing else changed shape.Testing
Five new tests, one per site plus the deduplication key collision. Each of them fails on
mainand passes here:With the change, on Node 22.20.0 on Windows:
test/prototype-headers.js4 passing,test/cache-interceptor77 passing,test/interceptors/deduplicate.js35 passing,test/snapshot-recorder.js15,test/snapshot-testing.js32,test/snapshot-redirect-interceptor.js1,test/fetch/headers.js66,test/util.js46 passing with 1 skipped, and everytest/http2-*.jsfile green includinghttp2-request-never-settles.js.eslintis clean.Status