fix: exclude Transfer-Encoding header during page cloning to prevent … - #337
Open
Ricardo08S wants to merge 1 commit into
Open
fix: exclude Transfer-Encoding header during page cloning to prevent …#337Ricardo08S wants to merge 1 commit into
Ricardo08S wants to merge 1 commit into
Conversation
…malformed chunked responses
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
When SNARE clones a target page that responds with
Transfer-Encoding: chunked(common for sites behind CDNs/proxies such as Cloudflare), the cloner stores
this header verbatim in
meta.json. When SNARE later serves the cloned page,it replays this header as-is, while aiohttp independently determines the
actual transfer encoding of the served body (since SNARE serves static cloned
content, not a real chunked stream).
This results in a response that advertises
Transfer-Encoding: chunkedbutwhose body is not actually formatted as valid HTTP chunks, producing a
response that's invalid per RFC 7230. Strict HTTP clients (e.g. curl 8.x)
reject this outright:
curl: (56) Illegal or missing hexadecimal sequence in chunked-encodingRoot cause
Cloner.get_headers()already excludes several headers known to causeconflicts when replayed by a different server (
content-length,content-encoding,cache-control, etc.), buttransfer-encodingwasmissing from this list. Since SNARE does not actually replay the original
chunked stream byte-for-byte, it should not advertise a transfer encoding
that depends on implementation details of the origin server.
Reproduction
Transfer-Encoding: chunked(e.g. adomain proxied through Cloudflare):
Content-Length(added by aiohttp) andTransfer-Encoding: chunked(replayed from meta.json) present in the response simultaneously— an invalid combination per RFC 7230 §3.3.3 — and curl fails to parse the
body as valid chunked data.
Fix
Add
transfer-encodingtoignored_headers_lowercaseincloner.py, thesame way
content-lengthandcontent-encodingare already excluded foranalogous reasons.
Testing
curlfails withIllegal or missing hexadecimal sequence in chunked-encoding.Content-Length-basedresponse, full body delivered intact.