Prototype pollution attack (smart-extend)
The deep copy function in the smart-extend npm package recursively merges user-supplied JSON without blocking the special __proto__ key, so a crafted object can add properties to Object.prototype. An attacker could then pollute every object in the running process, which the reporter says may lead to denial of service or remote code execution in some cases.
- Triaged in 26 hours
- Fixed in 4 months
- Disclosed after 5 months
Hi team, I would like to report a prototype pollution vulnerability in smart-extend that allows an attacker to inject properties on Object.prototype.
Module
module name: smart-extend
version: 1.7.3
npm page: https://www.npmjs.com/package/smart-extend
Module Description
smart-extend is an extension to jQuery's classic extend() method with additional features providing you with more power and control over your object extensions/clones. Works in both Node.JS and the browser.
Module Stats
40.948 downloads in the last week
Vulnerability
Vulnerability Description
this vulnerability type is similar the report of Olivier #310443 only
deepfunction is vulnerable when it performs a recursive copy of the specified objects.
Steps To Reproduce:
In the following code snippet, "payload" would come from user-input (JSON data)
var extend = require('smart-extend');
var payload = '{"__proto__":{"polluted":"deep_done !"}}';
var test = {};
console.log("Before: ", test.polluted);
extend.deep({},JSON.parse(payload));
console.log("After: ", test.polluted);
get results:
Before: undefined
After: deep_done !
Wrap up
Select Y or N for the following statements:
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Thanks!
Impact
It causes Denial of Service or RCE in some cases.
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 copies keys from the parsed input, including __proto__, straight onto the target object instead of skipping or sanitising dangerous property names.
Impact
The reporter claims it causes denial of service or, in some cases, remote code execution, though no exploitation beyond the pollution itself is demonstrated.
What the attacker needed
Attacker-controlled JSON reaches extend.deep; application uses smart-extend 1.7.3
How it was found
- Require the smart-extend module in a Node.js script.
- Build a JSON payload whose __proto__ key holds the property to inject, as if it came from user input.
- Parse the payload and pass it to the deep extend function with an empty target object.
- Read the injected property from a separate, untouched object to confirm it was polluted.
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 program copies user data into an object without filtering the special key __proto__, the attacker can change those shared defaults, so every object in the program suddenly has extra properties. That is called prototype pollution, and it can break the application or, in some setups, be turned into code execution.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.