Skip to content

Commit 1506ac0

Browse files
committed
limit the number of characters produced by getAThreewayIntersect
1 parent 0117a0f commit 1506ac0

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

javascript/ql/src/semmle/javascript/security/performance/SuperlinearBackTracking.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,20 @@ predicate step(
209209
*/
210210
pragma[noinline]
211211
string getAThreewayIntersect(InputSymbol s1, InputSymbol s2, InputSymbol s3) {
212-
result = intersect(s1, s2) and result = [intersect(s2, s3), intersect(s1, s3)]
212+
result = minAndMaxIntersect(s1, s2) and result = [intersect(s2, s3), intersect(s1, s3)]
213213
or
214-
result = intersect(s1, s3) and result = [intersect(s2, s3), intersect(s1, s2)]
214+
result = minAndMaxIntersect(s1, s3) and result = [intersect(s2, s3), intersect(s1, s2)]
215215
or
216-
result = intersect(s2, s3) and result = [intersect(s1, s2), intersect(s1, s3)]
216+
result = minAndMaxIntersect(s2, s3) and result = [intersect(s1, s2), intersect(s1, s3)]
217+
}
218+
219+
/**
220+
* Gets the minimum and maximum characters that intersect between `a` and `b`.
221+
* This predicate is used to limit the size of `getAThreewayIntersect`.
222+
*/
223+
pragma[noinline]
224+
string minAndMaxIntersect(InputSymbol a, InputSymbol b) {
225+
result = [min(intersect(a, b)), max(intersect(a, b))]
217226
}
218227

219228
private newtype TTrace =

javascript/ql/test/query-tests/Performance/ReDoS/PolynomialBackTracking.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@
442442
| tst.js:221:15:221:22 | ([^X]b)+ | Strings with many repetitions of 'Wb' can start matching anywhere after the start of the preceeding (([^X]b)+)* |
443443
| tst.js:227:15:227:22 | ([^X]b)+ | Strings with many repetitions of 'Wb' can start matching anywhere after the start of the preceeding (([^X]b)+)* |
444444
| tst.js:239:15:239:19 | (ab)+ | Strings with many repetitions of 'ab' can start matching anywhere after the start of the preceeding ((ab)+)* |
445-
| tst.js:245:15:245:21 | [\\n\\s]+ | Strings with many repetitions of '\\n' can start matching anywhere after the start of the preceeding ([\\n\\s]+)* |
446445
| tst.js:248:18:248:19 | A* | Strings with many repetitions of 'A' can start matching anywhere after the start of the preceeding A* |
447446
| tst.js:254:15:254:17 | \\w* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding \\d* |
448447
| tst.js:254:27:254:29 | \\w* | Strings starting with 'foobarbaz' and with many repetitions of 'foobarbaz' can start matching anywhere after the start of the preceeding \\d* |

0 commit comments

Comments
 (0)