Repository navigation
fix(h1): end a request without Content-Length or Transfer-Encoding after its headers - #1651
Merged
Merged
Conversation
…ter its headers kawa 0.7.1 parses a request with neither header as close-delimited: `kawa::h1::parse` maps `BodySize::Empty` to `ParsingPhase::Body` for a request as for a response, and that arm takes every byte left in the buffer (CleverCloud/kawa#23). A request pipelined in the same segment behind a plain GET (or HEAD, DELETE, a body-less POST) was forwarded raw to the first request's backend as its body: never routed, never checked against the frontend's Basic auth, with no Sozu-Id and no X-Forwarded-*/Forwarded hop (CWE-444). RFC 9112 §6.3 rule 7 gives such a request a zero-length body whatever its method or version; read-until-close (rule 8) is for responses only. `HttpContext::on_request_headers` now sets `ParsingPhase::Terminated` when it finds `ParsingPhase::Body` on `BodySize::Empty`, replacing the commented-out GET-only guard. kawa pushes the end-of-headers flags right after the callback with `end_stream: is_terminated()`, so the request is forwarded complete and the pipelined one is parsed, routed, authenticated and edited on its own by the keep-alive branch of `ConnectionH1::writable`. The `ParsingPhase::Body` conjunct confines the rule to the H1 parser: `pkawa::handle_header` calls the same callback for an H2 request while its body_size is still Empty, then frames a request whose DATA follows as chunked unless the callback terminated it. Close-delimited responses are unchanged. No allocation is added. Tests: a_request_without_length_ends_after_its_headers (GET, HEAD, DELETE, POST, HTTP/1.0 POST, Expect: 100-continue, Upgrade: websocket), a_framed_request_and_an_unframed_response_keep_their_bodies, an_h2_request_is_left_for_pkawa_to_frame, and six test_h1_unframed_request_then_* e2e tests (same cluster, another cluster, a Basic-auth-gated cluster; clear and TLS; four methods). All 24 e2e cases were red on 96b4bca: the first request's backend received both request lines under one Sozu-Id. Closes #1650 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 28, 2026 07:13
FlorentinDUBOIS
deleted the
fix/h1-request-without-length-has-no-body
branch
September 28, 2026 08:15
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 28, 2026
…rding it verbatim (#1653) ## Summary kawa 0.7.1 reads a `Content-Length` value with `usize::from_str`, which accepts one leading `+` (CleverCloud/kawa#25). `Content-Length: +5` framed a 5-byte body and was forwarded to the backend **verbatim**; a backend that refuses, ignores or re-reads `+5` takes the body for the start of the next request — never routed by Sōzu, never checked against the frontend's Basic auth, without `Sozu-Id` / `X-Forwarded-*` (CWE-444, the class of #1650). A backend's `Content-Length: +5` also reached the client unchanged. RFC 9110 §8.6: `Content-Length = 1*DIGIT`, and a sender MUST NOT forward a value that does not match. RFC 9112 §6.3 rule 5: unrecoverable framing error — 400 for a request, 502 for a response received by a proxy. ## Change - `HttpContext::on_request_headers` (`lib/src/protocol/kawa_h1/editor.rs`): right after the CL.TE guard, a request whose non-elided `Content-Length` is not exclusively ASCII digits is rejected (400) before routing. Counter `http.frontend.content_length_invalid`, contextual `warn!`. - `HttpContext::on_response_headers`: same check first; the failed parse makes `shared::end_stream_decision` answer 502. Counter `http.backend.content_length_invalid`. - Shared helper `has_non_digit_content_length`, zero allocation (the editor allocation tests still pass unchanged). - Mirrors the H2 side, `pkawa::write_regular_header` → `RejectReason::DuplicateCl`, which already refused a non-digit `content-length`. ## Non-canonical spellings — decision per form | Value | Before | After | |---|---|---| | `+5`, `+0` | accepted, forwarded verbatim | **400** (this guard) | | `-0`, `+`, `5 5`, `0x5`, `5.0`, overflow, non-ASCII digits, empty | 400 (kawa) | 400, guard is defense in depth | | `5, 5` | 400 (kawa) | 400 — RFC 9110 §8.6 allows reject or collapse; HAProxy's `http_parse_cont_len_header` collapses, Sōzu keeps rejecting | | `005` | forwarded as sent | unchanged: `1*DIGIT`, legal; the H2 path forwards it the same way | | `5` then `+5` | second line elided, `5` forwarded | unchanged (only canonical bytes leave) | | `+5` then `5` | `+5` forwarded | **400** | | `+5` beside `Transfer-Encoding: chunked` | CL elided by kawa | unchanged | | backend `Content-Length: +5` | forwarded to client | **502** | ## Tests Unit (`editor.rs`): `a_request_content_length_that_is_not_only_digits_is_rejected`, `a_forwarded_content_length_is_only_digits`, `a_response_content_length_that_is_not_only_digits_is_rejected`. E2E (`e2e/src/tests/h1_security_tests.rs`): `test_h1_signed_content_length_request_rejected`, `test_h1_signed_content_length_response_rejected`, `test_h1_leading_zero_content_length_forwarded`. Seen red on `main` (3ee0b6d) before the fix: - unit: `plus: … got Terminated with Length(5)`; `200 OK: a signed Content-Length must fail the response, got Terminated` - e2e request: backend received `POST /api HTTP/1.1\r\nHost: localhost\r\nContent-Length: +5\r\n…\r\n\r\nGET /` - e2e response: client received `HTTP/1.1 200 OK\r\nContent-Length: +5\r\nSozu-Id: …\r\n\r\nhello` After: 400 with no backend connection; 502 with neither `+5` nor the body; `005` forwarded and answered 200. Non-regression (CL, chunked, `test_h1_pipelining`, TE guard incl. `test_h1_te_ows_forwarded_canonically`) via the full workspace suite on this branch. ## Commands run ``` cargo +nightly fmt --all -- --check cargo build --locked cargo build --all-features --locked cargo clippy --all-targets --locked -- -D warnings cargo clippy --all-targets --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- -D warnings cargo test --workspace --locked -- --skip tests::fuzz_tests:: --test-threads=8 RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked python3 .github/scripts/check_doc_citations.py --self-test | --root testdata (exit 1 expected) | plain | --base origin/main ``` ## Docs `kawa_h1/LIFECYCLE.md` (Content-Length value clause), `doc/configure.md` (two metric rows; each is also counted in the existing `http.{frontend,backend}_parse_errors`), `CHANGELOG.md` (Security), `CLAUDE.md` (Security-sensitive areas). `doc/configure_admin_ops.md`'s `doc/configure.md:3070` line citation, moved by the new rows, now names the metric row instead. Interaction with #1651: both touch `on_request_headers`, in different places (this guard sits right after the CL.TE guard; #1651's branch after the request-line capture). Measured: `git merge-tree --write-tree origin/fix/h1-request-without-length-has-no-body HEAD` conflicts on `CLAUDE.md` only (both extend the same editor.rs line). In a throwaway merge of both branches, `cargo test -p sozu-lib --lib -- kawa_h1::editor` passed 33/33 and the e2e set (`unframed_request` ×6, `signed_content_length` ×2, `leading_zero_content_length`, `te_ows`, `valid_framing`, `test_h1_pipelining`) passed 12/12. Closes #1652 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 28, 2026
## What kawa 0.7.2 fixes [kawa 0.7.2](https://github.com/CleverCloud/kawa/releases/tag/v0.7.2), published 2026-09-28: - [CleverCloud/kawa#26](CleverCloud/kawa#26): a `Content-Length` value must be `1*DIGIT` (RFC 9110 §8.6). kawa checks the bytes before parsing and before calling `on_headers`, so `+5` is refused by the parser. - [CleverCloud/kawa#27](CleverCloud/kawa#27): a request with neither `Content-Length` nor `Transfer-Encoding` becomes `ParsingPhase::Terminated` as soon as its headers are parsed (RFC 9112 §6.3 rule 7). The end-of-headers `Flags` block carries `end_stream: true`, and the bytes that follow stay in `unparsed_data()`. Responses stay close-delimited. - [CleverCloud/kawa#24](CleverCloud/kawa#24): fixes an arithmetic underflow in `Store::consume`. ## Why both Sōzu guards stay Sōzu already worked around the first two bugs: - #1651: the `ParsingPhase::Body` + `BodySize::Empty` branch of `HttpContext::on_request_headers`; - #1653: `has_non_digit_content_length`, which answers 400 on a request and 502 on a response. With 0.7.2, neither guard fires on traffic kawa accepts. **Measured:** with all three call sites disabled (`if false`), every `kawa_h1::editor` unit test passes except one row that encoded kawa 0.7.1's behaviour (see below). The 9 related e2e tests (`test_h1_signed_content_length_*`, `test_h1_leading_zero_content_length_forwarded`, `test_h1_unframed_request_then_*`) also pass. This PR keeps both guards unchanged as defense in depth against a kawa regression, and removes no code. It only corrects the text that described them as live: - `lib/src/protocol/kawa_h1/editor.rs`: - the doc of `has_non_digit_content_length`; - the comments on the Content-Length clause, the rule-7 branch and the response mirror; - the version text of the TE comment (the pin moves from `^0.7.1` to `^0.7.2`; TE handling did not change); - the four `TO SEE THIS RED` recipes, which now say that deleting the Sōzu guard alone no longer turns the test red, and how to reproduce the bug instead: - `the_content_length_helper_judges_every_non_digit_value` still goes red on the helper by itself; - or pin kawa 0.7.1 (`kawa = { version = "=0.7.1", … }` in the root `Cargo.toml`, then `cargo update -p kawa --precise 0.7.1`) and delete the guard. - `lib/src/protocol/kawa_h1/LIFECYCLE.md`: §2 intro, §2.1 (TE text and the Content-Length clause; the table now has a kawa 0.7.1 column and a kawa ≥ 0.7.2 column), and §2.2. - `CLAUDE.md` (security-sensitive areas), `doc/configure.md` and `lib/src/metrics/names.rs`: the `http.{frontend,backend}.content_length_invalid` counters now stay at zero unless kawa regresses. The 400/502 answers are unchanged and still counted in `http.frontend_parse_errors` / `http.backend_parse_errors`. - `e2e/src/tests/h1_security_tests.rs`: the banners of the signed-Content-Length and unframed-request tests. - `CHANGELOG.md`: a `🔄 Changed` entry. **Pin recipe verified** (then fully reverted): with kawa pinned to 0.7.1 and the three guards disabled, three tests go red: - `a_request_without_length_ends_after_its_headers` fails with `GET / HTTP/1.1: must end after its headers, got Body`; - `a_request_content_length_that_is_not_only_digits_is_rejected` fails with `plus: … got Terminated with Length(5)`; - `a_response_content_length_that_is_not_only_digits_is_rejected` fails with `200 OK: … got Terminated`. ## Test changed, and why `a_forwarded_content_length_is_only_digits` failed under 0.7.2: ``` canonical-then-plus: must be accepted, got Error { marker: Headers, kind: Processing { message: "Invalid Content-Length field value" } } ``` The input was `Content-Length: 5` followed by `Content-Length: +5`. kawa 0.7.1 parsed the second line as 5, elided it as equal to the first, and forwarded `5`. The old assertion therefore encoded kawa 0.7.1's leniency, the very bug kawa#26 fixes: a `+5` field line is an invalid Content-Length, and RFC 9112 §6.3 rule 5 makes that an unrecoverable framing error. It is also inconsistent with the reverse order (`+5` then `5`), which Sōzu already rejected. The row now lives in `a_request_content_length_that_is_not_only_digits_is_rejected` and asserts refusal. That is a stronger assertion, not a weaker one. Its doc notes that, under a kawa 0.7.1 pin, this row fails even with the Sōzu clause in place, because the refusal comes from kawa alone (verified). No other test changed. ## Reference sweep `rg -n 'kawa' --glob '*.toml' --glob '*.md'` and `rg -n '0\.7\.1'`: - `Cargo.toml` `kawa = "^0.7.1"`: **updated** to `^0.7.2`. `lib/Cargo.toml` (`workspace = true`, `kawa/simd`, `kawa/tolerant-parsing`): unaffected, it inherits the workspace version. - `fuzz/Cargo.toml`: unaffected, it has no direct kawa dependency (through `sozu-lib`). `fuzz/Cargo.lock`: **updated**, kawa entry only. - `Cargo.lock`: **updated**, kawa entry only. `cargo update -p kawa --precise 0.7.2` also re-resolved `tempfile → getrandom 0.3.4 → 0.4.3`, so the entry was edited by hand, and `cargo metadata --locked` accepts it. - `os-build/config.toml`, `bin/config.toml`: unaffected, these are path mentions of `kawa_h1/answers.rs`. - `CLAUDE.md:132`, `doc/configure.md` (metric rows 2835 and 2837), `lib/src/protocol/kawa_h1/LIFECYCLE.md`, `lib/src/protocol/kawa_h1/editor.rs`, `e2e/src/tests/h1_security_tests.rs` (13b banner, rule-7 banner): **updated**. - `CLAUDE.md` / `doc/configure.md` "kawa >= 0.7.1 excludes OWS", `e2e/src/tests/h1_security_tests.rs:1425` and `:2176`: unaffected, they describe OWS trimming and a pre-0.7.1 history, and both remain true. - `lib/src/protocol/mux/{stream.rs,mod.rs,h2.rs}` "kawa-0.7.1 `storage/repr.rs`" / "kawa 0.7.1 reads the status": unaffected. kawa#24 changes the arithmetic of `consume`, not the FRONT/APPEND layout or the status parse those comments cite. The H2 code is also left alone because another branch is working on it. - `CHANGELOG.md` historical entries (kawa 0.7.1 bump, #1650, #1652, TE entries): unaffected, they describe the state at the time. ## Validation - `cargo +nightly fmt --all -- --check` → exit 0 - `cargo build --locked` → exit 0 - `cargo build --all-features --locked` → exit 0 - `cargo clippy --all-targets --locked -- -D warnings` → exit 0 - `cargo clippy --all-targets --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- -D warnings` → exit 0 - `cargo test --workspace --locked -- --skip tests::fuzz_tests:: --test-threads=8` → exit 0 - `python3 .github/scripts/check_doc_citations.py --self-test` / `--root .` / `--root . --base origin/main` / `--audit --root .` → exit 0 (all four) - `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked` → exit 0 - `cd fuzz && cargo check --locked` → exit 0 ## Protocol / security impact None on the wire: the same requests and responses are refused with the same status codes. The only observable change is which counter records the refusal. A non-`1*DIGIT` Content-Length is now counted in `*_parse_errors` and no longer in `*.content_length_invalid`. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 28, 2026
…h the request lifecycles Record the work merged from 2026-09-26 to 2026-09-28 that cut the system calls and heap allocations a worker pays per request, and bring the request lifecycle documentation back in line with the code. - doc/hot_path_zero_copy.md (new, linked from doc/README.md): goal and rules, the measurement method (intentrace, an LD_PRELOAD descriptor tracer and allocation counter, crate::test_allocations), one section per change with its before/after figures and pull requests, the correctness and safety fixes found along the way, the invariants and the tests that hold them, and the list of pull requests. - A closing measurement, taken on 2026-09-28 with release binaries at b5169d4 and c086b45 interleaved (crypto-ring, one worker, file:// access log, python backend, curl, N=20, intentrace), per request: H1 26.25-26.70 -> 18.45-18.85 system calls, 83.65-83.85 -> 39.95-40.35 heap operations; H1 keep-alive 14.75 -> 9.65 and 50.80 -> 7.80; H2 over TLS 61.25-61.60 -> 40.15-40.75 and 412.15-413.90 -> 240.60-241.75; H2 multiplexed 25.05 -> 13.55; TCP relay 39.00-39.10 -> 36.05-36.15. - doc/lifetime_of_a_session.md, rewritten: event loop, accept, TLS, PROXY pre-flight, the H1, H2, TCP and UDP lifecycles, close, soft stop and GOAWAY, with the system calls and allocations each step still pays. It corrects three statements the code contradicted: a reused keep-alive backend gets no liveness probe, a TCP session is closed on the first soft-stop pass, and a UDP listener is drained by UdpProxy::notify's SoftStop arm rather than by shutting_down. - The H2 soft stop follows #1654 (#1647): a draining session waits for a header block still arriving or a request awaiting its backend link, and a forced close is preceded by a final GOAWAY. The TCP soft stop is described as it has behaved since be5dd44 (2020-01-10). - The H1 smuggling fixes (#1651, #1653) are described as shipped: kawa 0.7.2 (#1655) fixes both upstream, the guards stay as defense in depth, and their content_length_invalid counters stay at zero unless kawa regresses. - lib/src/protocol/udp/LIFECYCLE.md: drop the SelectBackend / BackendResolved round trip that no longer exists (selection moved into the core), and add a per-datagram cost table. - lib/src/protocol/mux/LIFECYCLE.md: a section on what a request costs on the nominal path; a stale Router::connect reference is now Router::plan_connect. - CHANGELOG, mux LIFECYCLE, h2_mux_internals: an H2 backend connection belongs to one Mux session and carries the streams of one frontend connection only; the #1627, #1631 and #1632 entries no longer call it shared by several clients. A Documentation entry is added. - Line citations in the touched documents (lifetime_of_a_session, the UDP, kawa-H1 and mux LIFECYCLE files) are now symbol citations; pinned code blocks keep their verified line ranges. - Comments only in lib/src (http.rs, https.rs, mux/mod.rs, mux/h2.rs, mux/stream.rs, udp.rs, udp/flow.rs, udp/manager.rs): section references into the rewritten lifetime_of_a_session.md (the close path is now its section 11), the retired UDP SelectBackend / BackendResolved round trip, and the frontend-connection scope of a shared H2 backend connection. doc/udp_simulation.md and doc/testing.md describe the ChangeBackendSet action that replaced BackendResolved in the UDP simulator. Documentation and comments only: every changed .rs line is a comment, no production code, test or dependency change. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 28, 2026
…h the request lifecycles Record the work merged from 2026-09-26 to 2026-09-28 that cut the system calls and heap allocations a worker pays per request, and bring the request lifecycle documentation back in line with the code. - doc/hot_path_zero_copy.md (new, linked from doc/README.md): goal and rules, the measurement method (intentrace, an LD_PRELOAD descriptor tracer and allocation counter, crate::test_allocations), one section per change with its before/after figures and pull requests, the correctness and safety fixes found along the way, the invariants and the tests that hold them, and the list of pull requests. - A closing measurement, taken on 2026-09-28 with release binaries at b5169d4 and c086b45 interleaved (crypto-ring, one worker, file:// access log, python backend, curl, N=20, intentrace), per request: H1 26.25-26.70 -> 18.45-18.85 system calls, 83.65-83.85 -> 39.95-40.35 heap operations; H1 keep-alive 14.75 -> 9.65 and 50.80 -> 7.80; H2 over TLS 61.25-61.60 -> 40.15-40.75 and 412.15-413.90 -> 240.60-241.75; H2 multiplexed 25.05 -> 13.55; TCP relay 39.00-39.10 -> 36.05-36.15. - doc/lifetime_of_a_session.md, rewritten: event loop, accept, TLS, PROXY pre-flight, the H1, H2, TCP and UDP lifecycles, close, soft stop and GOAWAY, with the system calls and allocations each step still pays. It corrects three statements the code contradicted: a reused keep-alive backend gets no liveness probe, a TCP session is closed on the first soft-stop pass, and a UDP listener is drained by UdpProxy::notify's SoftStop arm rather than by shutting_down. - The H2 soft stop follows #1654 (#1647): a draining session waits for a header block still arriving or a request awaiting its backend link, and a forced close is preceded by a final GOAWAY. The TCP soft stop is described as it has behaved since be5dd44 (2020-01-10). - The H1 smuggling fixes (#1651, #1653) are described as shipped: kawa 0.7.2 (#1655) fixes both upstream, the guards stay as defense in depth, and their content_length_invalid counters stay at zero unless kawa regresses. - lib/src/protocol/udp/LIFECYCLE.md: drop the SelectBackend / BackendResolved round trip that no longer exists (selection moved into the core), and add a per-datagram cost table. - lib/src/protocol/mux/LIFECYCLE.md: a section on what a request costs on the nominal path; a stale Router::connect reference is now Router::plan_connect. - CHANGELOG, mux LIFECYCLE, h2_mux_internals: an H2 backend connection belongs to one Mux session and carries the streams of one frontend connection only; the #1627, #1631 and #1632 entries no longer call it shared by several clients. A Documentation entry is added. - Line citations in the touched documents (lifetime_of_a_session, the UDP, kawa-H1 and mux LIFECYCLE files) are now symbol citations; pinned code blocks keep their verified line ranges. - Comments only in lib/src (http.rs, https.rs, mux/mod.rs, mux/h2.rs, mux/stream.rs, udp.rs, udp/flow.rs, udp/manager.rs): section references into the rewritten lifetime_of_a_session.md (the close path is now its section 11), the retired UDP SelectBackend / BackendResolved round trip, and the frontend-connection scope of a shared H2 backend connection. doc/udp_simulation.md and doc/testing.md describe the ChangeBackendSet action that replaced BackendResolved in the UDP simulator. Documentation and comments only: every changed .rs line is a comment, no production code, test or dependency change. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 28, 2026
…h the request lifecycles (#1656) ## Summary Writes up the hot-path zero-copy and system-call work merged between 2026-09-26 and 2026-09-28, and rewrites the request lifecycle documentation so it describes the code as it now stands. The work covers the access logs, the request id, `TCP_INFO`, `ClusterId`, the H1 header editor, the H2 output queue and HPACK codec, the read and write paths, accept and close, session setup, and the drain loop. The new document says what changed, how it works, why it was done, and what was measured before and after each change. The lifecycle documents now say, for UDP, TCP, H1, H2 and the mux, which system calls and allocations each step still pays on the nominal path. Documentation and comments only: every changed `.rs` line is a comment (`git diff origin/main -- '*.rs' | grep '^[-+]' | grep -vE '^[-+]\s*(//|\*|$)|^(\+\+\+|---)'` prints nothing), and no production code, test or dependency changes. ## Files | File | Why | |---|---| | `doc/hot_path_zero_copy.md` (new) | Campaign document. §1 goal and rules; §2 method (fixed scenario, instruments) and the closing measurement; §3 one section per theme, each with its mechanism, rationale, before/after figures and PRs; §4 correctness and safety fixes found along the way; §5 invariants and the tests that hold them; §6 the 66 PRs merged in the window. | | `doc/lifetime_of_a_session.md` | Rewritten: event loop, accept, TLS, PROXY pre-flight, the H1, H2, TCP and UDP lifecycles, the mux session, close, soft stop and GOAWAY. Each protocol has a table of the system calls and allocations still paid on the nominal path. | | `lib/src/protocol/udp/LIFECYCLE.md` | Removes the `SelectBackend` / `BackendResolved` round trip, which no longer exists, and adds a §13 per-datagram cost table. Citations converted to symbols. | | `lib/src/protocol/mux/LIFECYCLE.md` | Adds §12, what a request costs on the nominal path. Converts the last five line citations outside pinned blocks, corrects the "cross-client" wording, and replaces `Router::connect` with `Router::plan_connect`. | | `lib/src/protocol/kawa_h1/LIFECYCLE.md` | 23 line citations converted to symbols. The §2.1/§2.2 wording from #1655 is kept. | | `doc/h2_mux_internals.md` | Corrects the "cross-client" wording in three places. The pinned blocks are unchanged. | | `CHANGELOG.md` | Corrects the "cross-client" wording in the #1627, #1631 and #1632 entries, and adds a `docs` entry. | | `doc/README.md` | Links the new document. | | `doc/architecture.md`, `CLAUDE.md` | Both still described `file.rs:LINE` citations, and `CLAUDE.md` still pointed at the stale `lifetime_of_a_session.md`. | | `doc/udp_simulation.md`, `doc/testing.md` | Describe the `ChangeBackendSet` action that replaced `BackendResolved` in the UDP simulator. | | comments in `lib/src/{http,https}.rs`, `lib/src/protocol/mux/{mod,h2,stream}.rs`, `lib/src/udp.rs`, `lib/src/protocol/udp/{flow,manager}.rs` | Section references into the rewritten `lifetime_of_a_session.md` (the close path is now §11), the retired UDP `SelectBackend` / `BackendResolved` round trip, and the frontend-connection scope of a shared H2 backend connection. Line counts unchanged, so no pinned block moves. | ## Closing measurement Measured on 2026-09-28. Two release binaries (`--no-default-features --features crypto-ring,opentelemetry,splice,simd`, glibc malloc), one built at `b5169d44` and one at `c086b456`, run interleaved pass by pass with two repetitions each. During the intentrace passes the one-minute load average was 10.7–24.9 in the first repetition and 2.7–8.5 in the second for the scenarios without keep-alive, and 1.5–2.9 for the keep-alive ones. Setup: one worker, a `file://` access log, a `python3 -m http.server` backend on loopback (an HTTP/1.1 variant for the keep-alive rows), `curl`, N = 20. Instruments: system calls with `intentrace -p <worker>`, ANSI codes stripped and counted on the system-call name field, cross-checked by an `LD_PRELOAD` descriptor tracer; allocations with an `LD_PRELOAD` malloc counter. Figures are per request; ranges are the two repetitions. | Scenario | System calls (intentrace) | Heap operations | Bytes requested | |---|---|---|---| | H1, one request per connection | 26.25–26.70 → **18.45–18.85** | 83.65–83.85 → **39.95–40.35** | 84 327–84 445 → **15 793–16 069** | | H1 keep-alive, 20 requests | 14.75 → **9.65** | 50.80 → **7.80** | 8 362 → **1 322** | | H1 keep-alive over TLS | 15.75 → **10.70** | 63.30 → **20.25–20.30** | 10 644–10 680 → **3 638–3 640** | | H2 over TLS, one request per connection | 61.25–61.60 → **40.15–40.75** | 412.15–413.90 → **240.60–241.75** | 137 094–137 857 → **47 559–47 963** | | H2 over TLS, 20 streams on one connection | 25.05 → **13.55** | 83.40–83.90 → **41.15–42.00** | 11 021–11 029 → **4 792–4 825** | | TCP relay (splice) | 39.00–39.10 → **36.05–36.15** | 31.45 → **14.45** | 4 068 → **3 778** | **Baseline limit.** `b5169d44` was the first release-build baseline. It already included #1552, #1553, #1557, #1558, #1561, #1565, #1568, #1578 and #1581, so their gains are not in this table; each is given, with its own figures, in its section of the document. All other per-PR figures come from the PR descriptions. UDP was not traced: its costs are read from the code and labelled as such. The TLS rows include 15 `getrandom(2)` per handshake, which comes from `crypto-ring`. That is the default provider (`bin/Cargo.toml`, `lib/Cargo.toml`, the Dockerfile, the RPM and Arch packages), so default builds pay it; a `crypto-aws-lc-rs` build issues none on this path (§3.13). Earlier reference points: the campaign's first map (2026-09-26, `LD_PRELOAD` interposer on a debug build, `stdout` access log) counted about 25.1 system calls per H1 request and 34.8 per H2 request, and undercounted because it did not interpose `fcntl` or `recv`. The 106.25 → 25.35 figure is the `tcp://` access-log pass of #1552, measured on its base `ca058989`. ## Doc/code contradictions corrected - Reusing a keep-alive backend involves no liveness probe. What exists is a replay on a fresh connection (`ReplayOnFreshBackend`). - `TcpSession::shutting_down` answers `true`: a TCP session is closed on the first soft-stop pass. It has done so since `be5dd44b` (2020-01-10). - The UDP soft stop is `UdpProxy::notify`'s `SoftStop` arm, not `shutting_down`, and it is active: `Drain`, then `close_all_flows` on every listener session, then the listener sockets are deregistered. - An H1 backend EOF is read by a later `readable` since #1606, not together with the last bytes. - `backend.pool.size` is incremented in `Mux::dial_backend`. - A new UDP flow also costs three `fcntl`, a `getsockname` and a `getpeername` in `udp_connect`, even in release builds. - The UDP simulator's `BackendResolved` action is now `ChangeBackendSet`. - The UDP LIFECYCLE described a `SelectBackend` / `BackendResolved` round trip that no longer exists; selection is done in the core. - `Router::connect` (removed) was cited instead of `Router::plan_connect`. Two code comments in `lib/src/protocol/mux/h2.rs` still name it; they are left for a later change. - An H2 backend connection belongs to one `Mux` session and carries only the streams of one frontend connection. The #1627, #1631 and #1632 entries called it shared by several clients. Another user is reachable only behind an intermediary that multiplexes users on one frontend connection. - Drifted citations: `h2.rs:1439` now pointed at an empty `///` line, and `https.rs:1065` no longer pointed at the shutdown write-up. ## Open question **TCP soft stop.** On soft stop, a TCP relay session is closed on the first pass, with whatever bytes it still has in flight and no drain of its own. The documentation states this without calling it a bug; whether it is the intended behaviour is for the maintainers to decide. ## Also reflected - #1654 (#1647): a draining H2 session waits for a header block still arriving or for a request awaiting its backend link, and a forced close is preceded by a final `GOAWAY(NO_ERROR)`. - #1655 (kawa 0.7.2): the #1651/#1653 guards are described as shipped and now defense in depth. Their `content_length_invalid` counters stay at zero unless kawa regresses. ## Validation - `python3 .github/scripts/check_doc_citations.py --self-test` → exit 0 - `python3 .github/scripts/check_doc_citations.py --root .` → exit 0 (54 line citations, 794 test names, 15 pinned blocks) - `python3 .github/scripts/check_doc_citations.py --root . --base origin/main` → exit 0 ("none of the 87 cited lines compared against f5136d6 changed their text") - `python3 .github/scripts/check_doc_citations.py --audit --root .` → exit 0. It reports 3 advisory findings, all in files this PR does not touch (`doc/configure_admin_ops.md`, `lib/src/protocol/proxy_protocol/LIFECYCLE.md`). - `cargo +nightly fmt --all -- --check` → exit 0 - `cargo build --locked` → exit 0 - `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked` → exit 0 - Relative markdown links in the touched files were checked with a script: 0 broken. CI has no markdown link checker. Signed-off-by: Florentin Dubois <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An HTTP/1.1 request with neither
Content-LengthnorTransfer-Encodingnow ends after its headers, for every method and version (RFC 9112 §6.3 rule 7). Before, kawa 0.7.1 parsed it as close-delimited, and a request pipelined behind it in the same segment was forwarded raw to the first request's backend as its "body": not routed, not Basic-auth checked, withoutSozu-IdorX-Forwarded-*(CWE-444). Details in #1650; the parser-level defect is CleverCloud/kawa#23.Protocol / security impact
HttpContext::on_request_headers(lib/src/protocol/kawa_h1/editor.rs) setsParsingPhase::Terminatedwhen it findsparsing_phase == ParsingPhase::Body && body_size == BodySize::Empty, replacing the commented-out GET-only guard. kawa pushes the end-of-headersFlagsright after the callback withend_stream: kawa.is_terminated(), so the request is forwarded complete;ConnectionH1::readablestops reading the frontend, and the keep-alive branch ofConnectionH1::writableparses, routes and edits the pipelined request on its own.ParsingPhase::Bodyconjunct:pkawa::handle_headercalls the same callback for an H2 request whilebody_sizeis stillEmpty, then frames a request whose DATA follows as chunked unless the callback terminated it. Keying onEmptyalone would drop H2 request bodies withoutcontent-length;an_h2_request_is_left_for_pkawa_to_framepins it (seen red with the conjunct removed).on_response_headers,ConnectionH1::terminate_close_delimited), requests withContent-Lengthor chunked framing, the CL.TE guard (it runs first and returns on rejection).Expect: 100-continuewithout length (no body to wait for),GET+Upgrade: websocket(no body; the 101 still switches to the pipe — existing WebSocket e2e tests pass), HTTP/1.0 (same rule).CONNECTis not tunnelled by Sōzu; it used to stream client bytes to the backend as a close-delimited request body and no longer does. Bytes a client sends behind an upgrade request before the 101 (forbidden by RFC 6455 §4.1) are now held and reach the backend after the 101 through the pipe, in the same segment as the request or a later one; before the fix they reached the backend before the 101 as the request's body (measured with a temporary e2e probe, not committed).a_bare_request_costs_one_scratch_and_one_copy_per_forwarding_headerstill counts 7.Tests
test_h1_unframed_request_then_{same_cluster,other_cluster,auth_gated_cluster}{,_tls}(e2e/src/tests/h1_security_tests.rs): one write carries<METHOD> /a/firstwithout length plusGET /{a,b,c}/second, forGET,HEAD,DELETE,POST, over a clear and a TLS listener with three path-routed clusters (/crequires Basic auth). The first backend must receive exactly one request line, the second request must reach its own cluster as a distinct edited request with its ownSozu-IdandX-Forwarded-For(or be answered 401 by Sōzu for/c, with its backend never contacted), and the client must read two responses. Red on 96b4bca in all 24 cases, e.g.request lines ["GET /a/first HTTP/1.1", "GET /b/second HTTP/1.1"], Sozu-Id ["01M3KAX0331KN97P81H6552FY8"]; green with the fix.editor.rs):a_request_without_length_ends_after_its_headers(GET, HEAD, DELETE, POST, HTTP/1.0 POST,Expect: 100-continue,Upgrade: websocket; red without the fix:GET / HTTP/1.1: must end after its headers, got Body),a_framed_request_and_an_unframed_response_keep_their_bodies,an_h2_request_is_left_for_pkawa_to_frame.Commands run
On the pre-rebase parent 96b4bca (full set), then after rebasing on 3ee0b6d: fmt, both clippy runs, all-features build, doc,
cargo test -p sozu-lib --lib, the e2e subseth1_security_tests tls_tests websocket 100_continue pipelining, and the citation checker. The full workspace suite ran on 96b4bca only.cargo build --locked,cargo build --all-features --lockedcargo clippy --workspace --all-targets --locked -- -D warningscargo clippy --workspace --all-targets --no-default-features --features crypto-ring,opentelemetry,splice,simd --locked -- -D warningscargo +nightly fmt --all --checkcargo test --workspace --locked -- --skip tests::fuzz_tests:: --test-threads=8RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked.github/scripts/check_doc_citations.py:--self-test,--root .github/scripts/testdata/citations(exit 1 as expected),--base origin/main, plainDocs
lib/src/protocol/kawa_h1/LIFECYCLE.md(§2 bullet, new §2.2),CHANGELOG.md(Security),CLAUDE.mdSecurity-sensitive areas (one sentence).Conflicts only with #1648 on
CHANGELOG.md(both insert at the top of Security); clean againstorigin/main(git merge-tree --write-tree).Closes #1650
Signed-off-by: Florentin Dubois [email protected]