Skip to main content
Menu
Advisories

HTTP/1 chunk-size line tail is not validated in Mint, enabling response-framing desync

GHSA-RJ5M-69WP-CXQ9Published Updated GitHub

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 9 and 5}~! are accepted as chunk size 5.
  • 0ZZZZ and 0 9 are 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

  1. Serve one HTTP/1.1 200 OK response with transfer-encoding: chunked from a loopback TCP server that controls the chunk-size line exactly.
  2. Connect with Mint.HTTP1 (mint 1.10.0) and stream the response.
  3. Chunk-size lines +5, Z5 and 00000000000000005 are refused with :invalid_chunk_size, confirming the earlier chunk-size fixes are present.
  4. 5ZZZZZ, 5 anything at all, 5<TAB>foo, 5 9 and 5}~! are each accepted with body hello; 0ZZZZ and 0 9 in place of the final 0 are accepted and end the body.
  5. Content-Length: +5, 5ZZZ and 5 9 are refused with :invalid_content_length_header in 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

Affected versions

References

GitHub · elixir-mint/mint