Commit 0249004
committed
fix: replace lazy quantifier with greedy to prevent ReDoS backtracking
Replace lazy quantifier +? with greedy quantifier + in regex patterns
to prevent catastrophic backtracking and ReDoS attacks.
The pattern ([^+\n]+?)(?=\n|$) uses a lazy quantifier that can cause
super-linear runtime when the lookahead fails, leading to backtracking.
Using a greedy quantifier ([^+\n]+)(?=\n|$) matches as much as possible
first, then verifies with the lookahead, preventing excessive backtracking.
Fixed patterns:
- Invoice Date patterns (2 regexes): Changed +? to +
- Due Date patterns (2 regexes): Changed +? to +
- Service patterns (2 regexes): Changed +? to +
The greedy quantifier is safer because it doesn't backtrack through
multiple positions when the lookahead fails, making the regex linear
in complexity rather than quadratic or exponential.1 parent b0f351a commit 0249004
1 file changed
Lines changed: 10 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1056 | 1056 | | |
1057 | 1057 | | |
1058 | 1058 | | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
1062 | 1063 | | |
1063 | 1064 | | |
1064 | 1065 | | |
1065 | | - | |
1066 | | - | |
1067 | | - | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
1068 | 1069 | | |
1069 | 1070 | | |
1070 | 1071 | | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
1074 | 1075 | | |
1075 | 1076 | | |
1076 | 1077 | | |
| |||
0 commit comments