Skip to content

Commit 57858af

Browse files
authored
Merge pull request github#13165 from erik-krogh/proto-assign-qhelp
JS: fixup in the qhelp for `js/prototype-polluting-assignment`
2 parents 1a9bd9c + 2ebce99 commit 57858af

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<p>
3636
In the example below, the untrusted value <code>req.params.id</code> is used as the property name
3737
<code>req.session.todos[id]</code>. If a malicious user passes in the ID value <code>__proto__</code>,
38-
the variable <code>todo</code> will then refer to <code>Object.prototype</code>.
39-
Finally, the modification of <code>todo</code> then allows the attacker to inject arbitrary properties
38+
the variable <code>items</code> will then refer to <code>Object.prototype</code>.
39+
Finally, the modification of <code>items</code> then allows the attacker to inject arbitrary properties
4040
onto <code>Object.prototype</code>.
4141
</p>
4242

@@ -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)