Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i/p/patterns: disallow /./ and /../ in path patterns #14774

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Nov 27, 2024

  1. i/p/patterns: disallow /./ and /../ in path patterns

    Since patterns like /foo/./bar don't match paths paths like /foo/bar,
    throw an error if the client tries to reply or create a rule with such a
    construction clearly in the pattern. That is, if the pattern contains
    `/./` or `/../`, or if it ends with `/.` or `/..`.
    
    Notably, we do this on the raw pattern string, similarly to how we
    validate that the pattern begins with a `/`: we don't consider whether
    all alts in a leading group happen to start with `/`, we simply throw an
    error if the first character is not `/`.
    
    In this case, we take a more lenient (but similarly lazy) approach: if
    there's a literal `/./` or `/../`, or trailing `/.` or `/..`, then an
    error is thrown. As long as there's something interrupting the `/` or
    end of the pattern string (e.g. a group), we consider that fine. For
    example, we allow `/foo/.{,bar}` even though technically this renders to
    the variants `/foo/.` and `/foo/.bar`, where the former is undesirable.
    
    We may reconsider this in the future, but checking whether any rendered
    variant contains `/./` or `/../` in general requires fully rendering
    each variant and checking each one, which we do not do at parse time,
    and one nearly always has at least one pattern which is capable of
    matching something valid (an exception being the pattern `/foo/.{,}`,
    for example). But the user must fairly deliberately shoot themself in
    the foot to end up in that situation.
    
    Again, the worst case if a pattern which is "bad" in this way gets past
    validation is that we end up with a path pattern which is incapable of
    matching any paths. This is undesirable, but not problematic.
    
    Signed-off-by: Oliver Calder <[email protected]>
    olivercalder committed Nov 27, 2024
    Configuration menu
    Copy the full SHA
    279b5f4 View commit details
    Browse the repository at this point in the history

Commits on Nov 28, 2024

  1. Configuration menu
    Copy the full SHA
    18556dc View commit details
    Browse the repository at this point in the history