[plain-object-merge] Prototype pollution
The merge function in the plain-object-merge npm package copies a __proto__ key from attacker-supplied input onto Object.prototype, so every object in the process gains the injected property. Depending on how the host application uses objects, this could lead to denial of service, property injection or remote code execution.
- Triaged in 2 hours
- Fixed in 9 months
- Disclosed after 10 months
I would like to report a prototype pollution vulnerability in plain-object-merge module.
It allows an attacker to inject properties on Object.prototype.
Module
module name: plain-object-merge
version: 1.0.1
npm page: https://www.npmjs.com/package/plain-object-merge
Module Description
Extremely fast function optimized for deep merging json-serializable plain objects.
Module Stats
[20] 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
plain-object-mergemodule:npm i plain-object-merge
Create an object with __proto__ property and pass it to the merge function:
const merge = require('plain-object-merge');
const payload = JSON.parse('{"__proto__":{"polluted":"yes"}}');
const obj = {};
console.log("Before : " + obj.polluted);
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
Likely the merge routine recursed into the __proto__ key of the input object instead of skipping or blocking it, letting the write reach Object.prototype.
Impact
The impact depends on the host application; the reporter states it may be possible to achieve denial of service, remote code execution or property injection.
What the attacker needed
Attacker-controlled input reaches merge; application uses the library on untrusted data
How it was found
- Install the plain-object-merge package.
- Build an input object that contains a __proto__ key with a nested property.
- Call merge with an empty object and that input.
- Observe that a separate, unrelated object now exposes the injected property.
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 template called the prototype. If a library copies a special key named __proto__ from untrusted input, it can add new defaults to that shared template, so every object in the program suddenly has the extra property. Here a small merge helper did exactly that, and the reporter showed a plain object gaining a 'polluted' value after the merge.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.