Last updated
Last updated
The most straightforward example of prototype pollution involves injecting the __proto__
property, which affects all objects that inherit from Object.prototype
.
This example adds the isUserAdmin
property to the prototype chain:
Also, you can directly manipulate the Object.prototype
by modifying the __proto__
property. This could be done in objects passed to vulnerable code:
If the application allows you to define properties via paths (e.g., obj.a.b
):
The constructor
property is part of the prototype chain for JavaScript objects:
The hasOwnProperty
method is often used to check if an object has a property, but it can be overridden in the prototype:
If an attacker can manipulate built-in objects' prototypes (like Array.prototype
or Function.prototype
), they could affect the behavior of all instances of those types:
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:
You can directly inject properties into the prototype of custom classes or objects:
Affects Node.js