Skip to content
Prototype pollution Disclosed report Intermediate CVE-2018-16486

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.

asgerf Follow

Originally disclosed on HackerOne

Medium 6.1 View original
  • 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:

JavaScript
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

The original report as published on HackerOne, by asgerf. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Load the defaults-deep module.
  2. Build an object whose constructor.prototype holds a property such as isAdmin.
  3. Pass that object to defaultsDeep with an empty target.
  4. 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.

More by asgerf

View all

7 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Prototype pollution

The lesson behind this report.

Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.