Prototype pollution attack (extend)
The extend library's deep-merge function could be tricked into copying a __proto__ key from attacker-supplied input onto Object.prototype. An attacker could then set properties that appear on every object in the application, which the report says may cause denial of service and possibly more.
- Triaged in 3 days
- Fixed in 7 days
- Disclosed after 40 days
I would like to report prototype pollution in extend It allows an attacker to inject properties on Object.prototype.
Module
module name: extend
version: 3.0.1
npm page: https://www.npmjs.com/package/extend
Module Description
node-extend is a port of the classic extend() method from jQuery. It behaves as you expect. It is simple, tried and true.
Note: The github project is called
node-extendbut the NPM package is justextend
Module Stats
7M downloads in the last week
Vulnerability
Vulnerability Description
This is a variant of this vulnerability: https://hackerone.com/reports/310443
The extend function can be tricked into adding or modifying properties of the Object prototype. These properties will be present on all objects.
Steps To Reproduce:
Craft an object of form {__proto__: {...}} and send it to extend(true, {}, ...).
let extend = require('extend');
let payload = JSON.parse('{"__proto__": {"isAdmin": true}}');
extend(true, {}, payload);
console.log({}.isAdmin); // true
Wrap up
- I contacted the maintainer to let them know: [N]
- I opened an issue in the related repository: [N]
Impact
Denial of service, possibly more depending on the application. See https://hackerone.com/reports/310443
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the deep-merge routine did not block the __proto__ key, so it recursed into it and wrote attacker-controlled properties onto Object.prototype.
Impact
The report states denial of service and possibly more depending on the application, since polluted prototype properties affect all objects.
What the attacker needed
Application passes attacker-controlled object to extend; deep merge mode is used
How it was found
- Load the extend module in a Node.js script.
- Parse a JSON object that contains a __proto__ key holding another object.
- Call extend in deep mode with an empty target and the parsed object as the source.
- Read a property from a fresh empty object and observe the injected value.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
JavaScript objects inherit shared defaults from a built-in object called Object.prototype. If a library copies a special key named __proto__ from user input, it can add new defaults that every object in the program then sees. Here that meant a value like isAdmin could suddenly appear on an empty object, which can break logic or crash things.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.