Skip to content

Match a REGEX path rule against the path without its query #1909

Closed

Description

@Shine-neko

A REGEX path rule is matched against the request path together with its query string. A pattern written for the path can therefore consume the query, or be defeated by it:

  • /api/.+ matches /api/?x=1, although the path /api/ does not match it;
  • ^/api/v2$ does not match /api/v2?x=1, although its path does.

Matching the query through a path regex is useful in its own right, so this is not a bug report. But there is currently no way to match a regex against the path alone.

Use case

In Sōzune, Gateway API HTTPRoutes can declare a RegularExpression path match, which applies to the path only, as it does in Traefik's PathRegexp or Envoy's safe_regex. Mapping it onto a Sōzu REGEX rule requires rewriting the user's pattern so it can never reach the query (stripping ? from character classes, dropping its anchors, and so on), which is fragile and changes the meaning of some patterns. Checking the regex after routing instead loses the fall-through to the next frontend when it fails.

Proposal

A path rule kind, or an option on REGEX, that matches the regex against the path only, up to the first ?.

The open question is how rewrite_path should behave for such a rule: its $PATH[n] captures would no longer see the query, so the rewritten path would presumably need the original query appended to it.

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