fix(decompress): treat inherited Object.prototype names as unsupported encodings - #5807
Open
NgoQuocViet2001 wants to merge 1 commit into
Open
fix(decompress): treat inherited Object.prototype names as unsupported encodings#5807NgoQuocViet2001 wants to merge 1 commit into
NgoQuocViet2001 wants to merge 1 commit into
Conversation
…d encodings supportedEncodings is a plain object literal, so the guard if (!supportedEncodings[encoding]) resolves inherited names through the prototype chain instead of rejecting them. onResponseStart lowercases the header first, which leaves exactly two reachable from the wire: constructor and __proto__. A response carrying Content-Encoding: constructor calls Object(), pushes the plain object it returns into the decompressor chain, and the request then never settles; __proto__ throws TypeError out of the interceptor. Give the table a null prototype so only its own entries can match.
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.
Problem
supportedEncodingsis a plain object literal, so the unsupported-encoding guard resolves inherited names through the prototype chain:onResponseStartlowercases the header before the lookup, and exactly twoObject.prototypeown-property names survive lowercasing —constructorand__proto__. Both are truthy, so both walk past the guard and get called.Effect
Measured against
mainwith a plainnode:httporigin and a client composed withinterceptors.decompress():constructoris the bad one:Object()returns a plain object, that object is pushed into the decompressor chain as if it were a stream, andclient.request()then neither resolves nor rejects. NouncaughtException, no teardown — the caller's await and the socket both leak. A remote origin (or any intermediary that rewritesContent-Encoding) can wedge a client with a single response header.An unrecognised encoding is supposed to pass through untouched, which is what
bogus-encodingshows.Fix
Give the lookup table a null prototype, so only its own entries can match. This matches the existing style in
lib/core/util.js:973,lib/util/runtime-features.js:7andlib/web/eventsource/eventsource.js:458.All five cases above then pass through cleanly.
Test plan
test/interceptors/decompress.jsbeside the existingshould pass through unsupported encoding, coveringconstructor,__proto__andgzip, constructor.node --test test/interceptors/decompress.js→ 38 passing.__proto__: nullline makes theconstructorcase hang rather than fail — the test run never terminates, which is the defect itself.npx standardon both touched files → clean.