HTTP/1 chunk-size line tail is not validated in Mint, enabling response-framing desync
Description
Mint's HTTP/1 chunked-body decoder validates only the hexadecimal digits of a chunk-size line and skips every byte between the last digit and the CRLF. RFC 9112 permits only a ;-introduced chunk extension there. On a pooled keep-alive connection that traverses an RFC-strict intermediary, a malicious origin can send chunk-size lines that Mint accepts but the intermediary rejects, producing a response-smuggling primitive against subsequent requests on the connection.
Details
Mint.HTTP1.Parse.chunk_size/1 in lib/mint/http1/parse.ex stops at the first non-hexadecimal byte and returns the remainder unexamined. Mint.HTTP1.decode_body/5 in lib/mint/http1.ex then hands that remainder to Parse.ignore_until_crlf/1, which advances over any byte until it finds CRLF. The accepted grammar is therefore 1*HEXDIG *OCTET CRLF:
5ZZZZZ,5 anything at all,5<TAB>foo,5 9and5}~!are accepted as chunk size 5.0ZZZZand0 9are accepted as the terminating zero-length chunk and end the body.5;name=value, a legal chunk extension, is accepted and must stay accepted.
The sibling Content-Length parser, Mint.HTTP1.Parse.content_length_header/1, trims trailing whitespace and requires the whole remaining value to be digits, so the two parsers disagree about the same class of input.
The fix adds Mint.HTTP1.Parse.chunk_extensions/1, which accepts only optional whitespace, ;-introduced extensions with token or quoted-string values, and the CRLF, and returns :invalid_chunk_size for anything else on both data chunks and the terminating chunk.
PoC
- Serve one
HTTP/1.1 200 OKresponse withtransfer-encoding: chunkedfrom a loopback TCP server that controls the chunk-size line exactly. - Connect with
Mint.HTTP1(mint 1.10.0) and stream the response. - Chunk-size lines
+5,Z5and00000000000000005are refused with:invalid_chunk_size, confirming the earlier chunk-size fixes are present. 5ZZZZZ,5 anything at all,5<TAB>foo,5 9and5}~!are each accepted with bodyhello;0ZZZZand0 9in place of the final0are accepted and end the body.Content-Length: +5,5ZZZand5 9are refused with:invalid_content_length_headerin the same run.
Impact
An attacker who controls or influences an HTTP/1 origin that a Mint client talks to through an RFC-strict pooled intermediary can make the intermediary and Mint disagree on chunk boundaries and on where the response ends, so bytes from one response are attributed to the next request sharing the connection. No smuggling chain against a specific intermediary was built; the divergence requires a fronting element stricter than Mint.
References
- Introduction commit: 6008958
- Patch commit: c823778