Repository navigation
Description
Summary
Sōzu accepts an HTTP/1.1 Content-Length whose value carries a leading + (Content-Length: +5), frames the body on it, and forwards the header verbatim to the backend. RFC 9110 §8.6 defines Content-Length = 1*DIGIT and says a sender MUST NOT forward a message whose Content-Length does not match that grammar. A backend that rejects, ignores, or re-reads +5 differently from Sōzu disagrees on where the request ends: the body Sōzu forwarded as part of the first request becomes the start of a second request on the backend connection — one Sōzu never routed, never checked against the frontend's Basic auth, and never decorated with Sozu-Id / X-Forwarded-* / Forwarded. This is the same class as #1650: HTTP request smuggling (CWE-444).
The response direction has the mirror defect: a backend's Content-Length: +5 is forwarded to the client unchanged.
Mechanism
- kawa 0.7.1,
process_headers(src/protocol/h1/parser/mod.rs), reads the value withnom::ParseTo::parse_to, which isfrom_utf8(..).parse::<usize>().usize::from_straccepts one leading+, so+5yieldsBodySize::Length(5). - The header block is left in place (only duplicates of equal value, and a
Content-Lengthbeside aTransfer-Encoding, are elided), so the original spelling is what the H1 serializer emits. HttpContext::on_request_headers(lib/src/protocol/kawa_h1/editor.rs) validatesTransfer-Encodingframing (the CL.TE guard) but never theContent-Lengthvalue;HttpContext::on_response_headersdoes not either.- The H2 path is not affected:
pkawa::handle_header→write_regular_header(lib/src/protocol/mux/pkawa.rs) already requires every byte of an H2content-lengthto be an ASCII digit and returnsRejectReason::DuplicateClotherwise.
Reproduction
POST /api HTTP/1.1
Host: localhost
Content-Length: +5
GET /
Measured on main (3ee0b6d) with the e2e harness, the backend receives:
POST /api HTTP/1.1\r\nHost: localhost\r\nContent-Length: +5\r\nX-Forwarded-For: …\r\n…\r\n\r\nGET /
and a backend answering HTTP/1.1 200 OK\r\nContent-Length: +5\r\n\r\nhello reaches the client as HTTP/1.1 200 OK\r\nContent-Length: +5\r\nSozu-Id: …\r\n\r\nhello.
Other non-canonical spellings
Measured against usize::from_str and the kawa parser:
| Value | kawa 0.7.1 | Note |
|---|---|---|
+5, +0 |
accepted, forwarded verbatim | the defect |
-0, -5, + |
refused (400) | |
5, 5, 5,5 |
refused (400) | RFC 9110 §8.6 permits rejecting a list of identical values |
5 5, 0x5, 5.0, 1e1 |
refused (400) | |
99999999999999999999999 |
refused (400) | usize overflow |
| U+0665, U+FF15 (non-ASCII digits) | refused (400) | |
| empty | refused (400) | |
005 |
accepted, forwarded verbatim | matches 1*DIGIT: legal |
Content-Length: 5 then Content-Length: +5 |
second line elided, 5 forwarded |
only canonical bytes leave |
Content-Length: +5 then Content-Length: 5 |
second line elided, +5 forwarded |
An exact usize::MAX parses everywhere; it is not a framing disagreement (the body never completes) and is out of scope here.
Expected
- A request whose forwarded
Content-Lengthis not exclusively ASCII digits is answered 400 before routing, and no byte reaches a backend. - A backend response carrying one fails the response parse and is answered 502; nothing of it reaches the client.
References
- RFC 9110 §8.6 (
Content-Length = 1*DIGIT; a sender MUST NOT forward a message with an invalid value; a recipient MAY reject or collapse a list of identical values). - RFC 9112 §6.3 rule 5 (an invalid
Content-LengthwithoutTransfer-Encodingis an unrecoverable framing error; a server MUST respond 400, a proxy receiving it in a response MUST respond 502 and close). - HAProxy's
http_parse_cont_len_header(src/http.c) accepts only digits and optional surrounding whitespace/commas: a+fails the parse. - Parser-side counterpart: h1: Content-Length accepts a leading '+' (usize::from_str) and is forwarded verbatim CleverCloud/kawa#25 (neighbour: h1: a request without Content-Length or Transfer-Encoding is parsed as close-delimited CleverCloud/kawa#23).
Activity
fix(h1): reject a Content-Length that is not 1*DIGIT instead of forwa…
fix(h1): reject a Content-Length that is not 1*DIGIT instead of forwa…
chore(deps): bump kawa to 0.7.2 (#1655)