Skip to content

Escape char not handled for patterns categorised as exact match #69851

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

Open
ywangd opened this issue Mar 3, 2021 · 1 comment
Open

Escape char not handled for patterns categorised as exact match #69851

ywangd opened this issue Mar 3, 2021 · 1 comment
Labels
>bug :Security/Security Security issues without another label Team:Security Meta label for security team

Comments

@ywangd
Copy link
Member

ywangd commented Mar 3, 2021

In #36017, we opitmised index matching performance by splitting the patterns into two categories: exact match and non-exact (wildcard) match. Set.contains was used for exact matches and Automaton is used for non-exact matches. The issue occurs when a pattern contains the escape char (/), which is handled specially (basically gets dropped) when building the automaton, but passed through unchanged when building the exact match Set.

For example:

  • The pattern ab\c and ab\c* do not both match ab\c. In fact, only the former exact match pattern ab\c does. The pattern ab\c* result in an automaton that matches abc*.
  • Similarly, the pattern abc\ matches exactly abc\ while abc\* matches exactly abc*.
  • Also, between patterns abc\ and a*c\, only the former matches abc\ while the later cannot match any string that ends with a \.

In addition to the above bug, there is also a tiny missed opportunity for optimisation:

if (pattern.startsWith("/") || pattern.contains("*") || pattern.contains("?")) {
nonExactMatch.add(pattern);
} else {
exactMatch.add(pattern);
}

If the chars * or ? is immediately after an escape char (which itself is not immediately after an escape), the pattern is in fact an exact instead of a non-exact match.

@ywangd ywangd added >bug :Security/Security Security issues without another label labels Mar 3, 2021
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Mar 3, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Security/Security Security issues without another label Team:Security Meta label for security team
Projects
None yet
Development

No branches or pull requests

2 participants