Skip to content

Commit 762f7bf

Browse files
authored
Merge pull request #9115 from erik-krogh/fileAndFolder
JS: resolve main module when there is a folder with the same name as the main file
2 parents e8b7262 + b1e8b33 commit 762f7bf

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

javascript/ql/lib/semmle/javascript/NodeModuleResolutionImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ File resolveMainModule(PackageJson pkg, int priority) {
9696
or
9797
result = tryExtensions(main.resolve(), "index", priority)
9898
or
99-
not exists(main.resolve()) and
99+
not main.resolve() instanceof File and
100100
exists(int n | n = main.getNumComponent() |
101101
result = tryExtensions(main.resolveUpTo(n - 1), getStem(main.getComponent(n - 1)), priority)
102102
)

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
@@ -94,6 +94,12 @@ nodes
9494
| lib.js:108:3:108:10 | obj[one] |
9595
| lib.js:108:3:108:10 | obj[one] |
9696
| lib.js:108:7:108:9 | one |
97+
| sublib/sub.js:1:37:1:40 | path |
98+
| sublib/sub.js:1:37:1:40 | path |
99+
| sublib/sub.js:2:3:2:14 | obj[path[0]] |
100+
| sublib/sub.js:2:3:2:14 | obj[path[0]] |
101+
| sublib/sub.js:2:7:2:10 | path |
102+
| sublib/sub.js:2:7:2:13 | path[0] |
97103
| tst.js:5:9:5:38 | taint |
98104
| tst.js:5:17:5:38 | String( ... y.data) |
99105
| tst.js:5:24:5:37 | req.query.data |
@@ -230,6 +236,11 @@ edges
230236
| lib.js:104:13:104:24 | arguments[1] | lib.js:104:7:104:24 | one |
231237
| lib.js:108:7:108:9 | one | lib.js:108:3:108:10 | obj[one] |
232238
| lib.js:108:7:108:9 | one | lib.js:108:3:108:10 | obj[one] |
239+
| sublib/sub.js:1:37:1:40 | path | sublib/sub.js:2:7:2:10 | path |
240+
| sublib/sub.js:1:37:1:40 | path | sublib/sub.js:2:7:2:10 | path |
241+
| sublib/sub.js:2:7:2:10 | path | sublib/sub.js:2:7:2:13 | path[0] |
242+
| sublib/sub.js:2:7:2:13 | path[0] | sublib/sub.js:2:3:2:14 | obj[path[0]] |
243+
| sublib/sub.js:2:7:2:13 | path[0] | sublib/sub.js:2:3:2:14 | obj[path[0]] |
233244
| tst.js:5:9:5:38 | taint | tst.js:8:12:8:16 | taint |
234245
| tst.js:5:9:5:38 | taint | tst.js:9:12:9:16 | taint |
235246
| tst.js:5:9:5:38 | taint | tst.js:12:25:12:29 | taint |
@@ -284,6 +295,7 @@ edges
284295
| lib.js:70:13:70:24 | obj[path[0]] | lib.js:59:18:59:18 | s | lib.js:70:13:70:24 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:59:18:59:18 | s | library input |
285296
| lib.js:87:10:87:14 | proto | lib.js:83:14:83:25 | arguments[1] | lib.js:87:10:87:14 | proto | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:83:14:83:25 | arguments[1] | library input |
286297
| lib.js:108:3:108:10 | obj[one] | lib.js:104:13:104:24 | arguments[1] | 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:24 | arguments[1] | library input |
298+
| 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 |
287299
| 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 |
288300
| 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 |
289301
| tst.js:14:5:14:32 | unsafeG ... taint) | tst.js:5:24:5:37 | req.query.data | tst.js:14:5:14:32 | unsafeG ... 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "sublib",
3+
"main": "./sub"
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports.set = function (obj, path, value) {
2+
obj[path[0]][path[1]] = value; // NOT OK
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("foo");

0 commit comments

Comments
 (0)