Skip to content

Commit 655b4a4

Browse files
committed
recognize more re-exported values as exported
1 parent 94e864e commit 655b4a4

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

javascript/ql/lib/semmle/javascript/PackageExports.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ private DataFlow::Node getAValueExportedByPackage() {
7575
result = getAnExportFromModule(mod)
7676
)
7777
or
78+
// re-export of a value from another module
79+
// `module.exports.foo = require("./other").bar;`
80+
// other.js:
81+
// `module.exports.bar = function () { ... };`
82+
exists(DataFlow::PropRead read, Import imp |
83+
read = getAValueExportedByPackage() and
84+
read.getBase().getALocalSource().getEnclosingExpr() = imp and
85+
result = imp.getImportedModule().getAnExportedValue(read.getPropertyName())
86+
)
87+
or
7888
// require("./other-module.js"); inside an AMD module.
7989
exists(Module mod, CallExpr call |
8090
call = getAValueExportedByPackage().asExpr() and

javascript/ql/test/query-tests/Security/CWE-915/PrototypePollutingAssignment/PrototypePollutingAssignment.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ nodes
117117
| lib.js:128:9:128:20 | obj[path[0]] |
118118
| lib.js:128:13:128:16 | path |
119119
| lib.js:128:13:128:19 | path[0] |
120+
| sublib/other.js:5:28:5:31 | path |
121+
| sublib/other.js:5:28:5:31 | path |
122+
| sublib/other.js:6:7:6:18 | obj[path[0]] |
123+
| sublib/other.js:6:7:6:18 | obj[path[0]] |
124+
| sublib/other.js:6:11:6:14 | path |
125+
| sublib/other.js:6:11:6:17 | path[0] |
120126
| sublib/sub.js:1:37:1:40 | path |
121127
| sublib/sub.js:1:37:1:40 | path |
122128
| sublib/sub.js:2:3:2:14 | obj[path[0]] |
@@ -287,6 +293,11 @@ edges
287293
| lib.js:128:13:128:16 | path | lib.js:128:13:128:19 | path[0] |
288294
| lib.js:128:13:128:19 | path[0] | lib.js:128:9:128:20 | obj[path[0]] |
289295
| lib.js:128:13:128:19 | path[0] | lib.js:128:9:128:20 | obj[path[0]] |
296+
| sublib/other.js:5:28:5:31 | path | sublib/other.js:6:11:6:14 | path |
297+
| sublib/other.js:5:28:5:31 | path | sublib/other.js:6:11:6:14 | path |
298+
| sublib/other.js:6:11:6:14 | path | sublib/other.js:6:11:6:17 | path[0] |
299+
| sublib/other.js:6:11:6:17 | path[0] | sublib/other.js:6:7:6:18 | obj[path[0]] |
300+
| sublib/other.js:6:11:6:17 | path[0] | sublib/other.js:6:7:6:18 | obj[path[0]] |
290301
| sublib/sub.js:1:37:1:40 | path | sublib/sub.js:2:7:2:10 | path |
291302
| sublib/sub.js:1:37:1:40 | path | sublib/sub.js:2:7:2:10 | path |
292303
| sublib/sub.js:2:7:2:10 | path | sublib/sub.js:2:7:2:13 | path[0] |
@@ -354,6 +365,7 @@ edges
354365
| lib.js:108:3:108:10 | obj[one] | lib.js:104:13:104:21 | arguments | lib.js:108:3:108:10 | obj[one] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:104:13:104:21 | arguments | library input |
355366
| lib.js:119:13:119:24 | obj[path[0]] | lib.js:118:29:118:32 | path | lib.js:119:13:119:24 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:118:29:118:32 | path | library input |
356367
| lib.js:128:9:128:20 | obj[path[0]] | lib.js:127:14:127:17 | path | lib.js:128:9:128:20 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:127:14:127:17 | path | library input |
368+
| sublib/other.js:6:7:6:18 | obj[path[0]] | sublib/other.js:5:28:5:31 | path | sublib/other.js:6:7:6:18 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | sublib/other.js:5:28:5:31 | path | library input |
357369
| sublib/sub.js:2:3:2:14 | obj[path[0]] | sublib/sub.js:1:37:1:40 | path | sublib/sub.js:2:3:2:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | sublib/sub.js:1:37:1:40 | path | library input |
358370
| tst.js:8:5:8:17 | object[taint] | tst.js:5:24:5:37 | req.query.data | tst.js:8:5:8:17 | object[taint] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:5:24:5:37 | req.query.data | user controlled input |
359371
| tst.js:9:5:9:17 | object[taint] | tst.js:5:24:5:37 | req.query.data | tst.js:9:5:9:17 | object[taint] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:5:24:5:37 | req.query.data | user controlled input |

javascript/ql/test/query-tests/Security/CWE-915/PrototypePollutingAssignment/sublib/other.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33

44
Foobar.prototype = {
55
method: function (obj, path, value) {
6-
obj[path[0]][path[1]] = value; // NOT OK - but not flagged [INCONSISTENCY]
6+
obj[path[0]][path[1]] = value; // NOT OK
77
},
88
};
99

1010
module.exports.foobar = Foobar;
11+
12+
module.other.notExported = function (obj, path, value) {
13+
obj[path[0]][path[1]] = value; // OK - not exported
14+
}
1115
})();

0 commit comments

Comments
 (0)