Skip to content

Commit a9a9e34

Browse files
committed
recognize delete expresssions as a sink for js/prototype-polluting-assignment
1 parent 1243c73 commit a9a9e34

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ module PrototypePollutingAssignment {
4949
this = any(DataFlow::PropWrite write).getBase()
5050
or
5151
this = any(ExtendCall c).getDestinationOperand()
52+
or
53+
this = any(DeleteExpr del).getOperand().flow().(DataFlow::PropRef).getBase()
5254
}
5355

5456
override DataFlow::FlowLabel getAFlowLabel() { result instanceof ObjectPrototype }

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ nodes
7070
| lib.js:70:13:70:24 | obj[path[0]] |
7171
| lib.js:70:17:70:20 | path |
7272
| lib.js:70:17:70:23 | path[0] |
73+
| lib.js:83:7:83:25 | path |
74+
| lib.js:83:14:83:25 | arguments[1] |
75+
| lib.js:83:14:83:25 | arguments[1] |
76+
| lib.js:86:7:86:26 | proto |
77+
| lib.js:86:15:86:26 | obj[path[0]] |
78+
| lib.js:86:19:86:22 | path |
79+
| lib.js:86:19:86:25 | path[0] |
80+
| lib.js:87:10:87:14 | proto |
81+
| lib.js:87:10:87:14 | proto |
7382
| tst.js:5:9:5:38 | taint |
7483
| tst.js:5:17:5:38 | String( ... y.data) |
7584
| tst.js:5:24:5:37 | req.query.data |
@@ -175,6 +184,14 @@ edges
175184
| lib.js:70:17:70:20 | path | lib.js:70:17:70:23 | path[0] |
176185
| lib.js:70:17:70:23 | path[0] | lib.js:70:13:70:24 | obj[path[0]] |
177186
| lib.js:70:17:70:23 | path[0] | lib.js:70:13:70:24 | obj[path[0]] |
187+
| lib.js:83:7:83:25 | path | lib.js:86:19:86:22 | path |
188+
| lib.js:83:14:83:25 | arguments[1] | lib.js:83:7:83:25 | path |
189+
| lib.js:83:14:83:25 | arguments[1] | lib.js:83:7:83:25 | path |
190+
| lib.js:86:7:86:26 | proto | lib.js:87:10:87:14 | proto |
191+
| lib.js:86:7:86:26 | proto | lib.js:87:10:87:14 | proto |
192+
| lib.js:86:15:86:26 | obj[path[0]] | lib.js:86:7:86:26 | proto |
193+
| lib.js:86:19:86:22 | path | lib.js:86:19:86:25 | path[0] |
194+
| lib.js:86:19:86:25 | path[0] | lib.js:86:15:86:26 | obj[path[0]] |
178195
| tst.js:5:9:5:38 | taint | tst.js:8:12:8:16 | taint |
179196
| tst.js:5:9:5:38 | taint | tst.js:9:12:9:16 | taint |
180197
| tst.js:5:9:5:38 | taint | tst.js:12:25:12:29 | taint |
@@ -219,6 +236,7 @@ edges
219236
| lib.js:34:3:34:14 | obj[path[0]] | lib.js:32:14:32:20 | args[1] | lib.js:34:3:34:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:32:14:32:20 | args[1] | library input |
220237
| lib.js:42:3:42:14 | obj[path[0]] | lib.js:40:14:40:20 | args[1] | lib.js:42:3:42:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:40:14:40:20 | args[1] | library input |
221238
| 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 |
239+
| 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 |
222240
| 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 |
223241
| 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 |
224242
| 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 |

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ class Foo {
6969
const value = this.value;
7070
return (obj[path[0]][path[1]] = value); // NOT OK
7171
}
72+
73+
safe() {
74+
const obj = this.obj;
75+
obj[path[0]] = this.value; // OK
76+
}
7277
}
7378

7479
module.exports.Foo = Foo;
80+
81+
module.exports.delete = function() {
82+
var obj = arguments[0];
83+
var path = arguments[1];
84+
delete obj[path[0]]; // OK
85+
var prop = arguments[2];
86+
var proto = obj[path[0]];
87+
delete proto[prop]; // NOT
88+
}

0 commit comments

Comments
 (0)