The Quirks of JavaScript Prototypes
In JavaScript, inheritance is prototype-based. Almost every object in JavaScript inherits properties from the root `Object.prototype`.
If an application accepts arbitrary JSON payloads (e.g. user profile updates) and merges them into an existing object using an un-sanitized recursive function, an attacker can submit:
{
"__proto__": {
"isAdmin": true
}
}When the recursive function encounters `__proto__`, it modifies the global prototype itself.
Now, examine what happens when an ordinary, unprivileged customer logs in:
const user = await getUser(userId); // Normal customer
if (user.isAdmin) {
// Evaluates to TRUE because isAdmin was injected into Object.prototype!
renderAdminPanel();
}Every single object in the Node.js process now possesses `isAdmin: true`, instantly escalating all visitors into administrative superusers! In extreme cases, prototype pollution can be chained to achieve Remote Code Execution (RCE) via Node.js `child_process` forks.