GHSL-2020-160: Prototype pollution in Merge-deep
The merge-deep library attempted to block prototype pollution by preventing merges into __proto__, but still allowed pollution of Object.prototype via a constructor payload. An attacker could set properties on Object.prototype, which are then inherited by all objects, potentially leading to denial of service or remote code execution depending on the application.
Originally disclosed on GitHub Security Lab
Merge-deep actively attempts to prevent prototype pollution by blocking object property merges into proto, however it still allows for prototype pollution of Object.prototype via a constructor payload.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
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 library's protection only blocked direct merges into __proto__, but did not block merges into constructor.prototype, allowing prototype pollution.
Impact
Depending on the application, this could lead to denial of service or remote code execution, though the code snippet throws an exception that might make exploitation difficult in some settings.
What the attacker needed
Attacker controls input to merge-deep
The fix
The vulnerability was fixed in version 3.0.3 released to npm.
How it was found
- Require the merge-deep library.
- Provide a payload that contains a constructor property with a prototype object.
- Call mergeDeep with an empty object and the parsed payload.
- Observe that Object.prototype.isAdmin becomes true.
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 JavaScript bug where an attacker can add or change properties on a base object that many other objects inherit from. In this case, the merge-deep library tried to stop this by blocking one way to reach that base object, but another way (using a 'constructor' property) still worked. This means an attacker could make every object in the program think it has a property like 'isAdmin' set to true, which might bypass security checks.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.