Skip to content

Commit a44aefa

Browse files
committed
add test for top-level closure modules - and simplify
1 parent fbfbe70 commit a44aefa

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

javascript/ql/src/semmle/javascript/PackageExports.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ private DataFlow::Node getAValueExportedByPackage() {
7878
private DataFlow::Node getAnExportFromModule(Module mod) {
7979
result.analyze().getAValue() = mod.(NodeModule).getAModuleExportsValue()
8080
or
81-
exists(Variable var | var = mod.(Closure::ClosureModule).getExportsVariable() |
82-
result.asExpr() = var.getAReference() or
83-
result.asExpr() = var.getAnAssignedExpr()
84-
)
81+
result = mod.(Closure::ClosureModule).getExportsVariable().getAnAssignedExpr().flow()
8582
or
8683
result.analyze().getAValue() = mod.(AmdModule).getDefine().getAModuleExportsValue()
8784
or

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| highlight.js:38:54:38:59 | [^()]* | Strings starting with 'A((' and with many repetitions of ''' can start matching anywhere after the start of the preceeding [^()]* |
2525
| highlight.js:38:64:38:69 | [^()]* | Strings starting with 'A(' and with many repetitions of ''' can start matching anywhere after the start of the preceeding [^()]* |
2626
| highlight.js:39:22:39:24 | \\w* | Strings starting with 'A' and with many repetitions of 'A' can start matching anywhere after the start of the preceeding [a-zA-Z_]\\w*\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{ |
27+
| lib/closure.js:4:6:4:7 | u* | Strings with many repetitions of 'u' can start matching anywhere after the start of the preceeding u*o |
2728
| 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 |
2829
| 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 |
2930
| polynomial-redos.js:7:24:7:26 | \\s+ | Strings with many repetitions of ' ' can start matching anywhere after the start of the preceeding \\s+$ |

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
nodes
2+
| lib/closure.js:3:21:3:21 | x |
3+
| lib/closure.js:3:21:3:21 | x |
4+
| lib/closure.js:4:16:4:16 | x |
5+
| lib/closure.js:4:16:4:16 | x |
26
| lib/lib.js:3:28:3:31 | name |
37
| lib/lib.js:3:28:3:31 | name |
48
| lib/lib.js:4:14:4:17 | name |
@@ -150,6 +154,10 @@ nodes
150154
| polynomial-redos.js:124:12:124:17 | result |
151155
| polynomial-redos.js:124:12:124:17 | result |
152156
edges
157+
| lib/closure.js:3:21:3:21 | x | lib/closure.js:4:16:4:16 | x |
158+
| lib/closure.js:3:21:3:21 | x | lib/closure.js:4:16:4:16 | x |
159+
| lib/closure.js:3:21:3:21 | x | lib/closure.js:4:16:4:16 | x |
160+
| lib/closure.js:3:21:3:21 | x | lib/closure.js:4:16:4:16 | x |
153161
| lib/lib.js:3:28:3:31 | name | lib/lib.js:4:14:4:17 | name |
154162
| lib/lib.js:3:28:3:31 | name | lib/lib.js:4:14:4:17 | name |
155163
| lib/lib.js:3:28:3:31 | name | lib/lib.js:4:14:4:17 | name |
@@ -296,6 +304,7 @@ edges
296304
| polynomial-redos.js:123:3:123:20 | result | polynomial-redos.js:124:12:124:17 | result |
297305
| polynomial-redos.js:123:13:123:20 | replaced | polynomial-redos.js:123:3:123:20 | result |
298306
#select
307+
| lib/closure.js:4:5:4:17 | /u*o/.test(x) | lib/closure.js:3:21:3:21 | x | lib/closure.js:4:16:4:16 | x | This $@ that depends on $@ may run slow on strings with many repetitions of 'u'. | lib/closure.js:4:6:4:7 | u* | regular expression | lib/closure.js:3:21:3:21 | x | library input |
299308
| lib/lib.js:4:2:4:18 | regexp.test(name) | lib/lib.js:3:28:3:31 | name | lib/lib.js:4:14:4:17 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'a'. | lib/lib.js:1:15:1:16 | a* | regular expression | lib/lib.js:3:28:3:31 | name | library input |
300309
| 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 |
301310
| polynomial-redos.js:7:2:7:34 | tainted ... /g, '') | polynomial-redos.js:5:16:5:32 | req.query.tainted | polynomial-redos.js:7:2:7:8 | tainted | This $@ that depends on $@ may run slow on strings with many repetitions of ' '. | polynomial-redos.js:7:24:7:26 | \\s+ | regular expression | polynomial-redos.js:5:16:5:32 | req.query.tainted | a user-provided value |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
goog.module('x.y.z.closure2');
2+
3+
exports = function (x) {
4+
/u*o/.test(x); // NOT OK
5+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ function bar(reg, name) {
1010

1111
if (typeof define !== 'undefined' && define.amd) { // AMD
1212
define([], function () {return bar});
13-
}
13+
}
14+
15+
module.exports.closure = require("./closure")

0 commit comments

Comments
 (0)