Skip to content

docs/router: path REGEX rules are documented as anchored but are not #1350

Closed

Description

@FlorentinDUBOIS

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 /admin also routes /public/admin-preview;
  • a Deny intended for one path can block more than intended, or a narrowly-written Deny can 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

  1. 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.
  2. 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.

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