Skip to content

Commit 851d53d

Browse files
committed
don't sanitize calls through substring calls that just remove the start
1 parent 08bc14f commit 851d53d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

javascript/ql/lib/semmle/javascript/security/regexp/PolynomialReDoSCustomizations.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ module PolynomialReDoS {
9090
isCharClassLike(root)
9191
)
9292
or
93-
this.(DataFlow::MethodCallNode).getMethodName() = StringOps::substringMethodName()
93+
this.(DataFlow::MethodCallNode).getMethodName() = StringOps::substringMethodName() and
94+
not this.(DataFlow::MethodCallNode).getNumArgument() = 1 // with one argument it just slices off the beginning
9495
}
9596
}
9697

javascript/ql/test/query-tests/Security/CWE-400/ReDoS/PolynomialReDoS.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ nodes
3232
| lib/lib.js:41:32:41:35 | name |
3333
| lib/lib.js:42:17:42:20 | name |
3434
| lib/lib.js:42:17:42:20 | name |
35+
| lib/lib.js:44:5:44:25 | name |
36+
| lib/lib.js:44:12:44:15 | name |
37+
| lib/lib.js:44:12:44:25 | name.substr(1) |
38+
| lib/lib.js:45:17:45:20 | name |
39+
| lib/lib.js:45:17:45:20 | name |
3540
| lib/moduleLib/moduleLib.js:1:28:1:31 | name |
3641
| lib/moduleLib/moduleLib.js:1:28:1:31 | name |
3742
| lib/moduleLib/moduleLib.js:2:13:2:16 | name |
@@ -257,6 +262,12 @@ edges
257262
| lib/lib.js:41:32:41:35 | name | lib/lib.js:42:17:42:20 | name |
258263
| lib/lib.js:41:32:41:35 | name | lib/lib.js:42:17:42:20 | name |
259264
| lib/lib.js:41:32:41:35 | name | lib/lib.js:42:17:42:20 | name |
265+
| lib/lib.js:41:32:41:35 | name | lib/lib.js:44:12:44:15 | name |
266+
| lib/lib.js:41:32:41:35 | name | lib/lib.js:44:12:44:15 | name |
267+
| lib/lib.js:44:5:44:25 | name | lib/lib.js:45:17:45:20 | name |
268+
| lib/lib.js:44:5:44:25 | name | lib/lib.js:45:17:45:20 | name |
269+
| lib/lib.js:44:12:44:15 | name | lib/lib.js:44:12:44:25 | name.substr(1) |
270+
| lib/lib.js:44:12:44:25 | name.substr(1) | lib/lib.js:44:5:44:25 | name |
260271
| lib/moduleLib/moduleLib.js:1:28:1:31 | name | lib/moduleLib/moduleLib.js:2:13:2:16 | name |
261272
| lib/moduleLib/moduleLib.js:1:28:1:31 | name | lib/moduleLib/moduleLib.js:2:13:2:16 | name |
262273
| lib/moduleLib/moduleLib.js:1:28:1:31 | name | lib/moduleLib/moduleLib.js:2:13:2:16 | name |
@@ -449,6 +460,7 @@ edges
449460
| lib/lib.js:8:2:8:17 | /f*g/.test(name) | lib/lib.js:7:19:7:22 | name | lib/lib.js:8:13:8:16 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'f'. | lib/lib.js:8:3:8:4 | f* | regular expression | lib/lib.js:7:19:7:22 | name | library input |
450461
| lib/lib.js:36:2:36:17 | /f*g/.test(name) | lib/lib.js:32:32:32:40 | arguments | lib/lib.js:36:13:36:16 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'f'. | lib/lib.js:36:3:36:4 | f* | regular expression | lib/lib.js:32:32:32:40 | arguments | library input |
451462
| lib/lib.js:42:17:42:33 | name.match(/f*g/) | lib/lib.js:41:32:41:35 | name | lib/lib.js:42:17:42:20 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'f'. | lib/lib.js:42:29:42:30 | f* | regular expression | lib/lib.js:41:32:41:35 | name | library input |
463+
| lib/lib.js:45:17:45:33 | name.match(/f*g/) | lib/lib.js:41:32:41:35 | name | lib/lib.js:45:17:45:20 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'f'. | lib/lib.js:45:29:45:30 | f* | regular expression | lib/lib.js:41:32:41:35 | name | library input |
452464
| lib/moduleLib/moduleLib.js:2:2:2:17 | /a*b/.test(name) | lib/moduleLib/moduleLib.js:1:28:1:31 | name | lib/moduleLib/moduleLib.js:2:13:2:16 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'a'. | lib/moduleLib/moduleLib.js:2:3:2:4 | a* | regular expression | lib/moduleLib/moduleLib.js:1:28:1:31 | name | library input |
453465
| lib/otherLib/js/src/index.js:2:2:2:17 | /a*b/.test(name) | lib/otherLib/js/src/index.js:1:28:1:31 | name | lib/otherLib/js/src/index.js:2:13:2:16 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'a'. | lib/otherLib/js/src/index.js:2:3:2:4 | a* | regular expression | lib/otherLib/js/src/index.js:1:28:1:31 | name | library input |
454466
| lib/snapdragon.js:7:15:7:32 | this.match(/aa*$/) | lib/snapdragon.js:3:34:3:38 | input | lib/snapdragon.js:7:15:7:18 | this | This $@ that depends on $@ may run slow on strings starting with 'a' and with many repetitions of 'a'. | lib/snapdragon.js:7:28:7:29 | a* | regular expression | lib/snapdragon.js:3:34:3:38 | input | library input |

javascript/ql/test/query-tests/Security/CWE-400/ReDoS/lib/lib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ module.exports.foo = function (name) {
4242
var data1 = name.match(/f*g/); // NOT OK
4343

4444
name = name.substr(1);
45-
var data2 = name.match(/f*g/); // NOT OK - but not flagged
45+
var data2 = name.match(/f*g/); // NOT OK
4646
}

0 commit comments

Comments
 (0)