docs: add guidance on avoiding catastrophic backtracking#4667
Merged
Conversation
Document the root cause of ReDoS in CRS regexes (ambiguity inside a quantified group, not greediness) and how to avoid it, since CRS cannot use atomic groups or possessive quantifiers. Add a "Avoiding Catastrophic Backtracking (Ambiguity)" subsection with the guiding principle, the two common ambiguous shapes (a `\s` branch next to a comment body that also matches whitespace; a token wrapped in `\s*` on both sides inside a repeated group), a before/after example, and two CRS-specific testing notes: test with `.` matching newlines (DOTALL, as ModSecurity runs it), and treat PCRE2 exceeding its backtracking limit (an error that makes the rule fail) as the meaningful signal rather than a checker's theoretical complexity label.
Contributor
|
This should also be documented on the website, where our regex docs live. |
theseion
requested changes
Jun 17, 2026
Co-authored-by: Max Leske <[email protected]>
theseion
approved these changes
Jun 18, 2026
This was referenced Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
what
CONTRIBUTING.mdwhy
\sbranch next to a comment body that also matches whitespace; a token wrapped in\s*on both sides inside a repeated group), and a before/after example..matching newlines (DOTALL, as ModSecurity runs@rx), and treat PCRE2 exceeding its backtracking limit (which errors and makes the rule fail to match) as the meaningful signal, rather than a checker's theoretical "exponential" label (RE2 is immune; PCRE2's required-literal optimization tames many theoretically-ambiguous cases).refs
ai disclosure
reand PCRE2grep -P); the before/after example is a real de-ambiguation verified to be flat on both engines while preserving functional matches