Prototype Pollution
Affects Node.js
Prototype pollution happens at some unsafe merge
, clone
, extend
and path assignment
operations on malicious JSON
objects.
This is exploitable only if any of the following three happens:
Object recursive merge
Property definition by path
Object clone
Some of the most popular libraries being affected are
lodash
andHoek
Templates
are a good target for prototype pollution.
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:
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
orFunction.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:
Last updated