[objtools] Prototype pollution
The merge function in the objtools 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 4 months
- Disclosed after 4 months
I would like to report a prototype pollution vulnerability in objtools module.
It allows an attacker to inject properties on Object.prototype.
Module
module name: objtools
version: 2.0.1
npm page: https://www.npmjs.com/package/objtools
Module Description
objtools provides several utility functions for working with structured objects. Basic examples of how to use are provided below. See the docs directory for full information.
Module Stats
[30] 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
objtoolsmodule:npm i objtools
Create an object with __proto__ property and pass it to the merge function:
const objtools = require('objtools');
const payload = JSON.parse('{"__proto__":{"polluted":"yes"}}');
let obj = {};
console.log("Before : " + obj.polluted);
objtools.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
The merge function copies a __proto__ key from input onto Object.prototype rather than only the target object.
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 objtools package
How it was found
- Install the objtools module with npm.
- Build an object from JSON that contains a __proto__ key holding a property to inject.
- Call objtools.merge with an empty target object and that crafted object.
- Observe that a fresh unrelated object now shows 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 object called Object.prototype. If a library copies a special key named __proto__ from untrusted input, it can add new defaults that every object in the program then sees. Here the merge helper did exactly that, so a crafted object quietly changed behaviour across the whole application.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.