Repository navigation
Conversation
Three related fixes in the Fetch interception response handlers: 1. Decode non-base64 getResponseBody bodies as latin1 (CDP convention) instead of utf8 — utf8 mangles bytes >= 0x80 (CJK content etc.) and breaks content-length parity. 2. Default CORS preflight Origin/Method/Headers values before building the fulfillRequest response. These request headers are optional per the CORS spec; when absent, undefined header values make Chrome's CDP bindings reject the whole fulfillRequest call. 3. Recompute content-length from the decoded buffer and strip content-encoding on captured responses. CDP returns the decompressed body while the captured headers carry the upstream compressed-size content-length; passing both through verbatim desyncs HTTP framing — the surplus body bytes get parsed as the start of the next response on reused keep-alive connections, corrupting browsers and chained proxies downstream.
m4dni5
marked this pull request as ready for review
September 9, 2026 23:53
Owner
|
Thank you for the report! Merged a fix for it. |
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
Responses captured through
Fetchinterception reach the client with a broken body/length/encoding triple. Clients that reuse connections — browsers, chained proxies — see truncated scripts, cancelled stylesheets, and pages that hang. Single-request clients like curl hide the damage, so these bugs are easy to miss.Root causes
Three independent bugs in the capture handlers in
cdp.js:1. Bodies decoded with the wrong encoding. Non-base64
Fetch.getResponseBodybodies are latin1-encoded text, but the code decodes them as utf8. Bytes >= 0x80 get mangled, changing the body length.2. Headers describe a different body than the one sent.
Fetch.getResponseBodyreturns the decompressed body, but the captured headers still carry the upstream compressed-sizecontent-lengthandcontent-encoding. The body is therefore longer than the declared length, and the surplus bytes get parsed as the start of the next response on that connection, corrupting everything after it.3. Optional CORS headers crash the preflight mock. The mocked preflight copies
Access-Control-Request-Method/Headersfrom the request. Both are optional per the CORS spec; when absent, the emitted headers havevalue: undefined, and Chrome's CDP bindings reject the entireFetch.fulfillRequestcall, killing the fetch.Fix
content-lengthfrom the actual body and stripcontent-encoding.Access-Control-Allow-Headerswhen the request asked for it.Verification
content-lengthmatches the delivered body on responses checked.