프로토타입 오염 (Prototype Pollution) - Object assignment
Prototype Pollution
Last updated
Prototype Pollution
Last updated
app.get('/test/:id', (req, res) => {
let id = req.params.id;
let items = req.session.todos[id];
if (!items) {
items = req.session.todos[id] = {};
}
// 위험: 외부 입력으로 바로 키를 사용
items[req.query.name] = req.query.text;
res.end(200);
});app.get('/test/:id', (req, res) => {
let id = req.params.id;
let items = req.session.todos[id];
if (!items) {
items = req.session.todos[id] = {};
}
const forbiddenKeys = ['__proto__', 'constructor', 'prototype'];
if (!forbiddenKeys.includes(req.query.name)) {
items[req.query.name] = req.query.text;
} else {
res.status(400).send('Invalid key name');
return;
}
res.end(200);
});