Skip to content

fix(router): send a single Host header to HTTP/1.1 backends - #1915

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
fix/rewrite-host-duplicate
Nov 3, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
fix/rewrite-host-duplicate

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1908.

Problem

apply_request_rewrites_and_headers (lib/src/protocol/mux/router.rs) rewrote the request authority for rewrite_host, then inserted a synthetic Host header block. The H1 converter (kawa::protocol::h1::converter) already writes Host: <authority> right after the request line, so an HTTP/1.1 backend got two Host headers. Go's net/http and other servers that refuse duplicates answered 400. The H2 converter filters every host block, so on H2 backends the block was dropped anyway.

The same root cause affected an operator request header named Host ([[…frontends.headers]] position = "request", key = "Host"). Without rewrite_host, the backend received the client's authority and the operator's value as two different Host lines:

GET / HTTP/1.1
Host: localhost
…
Host: override.local

That is the CWE-444-style primitive the code comment said the dedup prevented.

Change

  • The authority is now the only carrier of the backend Host. No Host header block is ever inserted.
  • A non-empty Host request header edit replaces the authority, and the last one wins. rewrite_host still takes precedence over it. An empty Host edit still drops header blocks only, and the authority always reaches the backend.
  • Behavior change on H2 backends: the operator Host edit is now sent as :authority. Before, the header was silently filtered there. H1 and H2 backends now see the same value.
  • The doc comment that claimed "the wire never carries two Host: headers" is fixed, and doc/configure.md documents the Host edit rule.

Tests (each seen red before the fix)

  • test_rewrite_host_h1_h1 now requires exactly one Host (backend.local). Before, it used contains, which passed with duplicates.
  • New test_request_header_host_h1_h1 checks that an operator Host edit gives a single Host: override.local.
  • New test_rewrite_host_h2_h1 checks that rewrite_host from an H2 (TLS) frontend to an H1 backend gives a single Host: backend.local.

Commands run

  • cargo +nightly fmt --all -- --check: exit 0
  • cargo clippy --all-targets --locked -- -D warnings: exit 0
  • cargo build --all-features --locked: exit 0
  • cargo test --workspace --locked -- --skip tests::fuzz_tests::: exit 0, 3416 passed, 0 failed (e2e: 670 passed)
  • redirect_rewrite_auth_tests + h2_security_header_injection: 47 passed

Docs

CHANGELOG Unreleased › Fixed; doc/configure.md (custom headers section).

Dependencies

#1919 (the lockfile fix for cargo audit) and #1914 are on main; main is merged into this branch, so CI runs on exactly the tree this PR lands. The later PRs are stacked on this one. Merge order: #1915 → #1918 → #1916 → #1917.

With `rewrite_host` on a frontend, `apply_request_rewrites_and_headers`
(`lib/src/protocol/mux/router.rs`) rewrote the request authority and then
added a synthetic `Host` header block. The HTTP/1.1 converter
(`kawa::protocol::h1::converter`) already writes `Host: <authority>` right
after the request line, so an HTTP/1.1 backend received two `Host`
headers, and servers that reject a duplicate (Go's `net/http`) answered
400. The HTTP/2 converter filters every `host` block, so the block was
useless there.

An operator request header named `Host` had the same root cause and
worse: the backend received the client's authority and the operator's
value as two different `Host` lines, the smuggling primitive the code
comment claimed to prevent.

The authority is now the only carrier of the backend `Host`: no `Host`
header block is ever inserted. A non-empty `Host` request header edit
replaces the authority (last one wins) unless `rewrite_host` is set,
which keeps precedence; an empty one still drops header blocks only.
An HTTP/2 backend therefore now receives that edit as `:authority`.

The H1→H1 rewrite test now requires exactly one `Host`; new e2e tests
cover the operator `Host` edit (H1→H1) and `rewrite_host` from an HTTP/2
frontend to an HTTP/1.1 backend.

Fixes #1908

Signed-off-by: Florentin Dubois <[email protected]>
`cargo audit --deny warnings` (CI "cargo audit") fails on main's
lockfile with two findings published after its last green run:

- RUSTSEC-2026-0433: pulldown-cmark 0.13.5, quadratic parsing of nested
  image wikilinks with ENABLE_WIKILINKS. Fixed in 0.13.6. A build
  dependency only, through prost-build.
- async-executor 1.14.0 is yanked. Moved to 1.14.1.

Lockfile-only: both are patch updates within the existing requirements.
Signed-off-by: Florentin Dubois <[email protected]>
Brings in #1919 (lockfile) and #1914 (command channel error) and keeps
both CHANGELOG slots, each followed by a blank line.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Nov 3, 2026
Stacks this branch on #1916, #1918 and #1915, up to date with main after
#1919 (lockfile) and #1914, so CI runs on the tree this PR lands. Keeps
every CHANGELOG slot, each followed by a blank line.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 026a1fb into main Nov 3, 2026
46 checks passed
FlorentinDUBOIS added a commit that referenced this pull request Nov 3, 2026
main now carries #1915 as a squash commit, whose CHANGELOG insertion
conflicts with the stacked original. Keeps every CHANGELOG slot; the
tree is unchanged.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/rewrite-host-duplicate branch November 4, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rewrite_host sends two Host headers to HTTP/1.1 backends

2 participants