Skip to content

Commit bb384fd

Browse files
committed
JS: Added test cases which cover new RegExp creation with replace on protytpe pulluting
1 parent aab0f6a commit bb384fd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ 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:130:5:130:53 | obj[req ... ), '')] |
194+
| tst.js:130:5:130:53 | obj[req ... ), '')] |
195+
| tst.js:130:9:130:19 | req.query.x |
196+
| tst.js:130:9:130:19 | req.query.x |
197+
| tst.js:130:9:130:52 | req.que ... '), '') |
198+
| tst.js:131:5:131:65 | obj[req ... ), '')] |
199+
| tst.js:131:5:131:65 | obj[req ... ), '')] |
200+
| tst.js:131:9:131:19 | req.query.x |
201+
| tst.js:131:9:131:19 | req.query.x |
202+
| tst.js:131:9:131:64 | req.que ... )), '') |
193203
edges
194204
| lib.js:1:38:1:40 | obj | lib.js:6:7:6:9 | obj |
195205
| lib.js:1:38:1:40 | obj | lib.js:6:7:6:9 | obj |
@@ -366,6 +376,14 @@ edges
366376
| tst.js:102:24:102:37 | req.query.data | tst.js:102:17:102:38 | String( ... y.data) |
367377
| tst.js:105:12:105:16 | taint | tst.js:105:5:105:17 | object[taint] |
368378
| tst.js:105:12:105:16 | taint | tst.js:105:5:105:17 | object[taint] |
379+
| tst.js:130:9:130:19 | req.query.x | tst.js:130:9:130:52 | req.que ... '), '') |
380+
| tst.js:130:9:130:19 | req.query.x | tst.js:130:9:130:52 | req.que ... '), '') |
381+
| tst.js:130:9:130:52 | req.que ... '), '') | tst.js:130:5:130:53 | obj[req ... ), '')] |
382+
| tst.js:130:9:130:52 | req.que ... '), '') | tst.js:130:5:130:53 | obj[req ... ), '')] |
383+
| tst.js:131:9:131:19 | req.query.x | tst.js:131:9:131:64 | req.que ... )), '') |
384+
| tst.js:131:9:131:19 | req.query.x | tst.js:131:9:131:64 | req.que ... )), '') |
385+
| tst.js:131:9:131:64 | req.que ... )), '') | tst.js:131:5:131:65 | obj[req ... ), '')] |
386+
| tst.js:131:9:131:64 | req.que ... )), '') | tst.js:131:5:131:65 | obj[req ... ), '')] |
369387
#select
370388
| 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 |
371389
| 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 +412,5 @@ edges
394412
| 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 |
395413
| 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 |
396414
| 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 |
415+
| tst.js:130:5:130:53 | obj[req ... ), '')] | tst.js:130:9:130:19 | req.query.x | tst.js:130:5:130:53 | obj[req ... ), '')] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:130:9:130:19 | req.query.x | user controlled input |
416+
| tst.js:131:5:131:65 | obj[req ... ), '')] | tst.js:131:9:131:19 | req.query.x | tst.js:131:5:131:65 | obj[req ... ), '')] | This assignment may alter Object.prototype if a malicious '__proto__' string is injected from $@. | tst.js:131:9:131:19 | req.query.x | user controlled input |

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,10 @@ app.get('/assign', (req, res) => {
123123
Object.assign(dest, plainObj[taint]);
124124
dest[taint] = taint; // OK - 'dest' is not Object.prototype itself (but possibly a copy)
125125
});
126+
127+
app.get('/foo', (req, res) => {
128+
let obj = {};
129+
obj[req.query.x.replace(new RegExp('_', 'g'), '')].x = 'foo'; // OK
130+
obj[req.query.x.replace(new RegExp('_', ''), '')].x = 'foo'; // NOT OK
131+
obj[req.query.x.replace(new RegExp('_', unknownFlags()), '')].x = 'foo'; // OK -- Might be okay but it is currently flagged as a problem
132+
});

0 commit comments

Comments
 (0)