Prototype pollution attack (defaults-deep / constructor.prototype)
The defaults-deep npm package recursively copies properties from a user-supplied object into a target without blocking the special constructor.prototype path. An attacker can therefore add or change properties on Object.prototype, which then appear on every object in the process.
- Triaged in 24 hours
- Fixed in 48 days
- Disclosed after 3 months
Summary by the program
The vulnerability was reported and verified. The package maintainer joined the report but never participated or published a patch. After 45+ days the report was disclosed.
The report
I would like to report a prototype pollution vulnerability in defaults-deep. It allows an attacker to inject properties on Object.prototype.
Module
module name: defaults-deep
version: 0.2.4
npm page: https://www.npmjs.com/package/defaults-deep
Module Description
Like extend but recursively copies only the missing properties/values to the target object.
Module Stats
6,659 downloads in the last week
Vulnerability
Vulnerability Description
This is a variant of this vulnerability: https://hackerone.com/reports/310443
The defaults-deep package 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 {constructor: {prototype: {...}}} and send it to defaults-deep:
var defaultsDeep = require('defaults-deep');
var payload = JSON.parse('{"constructor": {"prototype": {"isAdmin": true}}}');
defaultsDeep({}, 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 recursive merge routine did not block the constructor.prototype key path, so a nested object could write onto Object.prototype.
Impact
Denial of service is possible, and the effect could be worse depending on how the application uses the polluted properties.
What the attacker needed
Application passes attacker-controlled object to…
How it was found
- Load the defaults-deep module.
- Build an object whose constructor.prototype holds a property such as isAdmin.
- Pass that object to defaultsDeep with an empty target.
- Observe that the property now exists on a plain empty object.
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 properties from a common parent called the prototype. If an attacker can add a property to that shared parent, every object in the program suddenly has it, which can confuse the application or crash it. This package copied nested settings without checking for the special constructor.prototype path, so a crafted input could reach the shared parent.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.