mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
add another example of how to fix the prototype pollution issue
This commit is contained in:
@@ -48,6 +48,12 @@
|
||||
</p>
|
||||
|
||||
<sample src="examples/PrototypePollutingAssignmentFixed.js"/>
|
||||
|
||||
<p>
|
||||
Another way to fix it is to prevent the <code>__proto__</code> property from being used as a key, as shown below:
|
||||
</p>
|
||||
|
||||
<sample src="examples/PrototypePollutingAssignmentFixed2.js"/>
|
||||
|
||||
</example>
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
let express = require('express');
|
||||
let app = express()
|
||||
|
||||
app.put('/todos/:id', (req, res) => {
|
||||
let id = req.params.id;
|
||||
if (id === '__proto__' || id === 'constructor' || id === 'prototype') {
|
||||
res.end(403);
|
||||
return;
|
||||
}
|
||||
let items = req.session.todos[id];
|
||||
if (!items) {
|
||||
items = req.session.todos[id] = {};
|
||||
}
|
||||
items[req.query.name] = req.query.text;
|
||||
res.end(200);
|
||||
});
|
||||
Reference in New Issue
Block a user