Skip to content

Commit 7877423

Browse files
committed
add library input as source to js/prototype-polluting-assignment
1 parent c9b50f3 commit 7877423

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/PrototypePollutingAssignmentCustomizations.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,13 @@ module PrototypePollutingAssignment {
5353
private class DefaultSource extends Source {
5454
DefaultSource() { this instanceof RemoteFlowSource }
5555
}
56+
57+
import semmle.javascript.PackageExports as Exports
58+
59+
/**
60+
* A parameter of an exported function, seen as a source prototype-polluting assignment.
61+
*/
62+
class ExternalInputSource extends Source, DataFlow::SourceNode {
63+
ExternalInputSource() { this = Exports::getALibraryInputParameter() }
64+
}
5665
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
nodes
2+
| lib.js:1:38:1:40 | obj |
3+
| lib.js:1:43:1:46 | path |
4+
| lib.js:1:43:1:46 | path |
5+
| lib.js:1:43:1:46 | path |
6+
| lib.js:2:7:2:27 | currentPath |
7+
| lib.js:2:7:2:27 | currentPath |
8+
| lib.js:2:21:2:24 | path |
9+
| lib.js:2:21:2:24 | path |
10+
| lib.js:2:21:2:27 | path[0] |
11+
| lib.js:2:21:2:27 | path[0] |
12+
| lib.js:6:7:6:9 | obj |
13+
| lib.js:6:7:6:9 | obj |
14+
| lib.js:11:17:11:32 | obj[currentPath] |
15+
| lib.js:11:17:11:32 | obj[currentPath] |
16+
| lib.js:11:21:11:31 | currentPath |
17+
| lib.js:11:21:11:31 | currentPath |
18+
| lib.js:11:35:11:38 | path |
19+
| lib.js:11:35:11:38 | path |
20+
| lib.js:11:35:11:47 | path.slice(1) |
21+
| lib.js:11:35:11:47 | path.slice(1) |
222
| tst.js:5:9:5:38 | taint |
323
| tst.js:5:17:5:38 | String( ... y.data) |
424
| tst.js:5:24:5:37 | req.query.data |
@@ -24,6 +44,28 @@ nodes
2444
| tst.js:48:9:48:11 | obj |
2545
| tst.js:48:9:48:11 | obj |
2646
edges
47+
| lib.js:1:38:1:40 | obj | lib.js:6:7:6:9 | obj |
48+
| lib.js:1:38:1:40 | obj | lib.js:6:7:6:9 | obj |
49+
| lib.js:1:43:1:46 | path | lib.js:2:21:2:24 | path |
50+
| lib.js:1:43:1:46 | path | lib.js:2:21:2:24 | path |
51+
| lib.js:1:43:1:46 | path | lib.js:2:21:2:24 | path |
52+
| lib.js:1:43:1:46 | path | lib.js:11:35:11:38 | path |
53+
| lib.js:1:43:1:46 | path | lib.js:11:35:11:38 | path |
54+
| lib.js:1:43:1:46 | path | lib.js:11:35:11:38 | path |
55+
| lib.js:2:7:2:27 | currentPath | lib.js:11:21:11:31 | currentPath |
56+
| lib.js:2:7:2:27 | currentPath | lib.js:11:21:11:31 | currentPath |
57+
| lib.js:2:21:2:24 | path | lib.js:2:21:2:27 | path[0] |
58+
| lib.js:2:21:2:24 | path | lib.js:2:21:2:27 | path[0] |
59+
| lib.js:2:21:2:27 | path[0] | lib.js:2:7:2:27 | currentPath |
60+
| lib.js:2:21:2:27 | path[0] | lib.js:2:7:2:27 | currentPath |
61+
| lib.js:11:17:11:32 | obj[currentPath] | lib.js:1:38:1:40 | obj |
62+
| lib.js:11:17:11:32 | obj[currentPath] | lib.js:1:38:1:40 | obj |
63+
| lib.js:11:21:11:31 | currentPath | lib.js:11:17:11:32 | obj[currentPath] |
64+
| lib.js:11:21:11:31 | currentPath | lib.js:11:17:11:32 | obj[currentPath] |
65+
| lib.js:11:35:11:38 | path | lib.js:11:35:11:47 | path.slice(1) |
66+
| lib.js:11:35:11:38 | path | lib.js:11:35:11:47 | path.slice(1) |
67+
| lib.js:11:35:11:47 | path.slice(1) | lib.js:1:43:1:46 | path |
68+
| lib.js:11:35:11:47 | path.slice(1) | lib.js:1:43:1:46 | path |
2769
| tst.js:5:9:5:38 | taint | tst.js:8:12:8:16 | taint |
2870
| tst.js:5:9:5:38 | taint | tst.js:9:12:9:16 | taint |
2971
| tst.js:5:9:5:38 | taint | tst.js:12:25:12:29 | taint |
@@ -48,6 +90,7 @@ edges
4890
| tst.js:33:23:33:25 | obj | tst.js:48:9:48:11 | obj |
4991
| tst.js:33:23:33:25 | obj | tst.js:48:9:48:11 | obj |
5092
#select
93+
| lib.js:6:7:6:9 | obj | lib.js:1:43:1:46 | path | lib.js:6:7:6:9 | obj | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:1:43:1:46 | path | here |
5194
| 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 | here |
5295
| 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 | here |
5396
| 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 | here |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports.set = function recSet(obj, path, value) {
2+
var currentPath = path[0];
3+
var currentValue = obj[currentPath];
4+
if (path.length === 1) {
5+
if (currentValue === void 0) {
6+
obj[currentPath] = value; // NOT OK
7+
}
8+
return currentValue;
9+
}
10+
11+
return recSet(obj[currentPath], path.slice(1), value);
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "my-lib",
3+
"version": "0.0.7",
4+
"main": "./lib.js"
5+
}

0 commit comments

Comments
 (0)