Skip to content

Commit 99bad77

Browse files
authored
Merge pull request github#11906 from erik-krogh/moreStem
JS: expand what is parsed as the stem of a pathexpr
2 parents ddef87f + 4b74dec commit 99bad77

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ File tryExtensions(Folder dir, string basename, int priority) {
8787
* Or `name`, if `name` has no file extension.
8888
*/
8989
bindingset[name]
90-
private string getStem(string name) { result = name.regexpCapture("(.+?)(?:\\.([^.]+))?", 1) }
90+
private string getStem(string name) {
91+
// everything before the last dot
92+
result = name.regexpCapture("(.+?)(?:\\.([^.]+))?", 1)
93+
or
94+
// everything before the first dot
95+
result = name.regexpCapture("^([^.]*)\\..*$", 1)
96+
}
9197

9298
/**
9399
* Gets a file that a main module from `pkg` exported as `mainPath` with the given `priority`.

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+
| otherlib/src/otherlibimpl.js:1:37:1:40 | path |
121+
| otherlib/src/otherlibimpl.js:1:37:1:40 | path |
122+
| otherlib/src/otherlibimpl.js:2:3:2:14 | obj[path[0]] |
123+
| otherlib/src/otherlibimpl.js:2:3:2:14 | obj[path[0]] |
124+
| otherlib/src/otherlibimpl.js:2:7:2:10 | path |
125+
| otherlib/src/otherlibimpl.js:2:7:2:13 | path[0] |
120126
| sublib/other.js:5:28:5:31 | path |
121127
| sublib/other.js:5:28:5:31 | path |
122128
| sublib/other.js:6:7:6:18 | obj[path[0]] |
@@ -295,6 +301,11 @@ edges
295301
| lib.js:128:13:128:16 | path | lib.js:128:13:128:19 | path[0] |
296302
| lib.js:128:13:128:19 | path[0] | lib.js:128:9:128:20 | obj[path[0]] |
297303
| lib.js:128:13:128:19 | path[0] | lib.js:128:9:128:20 | obj[path[0]] |
304+
| otherlib/src/otherlibimpl.js:1:37:1:40 | path | otherlib/src/otherlibimpl.js:2:7:2:10 | path |
305+
| otherlib/src/otherlibimpl.js:1:37:1:40 | path | otherlib/src/otherlibimpl.js:2:7:2:10 | path |
306+
| otherlib/src/otherlibimpl.js:2:7:2:10 | path | otherlib/src/otherlibimpl.js:2:7:2:13 | path[0] |
307+
| otherlib/src/otherlibimpl.js:2:7:2:13 | path[0] | otherlib/src/otherlibimpl.js:2:3:2:14 | obj[path[0]] |
308+
| otherlib/src/otherlibimpl.js:2:7:2:13 | path[0] | otherlib/src/otherlibimpl.js:2:3:2:14 | obj[path[0]] |
298309
| sublib/other.js:5:28:5:31 | path | sublib/other.js:6:11:6:14 | path |
299310
| sublib/other.js:5:28:5:31 | path | sublib/other.js:6:11:6:14 | path |
300311
| sublib/other.js:6:11:6:14 | path | sublib/other.js:6:11:6:17 | path[0] |
@@ -367,6 +378,7 @@ edges
367378
| 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 |
368379
| 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 |
369380
| 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 |
381+
| otherlib/src/otherlibimpl.js:2:3:2:14 | obj[path[0]] | otherlib/src/otherlibimpl.js:1:37:1:40 | path | otherlib/src/otherlibimpl.js:2:3:2:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | otherlib/src/otherlibimpl.js:1:37:1:40 | path | library input |
370382
| 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 |
371383
| 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 |
372384
| 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 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "otherlib",
3+
"main": "dist/otherlibimpl.node.cjs.js"
4+
}
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+
}

0 commit comments

Comments
 (0)