You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
router: an exact-hostname rule added after a matching regex segment attaches to the regex leaf and leaks to every host it matches #1351
Adding an exact-hostname frontend after a regex hostname segment that matches it does not create
an exact-host rule. add_tree_rule's lookup resolves through the regex segment, so the rule lands
on the regex segment's leaf — and is then served for every host that regex matches.
A rule an operator wrote for one host silently applies to a family of hosts.
Measured
Regex segment /test[0-9]/.example.com added first, then an exact frontend for test4.example.com with path /only-for-test4:
Declaration order decides whether this happens at all:
exact test4 vs regex segment, regex declared FIRST -> adds=[true,false], lookup -> REGEX-SEG
exact test4 vs regex segment, exact declared FIRST -> adds=[true,true], lookup -> EXACT
Mechanism
TrieNode::lookup_with_path (lib/src/router/pattern_trie.rs:557-580) tries, in fixed order: children.get(suffix), then the wildcard once the prefix is exhausted, then the regexps list. The
exact-child arm has no fallback — if that subtree yields nothing, the regex segments are never
consulted.
add_tree_rule uses domain_lookup_mut, which walks the same structure, so when no exact child
exists the walk resolves through the matching regex segment and the new rule is attached to that
leaf.
Related observation
When the first-declared segment claims a host but its only rule mismatches on method, the request
404s rather than falling through to a second segment that would have matched:
segment A (method POST) declared first, segment B (method GET) second, GET request -> None
Same root cause: segment selection is method-blind and has no fallback.
Why it matters
The two shapes have different severities and both are silent:
A rule scoped to one host serving a whole regex family is a routing leak — the operator's
intent was narrower than the effect, and sozu query frontends shows exactly what they typed.
The 404 case is availability, not exposure, but equally invisible from configuration.
Not proposing a fix
The obvious change — make the exact-child arm fall back to the regex segments on a miss — alters
hostname resolution for everyone and could change routing for existing configurations, so it needs a
maintainer decision rather than a patch. Documenting the current behaviour is also unattractive: it
would bless a precedence order that looks more like an artefact of the trie walk than a design.
Provenance
Found while verifying documentation of router precedence for an unrelated trie fix
(the documentation was being corrected because it claimed hostname overlap is resolved by
declaration order; it is not). Exercised through the public Router surface; not reproduced against a
live proxy.
Activity
fix(router): give an exact hostname its own node, and state the prece…
test(router): quickcheck property harness for hostname resolution
test(router): quickcheck property harness for hostname resolution (#1407