Skip to content

Commit 2ebce99

Browse files
committed
add another example of how to fix the prototype pollution issue
1 parent 7a338c4 commit 2ebce99

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

javascript/ql/src/Security/CWE-915/PrototypePollutingAssignment.inc.qhelp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
</p>
4949

5050
<sample src="examples/PrototypePollutingAssignmentFixed.js"/>
51+
52+
<p>
53+
Another way to fix it is to prevent the <code>__proto__</code> property from being used as a key, as shown below:
54+
</p>
55+
56+
<sample src="examples/PrototypePollutingAssignmentFixed2.js"/>
5157

5258
</example>
5359

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let express = require('express');
2+
let app = express()
3+
4+
app.put('/todos/:id', (req, res) => {
5+
let id = req.params.id;
6+
if (id === '__proto__' || id === 'constructor' || id === 'prototype') {
7+
res.end(403);
8+
return;
9+
}
10+
let items = req.session.todos[id];
11+
if (!items) {
12+
items = req.session.todos[id] = {};
13+
}
14+
items[req.query.name] = req.query.text;
15+
res.end(200);
16+
});

0 commit comments

Comments
 (0)