The most frequent functions that leads to Prototype Pollution
Unsanatized assigning object properities
const car = Object.assign({}, userInput);{
"brand": "Mercedes",
"model": "CLA AMG 45s",
__proto__: {
evilProperty: "payload"
}
}const userInput = {
brand: "Mercedes",
model: "CLA AMG 45s",
__proto__: {
evilProperty: "payload"
}
};
// Insecure: directly using Object.assign()
const car = Object.assign({}, userInput);
console.log(car.brand); // "Mercedes"
console.log(car.model); // "CLA AMG 45s"
console.log(car.evilProperty); // undefined
// BUT here's the danger:
console.log({}.evilProperty); // "payload" ⚠️ -> Prototype Pollution happenedMerging objects
aaa
Last updated