Skip to content

router: an uppercase Host header does not match a lowercase frontend (add lowercases, lookup does not) #1349

Closed

Description

@FlorentinDUBOIS

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:

  1. Wire → authority. kawa's parse_origin_form / parse_authority_form / parse_absolute_form
    all produce Store::new_slice(buffer, ..) — a verbatim slice of wire bytes. The Host-header
    fallback is mem::swap(&mut authority, &mut header.val). grep -rn lowercase over the whole kawa
    crate returns zero hits.
  2. 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.
  3. HttpContext → listener. H1 at lib/src/protocol/kawa_h1/mod.rs:1551 and mux/H2 at
    lib/src/protocol/mux/router.rs:680 both reach frontend_from_request(host, uri, method) through
    extract_route(). Verbatim.
  4. listener → router. lib/src/http.rs:824 (and its https.rs twin): hostname_and_port strips
    only the port, and is_hostname_char accepts is_alphanum() in both the default and tolerant
    variants, so uppercase parses through. Then self.fronts.lookup(host, uri, method).
  5. Router::lookup calls self.tree.lookup_with_path(hostname_b, ..) — a byte-exact trie walk,
    no case folding.
  6. add_tree_rule lowercases via idna::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

  1. added 4 commits that reference this issue on Sep 20, 2026
    6c869da
    d9c2860
    d835ea3
    704b60d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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