Skip to content

Commit 57884ae

Browse files
committed
fix(security): tighten overlappingAlt detector to catch (a|aa)+ patterns
The previous regex required a second quantifier after the group quantifier, so patterns like (a|aa)+$ could bypass the ReDoS check. Remove the trailing quantifier requirement so any quantified alternation group is flagged. Addresses coderabbitai review comment on PR wonderwhy-er#400. https://claude.ai/code/session_01UesrAy2NYmCpw7rqX71V5X
1 parent b88ffdf commit 57884ae

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/search-manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export function isSafeRegex(pattern: string): boolean {
2121
return false;
2222
}
2323

24-
// Detect overlapping alternations in quantified groups: (a|a)+, (\w|\d)+
25-
// These can also cause catastrophic backtracking
26-
const overlappingAlt = /\((?:[^)]*\|[^)]*)\)[+*]\s*[+*?{]/;
24+
// Detect overlapping alternations in quantified groups: (a|a)+, (a|aa)+, (\w|\d)+
25+
// These can cause catastrophic backtracking even without a second outer quantifier
26+
const overlappingAlt = /\((?:[^)]*\|[^)]*)\)[+*]/;
2727
if (overlappingAlt.test(pattern)) {
2828
return false;
2929
}

0 commit comments

Comments
 (0)