Skip to content

h1: a request without Content-Length or Transfer-Encoding swallows the pipelined requests behind it #1650

Closed

Description

@FlorentinDUBOIS

Summary

An HTTP/1.1 request that carries neither Content-Length nor Transfer-Encoding (a plain GET, but equally HEAD, DELETE, a body-less POST, …) is read by Sōzu as a close-delimited message. Any request pipelined behind it in the same read is therefore consumed as the first request's "body" and forwarded raw to the first request's backend: it is never routed, never checked against the frontend's Basic auth, and carries none of the headers Sōzu adds (Sozu-Id, X-Forwarded-For, Forwarded, X-Forwarded-Proto, X-Forwarded-Port, X-Request-Id). This is HTTP request smuggling (CWE-444).

Mechanism

  • kawa 0.7.1 (kawa::h1::parse, src/protocol/h1/parser/mod.rs) leaves body_size at BodySize::Empty when neither header is present and, after process_headers, maps BodySize::Empty to ParsingPhase::Body with expects = 1 — for a request exactly as for a response.
  • In the ParsingPhase::Body arm, BodySize::Empty takes the whole remaining buffer (taken = len) as a Block::Chunk, and never decrements expects, so the request is never terminated.
  • Sōzu's request callback, HttpContext::on_request_headers (lib/src/protocol/kawa_h1/editor.rs), does not correct this: the guard that would have done so is commented out there (if self.method == Some(Method::Get) && request.body_size == kawa::BodySize::Empty { … Terminated }), and it would only have covered GET.
  • ConnectionH1::readable (lib/src/protocol/mux/h1.rs) keeps the front kawa in its body phase and keeps reading, and every byte the client sends before the first response completes is forwarded to the first request's backend as body data.

Scenario

One write(2) on a keep-alive connection to an HTTP or HTTPS listener with two clusters routed by path (/a → cluster_a, /b → cluster_b):

GET /a/first HTTP/1.1\r\nHost: localhost\r\n\r\nGET /b/second HTTP/1.1\r\nHost: localhost\r\n\r\n

cluster_a's backend receives the first request, edited, followed by the second one verbatim:

GET /a/first HTTP/1.1
Host: localhost
X-Forwarded-For: 127.0.0.1
…
Sozu-Id: 01M3KAX0331KN97P81H6552FY8

GET /b/second HTTP/1.1
Host: localhost

cluster_b never sees a connection; the client gets one response. The same holds for HEAD, DELETE and POST as the first method, on clear and TLS listeners, and when /b is replaced by a frontend with required_auth = true: the pipelined request reaches the first cluster's backend without any credential ever being checked. A backend that serves pipelined requests (most do) answers it.

Impact

  • Routing bypass: a request meant for (or forbidden on) one cluster is delivered to another cluster's backend, which then answers it under its own authority.
  • Basic-auth bypass: per-frontend authentication runs on the first request only; the smuggled one is never checked.
  • Forwarding-header bypass: the smuggled request carries whatever X-Forwarded-For / Forwarded / X-Real-IP the client chose, with no Sōzu hop appended and no elision applied, so a backend that trusts those headers for access control or logging trusts attacker input. It carries no Sozu-Id, so it is invisible in Sōzu's access log.

RFC

RFC 9112 §6.3, rule 7: "If this is a request message and none of the above are true, then the message body length is zero (no message body is present)." Rule 8 (read until close) applies to responses only.

Proposed fix

End such a request after its headers in HttpContext::on_request_headers, for every method and version: when kawa's H1 parser has selected close-delimited framing for a request (parsing_phase == ParsingPhase::Body && body_size == BodySize::Empty), set ParsingPhase::Terminated. kawa pushes the end-of-headers Flags block right after the callback with end_stream: kawa.is_terminated(), so the request is forwarded complete and the pipelined request stays unparsed until the keep-alive branch of ConnectionH1::writable parses it on its own.

The ParsingPhase::Body conjunct matters: pkawa::handle_header calls the same callback for an H2 request while its body_size is still Empty, and only afterwards frames a request whose DATA follows as chunked. Keying on Empty alone would drop those bodies. Close-delimited responses (on_response_headers) are legitimate and must stay untouched.

The parser-level defect is reported to kawa separately; the Sōzu guard stays independent of it.

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