Skip to content

Commit c537c80

Browse files
authored
Merge pull request github#11095 from erik-krogh/exportRead
JS: recognize more re-exported values as exported
2 parents 8756989 + 138a16f commit c537c80

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-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() = imp.getImportedModuleNode() 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]] |
@@ -289,6 +295,11 @@ edges
289295
| lib.js:128:13:128:16 | path | lib.js:128:13:128:19 | path[0] |
290296
| lib.js:128:13:128:19 | path[0] | lib.js:128:9:128:20 | obj[path[0]] |
291297
| lib.js:128:13:128:19 | path[0] | lib.js:128:9:128:20 | obj[path[0]] |
298+
| sublib/other.js:5:28:5:31 | path | sublib/other.js:6:11:6:14 | path |
299+
| sublib/other.js:5:28:5:31 | path | sublib/other.js:6:11:6:14 | path |
300+
| sublib/other.js:6:11:6:14 | path | sublib/other.js:6:11:6:17 | path[0] |
301+
| sublib/other.js:6:11:6:17 | path[0] | sublib/other.js:6:7:6:18 | obj[path[0]] |
302+
| sublib/other.js:6:11:6:17 | path[0] | sublib/other.js:6:7:6:18 | obj[path[0]] |
292303
| sublib/sub.js:1:37:1:40 | path | sublib/sub.js:2:7:2:10 | path |
293304
| sublib/sub.js:1:37:1:40 | path | sublib/sub.js:2:7:2:10 | path |
294305
| sublib/sub.js:2:7:2:10 | path | sublib/sub.js:2:7:2:13 | path[0] |
@@ -356,6 +367,7 @@ edges
356367
| 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 |
357368
| 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 |
358369
| 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 |
370+
| 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 |
359371
| 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 |
360372
| 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 |
361373
| 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 |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(function () {
2+
function Foobar() {}
3+
4+
Foobar.prototype = {
5+
method: function (obj, path, value) {
6+
obj[path[0]][path[1]] = value; // NOT OK
7+
},
8+
};
9+
10+
module.exports.foobar = Foobar;
11+
12+
module.other.notExported = function (obj, path, value) {
13+
obj[path[0]][path[1]] = value; // OK - not exported
14+
}
15+
})();
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports.set = function (obj, path, value) {
22
obj[path[0]][path[1]] = value; // NOT OK
3-
}
3+
}
4+
5+
var other = require('./other')
6+
exports.foobar = other.foobar;

0 commit comments

Comments
 (0)