Prototype pollution attack (defaults-deep)
The defaults-deep library merges attacker-controlled JSON into an object without blocking the special __proto__ key, so a crafted payload can add or change properties on every object in the Node.js process. This lets an attacker at least crash the server or make it return errors on every request, and the report says remote code execution may be possible with more complex payloads.
- Triaged in 4 hours
- Fixed in 12 days
- Disclosed after 16 days
As discussed in #309391, here's the separate report for each of the library. This one is the information for the defaults-deep library.
Module:
https://www.npmjs.com/package/defaults-deep
Summary:
Utilities function in all the listed modules can be tricked into modifying the prototype of "Object" when the attacker control part of the structure passed to these function. This can let an attacker add or modify existing property that will exist on all object.
Description:
Steps To Reproduce:
The simplest test case to reproduce the issue is the following code snippet. In the code snippet, "malicious_payload" would come from an endpoint which accepts JSON data.
var defaults-deep = require('defaults-deep'); var malicious_payload = '{"__proto__":{"oops":"It works !"}}';
var a = {}; console.log("Before : " + a.oops); defaults-deep({}, JSON.parse(malicious_payload)); console.log("After : " + a.oops);
This shows that an attacker can add attributes to all existing object on the server. Additional attribute can be used to change the execution code flow or cause error on every subsequent request by replacing "toString" or "valueOf".
Impact
This vulnerability is garanteed to at least obtain denial of service as all the library allow the property "toString" and "valueOf" to be replaced by a "String". This breaks the express module and forces the server to either crash or return a 500 to every subsequent request.
More complex payload can be crafted to gain remote code execution (see PoC in #309391).
Supporting Material/References:
If extra information is needed don't hesitate to ask.
Impact
Variable. Server crash or the server becoming unable to respond to all request is guaranteed, but more significant impact like remote code execution can be achieved in some cases.
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 deep-merge routine in defaults-deep did not reject or skip the special __proto__ key, so a nested key in attacker-supplied JSON was written onto Object.prototype.
Impact
The report states that denial of service is guaranteed because toString and valueOf can be replaced, breaking Express and making the server crash or return 500 to every later request, while remote code execution may be possible with more complex payloads.
What the attacker needed
Attacker controls JSON passed to defaults-deep; server runs Node.js with the library
How it was found
- Load the defaults-deep library in a Node.js program.
- Build a JSON payload whose nested key is the special prototype key.
- Parse the JSON and pass it to defaults-deep together with an empty object.
- Observe that a fresh object now has the property added by the payload.
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.
In JavaScript, every object inherits shared properties from a parent object called its prototype. If a program copies data from a user into an object without checking special key names, the user can change that shared parent, so the change appears on every object in the program. Here the library defaults-deep did not block the special key that points at the prototype, so a user-supplied JSON value could alter all objects.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.