Skip to content

Commit 0247606

Browse files
committed
JS: Add prototype pollution test
1 parent 2f4a181 commit 0247606

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| query-tests/Security/CWE-915/PrototypePollutingAssignment/tst.js:120 | did not expect an alert, but found an alert for PrototypePollutingAssignment | OK - 'object' is not Object.prototype itself (but possibly a copy) | PrototypePollutingAssignment |
2+
| query-tests/Security/CWE-915/PrototypePollutingAssignment/tst.js:124 | did not expect an alert, but found an alert for PrototypePollutingAssignment | OK - 'dest' is not Object.prototype itself (but possibly a copy) | PrototypePollutingAssignment |

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,26 @@ nodes
190190
| tst.js:105:5:105:17 | object[taint] |
191191
| tst.js:105:5:105:17 | object[taint] |
192192
| tst.js:105:12:105:16 | taint |
193+
| tst.js:116:9:116:38 | taint |
194+
| tst.js:116:17:116:38 | String( ... y.data) |
195+
| tst.js:116:24:116:37 | req.query.data |
196+
| tst.js:116:24:116:37 | req.query.data |
197+
| tst.js:119:9:119:51 | object |
198+
| tst.js:119:18:119:51 | Object. ... taint]) |
199+
| tst.js:119:32:119:33 | {} |
200+
| tst.js:119:32:119:33 | {} |
201+
| tst.js:119:36:119:50 | plainObj[taint] |
202+
| tst.js:119:45:119:49 | taint |
203+
| tst.js:120:5:120:10 | object |
204+
| tst.js:120:5:120:10 | object |
205+
| tst.js:122:9:122:17 | dest |
206+
| tst.js:122:16:122:17 | {} |
207+
| tst.js:123:19:123:22 | dest |
208+
| tst.js:123:19:123:22 | dest |
209+
| tst.js:123:25:123:39 | plainObj[taint] |
210+
| tst.js:123:34:123:38 | taint |
211+
| tst.js:124:5:124:8 | dest |
212+
| tst.js:124:5:124:8 | dest |
193213
edges
194214
| lib.js:1:38:1:40 | obj | lib.js:6:7:6:9 | obj |
195215
| lib.js:1:38:1:40 | obj | lib.js:6:7:6:9 | obj |
@@ -366,6 +386,26 @@ edges
366386
| tst.js:102:24:102:37 | req.query.data | tst.js:102:17:102:38 | String( ... y.data) |
367387
| tst.js:105:12:105:16 | taint | tst.js:105:5:105:17 | object[taint] |
368388
| tst.js:105:12:105:16 | taint | tst.js:105:5:105:17 | object[taint] |
389+
| tst.js:116:9:116:38 | taint | tst.js:119:45:119:49 | taint |
390+
| tst.js:116:9:116:38 | taint | tst.js:123:34:123:38 | taint |
391+
| tst.js:116:17:116:38 | String( ... y.data) | tst.js:116:9:116:38 | taint |
392+
| tst.js:116:24:116:37 | req.query.data | tst.js:116:17:116:38 | String( ... y.data) |
393+
| tst.js:116:24:116:37 | req.query.data | tst.js:116:17:116:38 | String( ... y.data) |
394+
| tst.js:119:9:119:51 | object | tst.js:120:5:120:10 | object |
395+
| tst.js:119:9:119:51 | object | tst.js:120:5:120:10 | object |
396+
| tst.js:119:18:119:51 | Object. ... taint]) | tst.js:119:9:119:51 | object |
397+
| tst.js:119:32:119:33 | {} | tst.js:119:18:119:51 | Object. ... taint]) |
398+
| tst.js:119:36:119:50 | plainObj[taint] | tst.js:119:18:119:51 | Object. ... taint]) |
399+
| tst.js:119:36:119:50 | plainObj[taint] | tst.js:119:32:119:33 | {} |
400+
| tst.js:119:36:119:50 | plainObj[taint] | tst.js:119:32:119:33 | {} |
401+
| tst.js:119:45:119:49 | taint | tst.js:119:36:119:50 | plainObj[taint] |
402+
| tst.js:122:9:122:17 | dest | tst.js:123:19:123:22 | dest |
403+
| tst.js:122:9:122:17 | dest | tst.js:123:19:123:22 | dest |
404+
| tst.js:122:9:122:17 | dest | tst.js:124:5:124:8 | dest |
405+
| tst.js:122:9:122:17 | dest | tst.js:124:5:124:8 | dest |
406+
| tst.js:122:16:122:17 | {} | tst.js:122:9:122:17 | dest |
407+
| tst.js:123:25:123:39 | plainObj[taint] | tst.js:122:16:122:17 | {} |
408+
| tst.js:123:34:123:38 | taint | tst.js:123:25:123:39 | plainObj[taint] |
369409
#select
370410
| 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 | library input |
371411
| lib.js:15:3:15:14 | obj[path[0]] | lib.js:14:38:14:41 | path | lib.js:15:3:15:14 | obj[path[0]] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | lib.js:14:38:14:41 | path | library input |
@@ -394,3 +434,7 @@ edges
394434
| tst.js:94:5:94:37 | obj[req ... ', '')] | tst.js:94:9:94:19 | req.query.x | tst.js:94:5:94:37 | obj[req ... ', '')] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:94:9:94:19 | req.query.x | user controlled input |
395435
| tst.js:97:5:97:46 | obj[req ... g, '')] | tst.js:97:9:97:19 | req.query.x | tst.js:97:5:97:46 | obj[req ... g, '')] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:97:9:97:19 | req.query.x | user controlled input |
396436
| tst.js:105:5:105:17 | object[taint] | tst.js:102:24:102:37 | req.query.data | tst.js:105:5:105:17 | object[taint] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:102:24:102:37 | req.query.data | user controlled input |
437+
| tst.js:119:32:119:33 | {} | tst.js:116:24:116:37 | req.query.data | tst.js:119:32:119:33 | {} | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:116:24:116:37 | req.query.data | user controlled input |
438+
| tst.js:120:5:120:10 | object | tst.js:116:24:116:37 | req.query.data | tst.js:120:5:120:10 | object | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:116:24:116:37 | req.query.data | user controlled input |
439+
| tst.js:123:19:123:22 | dest | tst.js:116:24:116:37 | req.query.data | tst.js:123:19:123:22 | dest | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:116:24:116:37 | req.query.data | user controlled input |
440+
| tst.js:124:5:124:8 | dest | tst.js:116:24:116:37 | req.query.data | tst.js:124:5:124:8 | dest | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:116:24:116:37 | req.query.data | user controlled input |

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,23 @@ app.get('/bar', (req, res) => {
103103

104104
let object = {};
105105
object[taint][taint] = taint; // NOT OK
106-
106+
107107
const bad = ["__proto__", "constructor"];
108108
if (bad.includes(taint)) {
109109
return;
110110
}
111111

112112
object[taint][taint] = taint; // OK
113-
});
113+
});
114+
115+
app.get('/assign', (req, res) => {
116+
let taint = String(req.query.data);
117+
let plainObj = {};
118+
119+
let object = Object.assign({}, plainObj[taint]);
120+
object[taint] = taint; // OK - 'object' is not Object.prototype itself (but possibly a copy)
121+
122+
let dest = {};
123+
Object.assign(dest, plainObj[taint]);
124+
dest[taint] = taint; // OK - 'dest' is not Object.prototype itself (but possibly a copy)
125+
});

0 commit comments

Comments
 (0)