Skip to content

Add ReDoS check for nested quantifiers - #56

Merged
thatch merged 1 commit into
thatch:masterfrom
jvoisin:redos
Jul 31, 2026
Merged

Add ReDoS check for nested quantifiers#56
thatch merged 1 commit into
thatch:masterfrom
jvoisin:redos

Conversation

@jvoisin

@jvoisin jvoisin commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Flag unbounded quantifiers (, +, open-ended {n,}) applied to a group whose whole body reduces to a single unbounded repetition, e.g. (a+)+, (a+), ([ab])+, (a{1,})+ and (a+|b). These are the classic catastrophic-backtracking shapes where the inner quantifier can split the same input in exponentially many ways.

The check is deliberately conservative to stay false-positive-free on real lexers: bodies with a mandatory fixed part (ab+, a+b), single-char alternations (a|b), bounded outer quantifiers ((a+)?, (a+){2}) and the common string-lexer idioms (.|[^"])* / ([^"\\]|\.)* are left alone. This misses multi-atom overlaps like (\w+\s?)*.

Includes unit tests covering the positive, alternation-branch, nested-group and safe/no-flag cases.

Flag unbounded quantifiers (*, +, open-ended {n,}) applied to a group
whose whole body reduces to a single unbounded repetition, e.g. (a+)+,
(a+)*, ([ab]*)+, (a{1,})+ and (a+|b)*. These are the classic
catastrophic-backtracking shapes where the inner quantifier can split
the same input in exponentially many ways.

The check is deliberately conservative to stay false-positive-free on
real lexers: bodies with a mandatory fixed part (ab+, a+b), single-char
alternations (a|b), bounded outer quantifiers ((a+)?, (a+){2}) and the
common string-lexer idioms (\.|[^"])* / ([^"\\]|\\.)* are left alone.
This misses multi-atom overlaps like (\w+\s?)*.

Includes unit tests covering the positive, alternation-branch,
nested-group and safe/no-flag cases.
thatch added a commit that referenced this pull request Jul 31, 2026
Renumber check_single_char_alternation from 129 to 131; it collided
with the checks added by #55 and #56 (both already 129/130), since
all three PRs were written independently against the same base.
thatch added a commit that referenced this pull request Jul 31, 2026
Renumber check_quantified_lookaround from 129 to 132; it collided
with checks added by #55/#56/#57 (129/130/131), since all were
written independently against the same base.
@thatch
thatch merged commit 303035f into thatch:master Jul 31, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants