Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possessive quantifiers to the regex to prevent catastrophic backtracking.
- Loading branch information
Add possessive quantifiers to the regex to prevent catastrophic backtracking.
05f3a28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josh-gaby may I ask how this
+
quantifiers help to prevent the issue or why the*
is not replaced by the+
then?05f3a28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@powtac The
*
matches between zero and unlimited times and is greedy, it matches us much as possible and gives back as needed when no matches are found which is what causes the backtracking issue in the CVE.Replacing the
*
with a+
would result in the query matching between one and unlimited times (required rather than optional), however changing the*
to*+
makes it possesive rather than greedy and prevents the backtracking.05f3a28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josh-gaby thank you for the detailed explanation. I was not aware of the different quantifier strategy when combining
*
and+
.05f3a28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, it can also be used to modify the standard
+
quantifier too,++
is the posessive quantifier used to match between one and unlimited times.