Repository navigation
fix(listener): resolve HSTS inheritance against each listener's own default - #1697
Merged
Merged
Conversation
…efault A policy-carrying frontend (tags, headers, redirect, rewrite, auth) with no hsts block of its own, added while its HTTPS listener had no HSTS default, was recorded as an explicit override (inherits_listener_hsts = false). A listener later added on the same address copied it without its own default, and a later listener HSTS patch did not reach it, contrary to the documented contract that every frontend without a per-frontend [hsts] block at add time inherits the listener default. add_https_frontend now records the frontend's own intent (no hsts declared) instead of whether a default existed, and Frontend::new no longer requires a resolved value, so Router::refresh_inheriting_hsts resolves it against each listener's default, both when HttpsProxy::add_listener copies a sibling's routes and on every later patch. Explicit per-frontend hsts, including enabled = false, is never overridden. Behaviour change on a single listener: such a frontend added before the listener had an HSTS default now receives the header once a patch enables it, as frontends without any policy already did. Closes #1691 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 29, 2026 17:55
FlorentinDUBOIS
deleted the
fix/hsts-inheritance-on-copied-frontends
branch
September 29, 2026 19:04
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 29, 2026
#1695) Closes #1689 ## Problem (reproduced) kawa's H1 parser pushes a chunked request's trailer fields after its last chunk with no callback, so `HttpContext::on_request_headers` never sees them. On `main` (`3ed6e8a6`) the new e2e test shows the backend receiving them verbatim: ``` TRAILER-SPOOF: backend received "POST /api HTTP/1.1\r\n...X-Forwarded-For: 127.0.0.1\r\n...\r\n\r\n5\r\nHello\r\n0\r\nX-Forwarded-For: 6.6.6.6\r\nForwarded: for=6.6.6.6\r\nX-Real-IP: 6.6.6.6\r\nX-Request-Id: 6.6.6.6\r\nX-Forwarded-Proto: 6.6.6.6\r\nX-Forwarded-Port: 6.6.6.6\r\nX-Forwarded-Host: 6.6.6.6\r\nGrpc-Status: 0\r\n\r\n" ``` A backend that merges trailers into its header view then sees a forged client address (RFC 9110 §6.5.1, CWE-348). ## Fix - `TRAILER_SPOOF_VECTOR_HEADERS` (`lib/src/protocol/kawa_h1/editor.rs`) is now the **single list** for both frontends: `x-real-ip`, `x-forwarded-for`, `forwarded`, `x-request-id`, `x-forwarded-proto`, `x-forwarded-port`, `x-forwarded-host`. `pkawa::handle_trailer` reads it instead of the inline seven-name `matches!` that #1685 (merged as `5471bfba`) added, so H1 and H2 cannot drift. H2 behaviour is unchanged. This branch is rebased on `origin/main` (`a6419607`), which includes #1685, #1696, #1697 and #1699. The `editor.rs` conflict with #1696 (both appended tests at the end of the test module) keeps both sets of tests, and the `pkawa.rs` comment keeps #1699's mode wording while naming the shared constant. The `pkawa.rs` conflict was resolved in favour of the shared constant, keeping #1685's `forwarded_headers`-mode wording in the doc comments, the test rationale and the `doc/configure.md` paragraph (which now also names the H1 path). - `elide_request_trailer_spoof_vectors` (same file) runs after both frontend `kawa::h1::parse` sites of `ConnectionH1`: `readable`, and the keep-alive branch of `writable` that parses a pipelined request. Each call site reads `kawa.blocks.len()` just before the parse and passes it as `first_new_block`. The walk goes back only over the blocks that parse appended (closing `Flags` + trailer fields), stopping at the `end_body` marker or at `first_new_block`. It elides matching names in any case with `Pair::elide`. - **Linear cost (review item):** a parse only appends blocks and `prepare` only drains from the front between parses, so every older field was already examined by the call after the parse that queued it. A client that trickles one trailer line per segment while the backend isn't writable costs one block per line, not an O(n²) re-walk. This holds when earlier trailer fields were already drained to the backend. - **Framing:** kawa's H1 and H2 converters skip elided pairs. The last chunk and the closing empty line are still written, so the framing stays valid even when every field is dropped. The e2e test asserts `...0\r\nGrpc-Status: 0\r\n\r\n` on the wire. - **Cost:** the function returns on the `kind` / `body_size == Chunked` / `parsing_phase ∈ {Trailers, Terminated}` checks before reading any block. Requests without trailers pay three field compares. - **Responses are not filtered.** A response trailer goes to the client, which does not take client attribution from it, so the spoofing risk this issue describes does not apply. - New counter `http.trailer.spoof_vector_elided` (one increment per elided H1 field), documented in `doc/configure.md`. - Docs: `doc/configure.md` (anti-spoof paragraph + metric row), `lib/src/protocol/kawa_h1/LIFECYCLE.md` §2.3, `CHANGELOG.md` (Unreleased / Security). ## Tests (red, then green) New tests: `a_chunked_request_trailer_section_loses_its_spoof_vector_fields`, `a_trailer_section_parsed_after_the_last_chunk_was_forwarded_is_filtered`, `a_trailer_section_split_across_reads_is_filtered_in_each_part`, `a_trailer_walk_stops_at_the_blocks_queued_before_the_parse`, `trailer_elision_leaves_headers_and_responses_alone` (editor unit tests). The e2e tests are `test_h1_trailer_spoof_headers_dropped`, `test_h1_trailer_spoof_headers_dropped_split` (trailers in a separate write), `test_h1_trailer_spoof_headers_dropped_split_inside_trailers` (`X-Forwarded-For` in one write, the rest in the next) and `test_h1_pipelined_trailer_spoof_headers_dropped`. `handle_trailer_drops_each_spoof_header_individually` now iterates the shared list. RED, e2e on unfixed code: ``` TRAILER-SPOOF: FAIL — a spoofed forwarding trailer reached the backend test tests::h1_security_tests::test_h1_trailer_spoof_headers_dropped ... FAILED TRAILER-SPOOF-SPLIT: FAIL — a spoofed forwarding trailer reached the backend test tests::h1_security_tests::test_h1_trailer_spoof_headers_dropped_split ... FAILED test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 504 filtered out ``` RED, unit tests: `elide_request_trailer_spoof_vectors` stubbed to `return 0`, and pkawa restored to its old four-name `matches!`: ``` test protocol::mux::pkawa::tests::handle_trailer_drops_each_spoof_header_individually ... FAILED test protocol::kawa_h1::editor::tests::a_trailer_section_parsed_after_the_last_chunk_was_forwarded_is_filtered ... FAILED test protocol::kawa_h1::editor::tests::a_chunked_request_trailer_section_loses_its_spoof_vector_fields ... FAILED test protocol::kawa_h1::editor::tests::trailer_elision_leaves_headers_and_responses_alone ... ok trailer with only x-forwarded-proto should leave no surviving block test result: FAILED. 1 passed; 3 failed; 0 ignored; 0 measured; 1348 filtered out ``` RED, pipelined path: only the keep-alive call site in `mux/h1.rs` disabled: ``` TRAILER-SPOOF-PIPELINED: FAIL — a spoofed forwarding trailer reached the backend test tests::h1_security_tests::test_h1_pipelined_trailer_spoof_headers_dropped ... FAILED ``` RED, review items after the rebase: Walk ignoring `first_new_block` (`range_mut(0..)`). The function's own post-condition `debug_assert!` ("only blocks appended by the last parse are elided") fires before the test's assertion: ``` test protocol::kawa_h1::editor::tests::a_trailer_section_split_across_reads_is_filtered_in_each_part ... ok test protocol::kawa_h1::editor::tests::a_trailer_walk_stops_at_the_blocks_queued_before_the_parse ... FAILED test result: FAILED. 1 passed; 1 failed ``` Elision disabled (`return 0`): ``` test protocol::kawa_h1::editor::tests::a_trailer_section_split_across_reads_is_filtered_in_each_part ... FAILED assertion `left == right` failed: the first trailer part is filtered on its own left: 0 right: 1 TRAILER-SPOOF-SPLIT-INSIDE: FAIL — a spoofed forwarding trailer reached the backend test tests::h1_security_tests::test_h1_trailer_spoof_headers_dropped_split_inside_trailers ... FAILED ``` GREEN: ``` test protocol::mux::pkawa::tests::handle_trailer_drops_each_spoof_header_individually ... ok test protocol::kawa_h1::editor::tests::a_chunked_request_trailer_section_loses_its_spoof_vector_fields ... ok test protocol::kawa_h1::editor::tests::a_trailer_section_parsed_after_the_last_chunk_was_forwarded_is_filtered ... ok test protocol::kawa_h1::editor::tests::trailer_elision_leaves_headers_and_responses_alone ... ok test tests::h1_security_tests::test_h1_trailer_spoof_headers_dropped ... ok test tests::h1_security_tests::test_h1_trailer_spoof_headers_dropped_split ... ok test tests::h1_security_tests::test_h1_trailer_spoof_headers_dropped_split_inside_trailers ... ok test protocol::kawa_h1::editor::tests::a_trailer_section_split_across_reads_is_filtered_in_each_part ... ok test protocol::kawa_h1::editor::tests::a_trailer_walk_stops_at_the_blocks_queued_before_the_parse ... ok test tests::h1_security_tests::test_h1_pipelined_trailer_spoof_headers_dropped ... ok ``` ## Validation (each by its own exit code) - `cargo build --all-features`: 0 - `cargo clippy --all-features --all-targets -- -D warnings`: 0 - `cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings` (MSRV): 0 - `cargo +nightly fmt --all -- --check`: 0 - `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked`: 0 - `cargo test -p sozu-lib`: 0 (1381 passed) - `cargo test -p sozu`: 0 - `cargo test -p sozu-command-lib`: 0 - `cargo test -p sozu-e2e -- trailer h1_security mux_tests forward connection`: 0 (104 passed) - `check_doc_citations.py` `--self-test` / `--root .` / `--base origin/main` / `--audit --root .`: all 0 (the audit's three advisory findings are in files this PR does not touch) ## Residual risks - The advisory `Trailer:` request header still lists the dropped names. It is informational only, and this PR leaves it as sent. - An H2-frontend request forwarded to an H1 backend goes through `pkawa::handle_trailer`, not this walk. It uses the same list. - The bounded walk assumes kawa 0.7.2's invariants: parsing only appends blocks, and draining happens only from the front between parses. A debug post-condition guards this. 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
A policy-carrying HTTPS frontend (tags, headers, redirect, rewrite, auth) with no
hstsblock of its own, added while its listener had no HSTS default, was stored withinherits_listener_hsts = false. Two consequences:HttpsProxy::add_listener) copied the frontend but never applied its own HSTS default to it.sozu listener https update --hsts-*on the frontend's own listener did not reach it either.Both contradict the documented contract (
doc/configure.md, HSTS hot-reconfig): a frontend with no per-frontend[hsts]block at add time inherits the listener default.Fix
HttpsProxy::add_https_frontend(lib/src/https.rs) now records the frontend's own intent. If the frontend declared nohsts, the origin isHstsOrigin::InheritedFromListenerDefault, andfront.hststakes the listener default, which may beNone. It no longer checks whether a default existed.Frontend::new(lib/src/router/mod.rs) drops the&& hsts.is_some()condition, soinherits_listener_hstsreflects only that intent.Router::refresh_inheriting_hstsis unchanged. It already runs on the copy inadd_listenerand on every listener HSTS patch, and it now reaches these frontends too.No new allocation, and nothing changes on the request path. The only extra work is the refresh walk, which now also rebuilds these frontends during a listener patch or a listener add.
Behaviour change on a single listener
This affects a policy-carrying frontend with no
hstsof its own, added before the listener had an HSTS default. When a patch later enables the default, that frontend now gets the header. Before, it did not; frontends without any policy already did, through route promotion. Two cases are unchanged:hsts(includingenabled = false).Tests (
lib/src/https.rs,listener_sibling_tests)a_copied_frontend_without_hsts_inherits_the_new_listener_default: two HTTPS listeners on one address (the second oninterface = "lo"). A tagged frontend withouthstsis added while the first listener has no default, then the second listener is added withmax-age=100. Each listener must serve its own default, including after a separate patch to each listener.a_frontend_with_explicit_hsts_is_never_overridden_by_a_listener_default: guard. A frontend with explicithstskeeps it on both listeners, at copy time and after patches. It is green both before and after the fix.a_listener_hsts_patch_refreshes_every_frontend_without_its_own_hsts: a single listener, starting with no default and with a default. A patch that enables HSTS reaches the tagged frontend, and a patch that disables it removes the header.RED on
origin/main(d9ce2a0) with the tests only:GREEN with the fix:
Validation (each by its own exit code, all 0)
cargo build --all-featurescargo clippy --all-features --all-targets -- -D warningscargo +nightly fmt --all -- --checkRUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --lockedcargo test -p sozu-lib: 1371 passedcargo test -p sozu: 242 passedcargo test -p sozu-command-lib: 210 passedcargo test -p sozu-e2e -- <group>:hsts7,https6,tls_tests9,listener27, all passedcheck_doc_citations.pyin all four modes:--self-test,--root .,--base origin/main,--audit --root .Docs
doc/configure.md, HSTS hot-reconfig: defines an inheriting frontend and describes how a listener added on a shared address resolves inheritance.CHANGELOG.md, Unreleased / Fixed.doc/configure_admin_ops.md: one line citation renumbered (doc/configure.md:1266becomes:1268), because the docs insertion moved that line.Not addressed (pre-existing, follow-ups)
HttpsProxy::update_listenerfinds the listener to patch by address alone (.find(...)). With several listeners on one address (on different interfaces), anUpdateHttpsListenerConfigreaches only one of them, whichever theHashMaporder yields first. The new tests callHttpsListener::update_configon each listener directly.Closes #1691