Repository navigation
Description
Summary
An uppercase Host: header does not route to a frontend added with a lowercase hostname. Host is
case-insensitive per RFC 9110 §7.2 / §4.2.3, so this is a routing defect rather than a configuration
mistake.
The cause is asymmetric normalization: the add path lowercases, the lookup path does not.
Trace
Each link verified at source:
- Wire → authority. kawa's
parse_origin_form/parse_authority_form/parse_absolute_form
all produceStore::new_slice(buffer, ..)— a verbatim slice of wire bytes. The Host-header
fallback ismem::swap(&mut authority, &mut header.val).grep -rn lowercaseover the whole kawa
crate returns zero hits. - authority →
HttpContext.lib/src/protocol/kawa_h1/editor.rs:630—
self.authority = authority.data_opt(buf).and_then(|d| from_utf8(d).ok()).map(ToOwned::to_owned).
Verbatim. HttpContext→ listener. H1 atlib/src/protocol/kawa_h1/mod.rs:1551and mux/H2 at
lib/src/protocol/mux/router.rs:680both reachfrontend_from_request(host, uri, method)through
extract_route(). Verbatim.- listener → router.
lib/src/http.rs:824(and itshttps.rstwin):hostname_and_portstrips
only the port, andis_hostname_characceptsis_alphanum()in both the default and tolerant
variants, so uppercase parses through. Thenself.fronts.lookup(host, uri, method). Router::lookupcallsself.tree.lookup_with_path(hostname_b, ..)— a byte-exact trie walk,
no case folding.add_tree_rulelowercases viaidna::domain_to_ascii.
Measured
hostname_and_port("WWW.EXAMPLE.COM") -> host = "WWW.EXAMPLE.COM"
wire Host "WWW.EXAMPLE.COM:443" -> parsed -> lookup -> None
wire Host "www.example.com" -> parsed -> lookup -> Some("LOWER")
Declaring the frontend as WWW.EXAMPLE.COM does not help: idna::domain_to_ascii lowercases it on
the way in, so lookup("WWW.EXAMPLE.COM") still returns None. There is no configuration that makes
an uppercase Host route.
Impact
A client sending Host: WWW.EXAMPLE.COM — legal, and produced by some clients and test tooling —
gets a routing failure rather than the frontend the operator configured. It is not exploitable as far
as I can tell, but it is a correctness gap against the HTTP specification, and it is invisible from
configuration: sozu query frontends shows the frontend present and correct.
Suggested direction
Lowercase the authority on the lookup path so the two sides agree — most cheaply where the host is
already being extracted for routing, rather than in the parser, since the parsed value is also used
for logging and X-Forwarded-* where preserving the client's bytes may be wanted. Where exactly it
belongs is a maintainer call; the invariant to restore is that add and lookup normalize
identically.
Worth deciding at the same time whether SNI matching has the same asymmetry.
Provenance
Pre-existing; found while auditing the router's hostname handling for an unrelated trie fix. Traced
through source and exercised through hostname_and_port plus Router::lookup; not reproduced against
a live proxy over a real socket.
Activity
fix(router): match the Host header case-insensitively
fix(router): match the Host header case-insensitively
fix(router): match the Host header case-insensitively
fix(router): match the Host header case-insensitively