Skip to content

Commit 6327fce

Browse files
committed
remove paths without unmatched returns from polynomial-redos
1 parent 55c17f4 commit 6327fce

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

javascript/ql/lib/semmle/javascript/security/performance/PolynomialReDoS.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,15 @@ module PolynomialReDoS {
2828
super.isSanitizer(node) or
2929
node instanceof Sanitizer
3030
}
31+
32+
override predicate hasFlowPath(DataFlow::SourcePathNode source, DataFlow::SinkPathNode sink) {
33+
super.hasFlowPath(source, sink) and
34+
// require that there is a path without unmatched return steps
35+
DataFlow::hasPathWithoutUnmatchedReturn(source, sink)
36+
}
37+
38+
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
39+
DataFlow::localFieldStep(pred, succ)
40+
}
3141
}
3242
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
| lib/indirect.js:2:6:2:7 | k* | Strings with many repetitions of 'k' can start matching anywhere after the start of the preceeding k*h |
3232
| lib/lib.js:1:15:1:16 | a* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding a*b |
3333
| lib/lib.js:8:3:8:4 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |
34+
| lib/lib.js:28:3:28:4 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |
3435
| lib/moduleLib/moduleLib.js:2:3:2:4 | a* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding a*b |
3536
| lib/otherLib/js/src/index.js:2:3:2:4 | a* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding a*b |
3637
| lib/sublib/factory.js:13:14:13:15 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ nodes
1515
| lib/lib.js:7:19:7:22 | name |
1616
| lib/lib.js:8:13:8:16 | name |
1717
| lib/lib.js:8:13:8:16 | name |
18+
| lib/lib.js:21:14:21:14 | x |
19+
| lib/lib.js:21:14:21:14 | x |
20+
| lib/lib.js:22:9:22:9 | x |
21+
| lib/lib.js:27:6:27:19 | y |
22+
| lib/lib.js:27:10:27:19 | id("safe") |
23+
| lib/lib.js:28:13:28:13 | y |
24+
| lib/lib.js:28:13:28:13 | y |
1825
| lib/moduleLib/moduleLib.js:1:28:1:31 | name |
1926
| lib/moduleLib/moduleLib.js:1:28:1:31 | name |
2027
| lib/moduleLib/moduleLib.js:2:13:2:16 | name |
@@ -186,6 +193,12 @@ edges
186193
| lib/lib.js:7:19:7:22 | name | lib/lib.js:8:13:8:16 | name |
187194
| lib/lib.js:7:19:7:22 | name | lib/lib.js:8:13:8:16 | name |
188195
| lib/lib.js:7:19:7:22 | name | lib/lib.js:8:13:8:16 | name |
196+
| lib/lib.js:21:14:21:14 | x | lib/lib.js:22:9:22:9 | x |
197+
| lib/lib.js:21:14:21:14 | x | lib/lib.js:22:9:22:9 | x |
198+
| lib/lib.js:22:9:22:9 | x | lib/lib.js:27:10:27:19 | id("safe") |
199+
| lib/lib.js:27:6:27:19 | y | lib/lib.js:28:13:28:13 | y |
200+
| lib/lib.js:27:6:27:19 | y | lib/lib.js:28:13:28:13 | y |
201+
| lib/lib.js:27:10:27:19 | id("safe") | lib/lib.js:27:6:27:19 | y |
189202
| lib/moduleLib/moduleLib.js:1:28:1:31 | name | lib/moduleLib/moduleLib.js:2:13:2:16 | name |
190203
| lib/moduleLib/moduleLib.js:1:28:1:31 | name | lib/moduleLib/moduleLib.js:2:13:2:16 | name |
191204
| lib/moduleLib/moduleLib.js:1:28:1:31 | name | lib/moduleLib/moduleLib.js:2:13:2:16 | name |

javascript/ql/test/query-tests/Performance/ReDoS/lib/lib.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@ module.exports.closure = require("./closure")
1616

1717
module.exports.func = function (conf) {
1818
return require("./indirect")
19+
}
20+
21+
function id (x) {
22+
return x;
23+
}
24+
module.exports.id = id;
25+
26+
module.exports.safe = function (x) {
27+
var y = id("safe");
28+
/f*g/.test(y); // OK
1929
}

0 commit comments

Comments
 (0)