Repository navigation
Description
Summary
doc/configure.md states that REGEX rules are anchored at both ends (\A...\z) since v2.0.0. That
is true for hostname regexes and false for path regexes, and the sentence sits in the
path / path_type section where an operator will read it as being about paths.
An operator who writes path_type = "REGEX", path = "/admin" gets a rule that also matches
/foo/admin/bar.
Evidence
PathRule::from_config (lib/src/router/mod.rs:1047):
Ok(PathRuleKind::Regex) => Regex::new(&rule.value).ok().map(PathRule::Regex)No anchoring is added, and regex::bytes::Regex::is_match is unanchored by construction.
Measured: a path regex bc matches request path /abcd; so does /ab.
The v2.0.0 anchoring work was hostname-only — CHANGELOG:927 covers pattern-trie segments and
CHANGELOG:1079-1082 covers convert_regex_domain_rule. Nothing in that work touched
PathRule::from_config.
Why it matters
Path rules select which cluster serves a request, and Route::Deny frontends use the same matching.
A regex the operator believes is exact is in fact a substring match, so:
- a rule intended for
/adminalso routes/public/admin-preview; - a
Denyintended for one path can block more than intended, or a narrowly-writtenDenycan be
sidestepped by a path the author assumed was excluded.
The documentation promising anchoring is what makes this dangerous: an operator has no reason to add
\A/\z by hand when the manual says it is already done.
Two ways to resolve, and it needs a maintainer decision
- Fix the documentation. Scope the anchoring sentence to hostname regexes and state plainly that
path regexes are unanchored, with a note to anchor by hand. Cheap, no behaviour change, but leaves
every existing unanchored path regex doing what it does today. - Anchor path regexes in
from_config. Makes the documented behaviour true, and is what most
operators appear to expect — but it is a behaviour change that would narrow existing rules and
could stop routing traffic that currently matches. That needs a release note and probably a
deprecation path.
I have not assumed which is wanted, so nothing is changed. Happy to prepare either.
Provenance
Pre-existing. Found while verifying an unrelated routing-precedence documentation fix: the sentence
was being carried forward into a rewritten section, which is how it came under scrutiny. Verified by
reading from_config and by exercising PathRule::Regex directly; not reproduced against a live
proxy.
Activity