Repository navigation
fix(http): resolve access-log tags through the router, not a hostname map - #1386
Merged
Merged
Conversation
`AddCertificate.certificate.names` is a free `Vec<String>` that `CertificateResolver::add_certificate` inserted into the SNI `TrieNode<Fingerprint>` verbatim. That trie is the same `lib/src/router/pattern_trie.rs` the HTTP router uses, where a dot-separated label wrapped in `/.../` is compiled as a REGEX segment, so a certificate declared for `/te.*/.example.com` was served for `test.example.com` and for `tenant.example.com` alike -- one certificate bound to an open-ended class of SNI values, with an inventory that shows a SAN-shaped string. The validation that existed could not catch it: it dry-runs every name into a scratch trie and asks only whether the name INSERTS, which a regex segment does. The check has to be on the name's bytes. `add_certificate` now also refuses a name containing `/`, in the SAME pre-mutation block as the `MAX_HOSTNAME_LENGTH` bound, returning `CertificateResolverError::InvalidName`; nothing is half-registered. A `/` cannot occur in a DNS name, so no legitimate SAN is lost, and an ordinary `*.example.com` wildcard is not a regex segment and still loads. This is the rule `config::validate_sni_pattern` already applies to every path into the TCP SNI route table; the certificate trie was the one SNI table left open. Removal is unaffected: `remove_certificate` re-inserts the names a certificate already carries and never re-validates them, so a certificate an earlier build accepted stays removable. `doc/configure.md` states the rule under "Hostname case" and `CHANGELOG.md` tells an operator how to find an affected configuration -- the bundled CLI never sets the `names` override, so only a control plane that fills it, or a saved state replaying one, can be affected. Reported in #1378. Signed-off-by: Florentin Dubois <[email protected]>
`add_tree_rule`, `remove_tree_rule` and `has_hostname` ran the WHOLE configured hostname through `idna::domain_to_ascii`, regex segments included. That function ASCII-lowercases, and lowercasing an uppercase regex escape inverts the character class it names: measured, `"/\D+/.example.com"` normalised to `"/\d+/.example.com"` and `"/[^\D]/.example.com"` to `"/[^\d]/.example.com"`. `\D` is "not a digit" and `\d` is "a digit", so the installed rule matched the exact COMPLEMENT of what the operator wrote while `sozu query frontends` still echoed the original spelling. Measured on the tree as it stood, the frontend `/\D+/.rx.example.com` served `777.rx.example.com` and did not serve `abc.rx.example.com`. `\W`/`\w` and `\S`/`\s` invert the same way. Pre and Post never carried it: `convert_regex_domain_rule` copies a segment's source verbatim and `DomainRule::from_str` takes its case insensitivity from the `RegexBuilder` instead. `tree_hostname_to_ascii` normalises the literal labels only and copies a `/`-delimited segment byte for byte -- the split `convert_regex_domain_rule` already makes and the one `pattern_trie.rs`'s `insert_recursive` addresses a `regexps` entry by. Per-label and whole-domain IDNA agree on a label (measured: `"MUNCHEN"` with an umlaut maps to `"xn--mnchen-3ya"` either way), so a genuine unicode label in a hostname that also carries a regex segment is still punycoded. A hostname with no `/` at all, and one whose `/` does not parse as that grammar (`abc/[0-9]+/.example.com`, `example.com/`), both keep the historical whole-string call byte for byte. Leaving the source unfolded moves the case fold onto the compile, and that half is load-bearing: an uppercase literal such as `/API[0-9]/` used to meet the ASCII-lowercased lookup key only because the source had been lowercased too. `pattern_trie`'s `compiled_segment` wraps `anchored_segment` and sets `case_insensitive(true)`, exactly as `DomainRule::from_str` does, so literals fold and `\d`/`\D`, `\w`/`\W` and `\s`/`\S` do not. `RegexBuilder` leaves `as_str()` as the pattern it was handed, so `anchored_segment` remains the single source of a `regexps` entry's identity, a stored segment stays removable, and `captures_len` -- and therefore every `$HOST[n]` rewrite index -- is unchanged. This changes existing rules. A trie-routed frontend spelling `\D`, `\W` or `\S` has been matching the complement of its source and now matches what it says; a rule tuned against the folded behaviour must be respelled with the lowercase escape it actually meant. `/API[0-9]/` keeps matching exactly the hosts it matched before. `doc/configure.md` and `CHANGELOG.md` carry the migration note in this changeset. Regression tests, each seen red on the unfixed tree: `a_tree_hostname_regex_escape_is_not_case_folded`, `every_inverting_uppercase_regex_escape_survives_a_tree_insert`, `a_unicode_label_is_punycoded_while_its_sibling_regex_segment_is_not`, and `compiled_segment_folds_case_without_respelling_its_identity`. Closes #1377 Signed-off-by: Florentin Dubois <[email protected]>
… map The per-frontend tag cache was written under the frontend RULE's hostname (`listener.set_tags(front.hostname, front.tags)` in `lib/src/https.rs` and its twin in `lib/src/http.rs`) and read back under the REQUEST's authority (`listener.get_tags(hostname)` in `lib/src/protocol/mux/stream.rs`). The store is a `BTreeMap<String, CachedTags>` and the read is `self.tags.get(key)`: exact key, no pattern resolution. For `*.example.com`, `/foo.*/.example.com` or any Pre/Post rule string, the key written can never be produced by the key read, so `get_tags` returned None and the configured tags were silently absent from every access-log line of that frontend. Three ways to miss from the one asymmetry: wildcard/regex, port (the read strips `:port`, the write does not) and case. Resolve L7 tags through the router instead of through a parallel exact map, the way `lib/src/tcp.rs` already builds `sni_tags_key` with the same function on both sides. The router knows which frontend rule matched and is the only correct owner of its tags; a request carries a concrete authority while tags are configured per rule, so no string key can be spelled the same on both sides. - `Router::add_http_front_with_hsts_origin` counts `tags` as a policy field, so a tagged frontend is stored as `Route::Frontend(Rc<Frontend>)` carrying `Rc<CachedTags>` rather than a tagless `Route::ClusterId`. Only a tagged frontend pays that shape. - `Router::route_from_request` stashes `RouteResult.tags` on `HttpContext.tags` before every early return, so a redirect, a 401 and a backend-connect failure log them too. The `..` that dropped the field is gone with it. - `Stream::generate_access_log` reads from there, keeping the authority lookup only as the fallback for a request that never reached routing at all. The WS/WSS post-upgrade pipe keeps its own `tags_key` string, which only the TCP SNI-preread path sets; on an HTTP/HTTPS listener it falls back to the listener address and carries no frontend tags on any frontend shape. That is a separate pre-existing miss, recorded in `doc/observability.md` rather than folded in here. `a_wildcard_frontends_tags_reach_the_access_log_of_a_concrete_authority` registers `*.example.com` with tags through `HttpProxy::add_http_frontend`, routes `foo.example.com` through `Router::route_from_request`, emits through `Stream::generate_access_log` and asserts on the rendered access-log line. Repairs the 24 `file.rs:NNN` doc citations this changeset moved. Inserting a field into `HttpContext` and an import above it shifts every line below them in `lib/src/protocol/kawa_h1/editor.rs`, which `kawa_h1/LIFECYCLE.md` cites 21 times; the `RouteResult` stash shifts `mux/router.rs` below it, and the `tags: None` test literal shifts `mux/answers.rs`. The CI resolver saw only the two that happened to land on a blank line (`doc/benchmark.md`, `doc/lifetime_of_a_session.md`) — it cannot see a citation that drifts onto a different non-blank line, which is what the other 22 did. Twenty-two are re-anchored on the symbol their sentence already names — the struct, field, method or test — with the file path and no line number, because a fresh number would rot at the next edit above it and the pull request that breaks it is never the one that contains it. Two stay ranges and are renumbered instead (`editor.rs:607-627`, `:628-631`): the prose there means the Transfer-Encoding fold and the rejection predicate specifically, not the function that holds them, which is the one case the convention keeps a range for. `doc/benchmark.md` also loses a bare call-site line that the two symbols around it already pin. Closes #1379 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 21, 2026 00:23
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.
Access-log tags were keyed by the frontend rule's hostname on the write side and read
back by the request's authority, against a
BTreeMap<String, CachedTags>with exact-keyget. So for every frontend whose hostname is not an exact literal — wildcard, regex,Pre/Post — the key written could never be produced by the key read, and the configured tags
were silently absent from every access-log line. Exact frontends were unaffected, which is
why it did not show up in ordinary testing.
Resolved through the router, not by making the two spellings agree. The router already
knows which frontend rule matched, and is the only owner that can be right when several
frontends share a hostname on different paths — something no hostname-derived key can
express.
router::Frontendhas carriedtagssince theRouteResultwork;route_from_requestwas destructuringRouteResultwith a trailing..that dropped it.A second half the issue did not mention, and without it the first is a no-op.
add_http_front_with_hsts_origin'shas_policypredicate did not counttags, so a taggedfrontend was stored as the legacy
Route::ClusterId— andRouteResult::forward()hardcodestags: None. Both halves are covered by the single regression test, verified independently:each mutation alone reddens it.
The test asserts on the rendered access-log line captured through
capture_test_logs,not on an intermediate field, so it stays valid whatever the resolution mechanism becomes.
The RED line is the bug verbatim — the request routed, the line was emitted, with
[]wherethe tags belong.
The authority lookup survives only as the fallback for a request that never reached routing
(malformed, unknown host, SNI/authority mismatch), where there is no matched frontend to ask.
Known gap left open deliberately: the WS/WSS post-upgrade pipe reads
Pipe::set_tags_key,which only the TCP SNI-preread path sets, so a WebSocket access line carries no frontend tags
on any frontend shape including exact ones. Different cause, different symptom; recorded in
doc/observability.mdand the CHANGELOG rather than silently folded in.Citation repair in the same changeset. This commit shifts
kawa_h1/editor.rsby +21 andmux/router.rsby +14, which moved 24file.rs:NNNcitations. TheDoc citationsguardflagged 2 — the only ones that landed on a blank line. The other 22 landed on non-blank code
and were invisible to it; they were found by resolving every citation with the checker's own
resolver and diffing the cited line's text against the merge base. 22 are now anchored on the
symbol their own prose already names; 2 stay ranges because the prose means a specific block
inside
on_request_headers, and both ends were verified to land on the right code. Twofurther citations that had not moved but were already off by one are corrected too.
BUILD=0 CLIPPY=0 TEST=0 FMT=0 CITATIONS=0—test result: ok. 916 passed; 0 failed.Stacked on #1385; review the top commit.
Closes #1379