Skip to content

h1: a signed or non-canonical Content-Length is accepted and forwarded verbatim #1652

Closed

Description

@FlorentinDUBOIS

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 with nom::ParseTo::parse_to, which is from_utf8(..).parse::<usize>(). usize::from_str accepts one leading +, so +5 yields BodySize::Length(5).
  • The header block is left in place (only duplicates of equal value, and a Content-Length beside a Transfer-Encoding, are elided), so the original spelling is what the H1 serializer emits.
  • HttpContext::on_request_headers (lib/src/protocol/kawa_h1/editor.rs) validates Transfer-Encoding framing (the CL.TE guard) but never the Content-Length value; HttpContext::on_response_headers does 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 H2 content-length to be an ASCII digit and returns RejectReason::DuplicateCl otherwise.

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-Length is 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

Activity

  1. added a commit that references this issue on Sep 28, 2026
    8c95973
  2. added a commit that references this issue on Sep 28, 2026
    c086b45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions