Prototype Pollution Vulnerability in mpath Package
The mpath library lets a caller pass a path containing the prototype object, so setting a value writes onto Object.prototype instead of the intended object. An attacker who controls the path could add or overwrite properties that every object in the process then inherits.
Originally disclosed on HackerOne
- Disclosed after 4 months
I would like to report prototype pollution vulnerability in mpath. It allows an attacker to inject arbitrary properties on Object.prototype.
Module
module name: mpath
version: 0.4.1
npm page: https://www.npmjs.com/package/mpath
Module Description
{G,S}et javascript object values using MongoDB-like path notatio
Module Stats
305,874 downloads in the last week
Vulnerability
Vulnerability Description
An attacker can specify a path that include the prototype object, and thus overwrite important properties on Object.prototype or add new ones.
Steps To Reproduce:
var mpath = require("mpath");
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.set('__proto__.x', ['hilarious', 'fruity'], obj);
console.log({}.x);
Patch
N/A validate property names before overwriting them and prevent write to certain paths.
Wrap up
- I contacted the maintainer to let them know: [N
- I opened an issue in the related repository: N
Impact
This may be an intended behaviour of this module, but it needs to be better documented. Moreover, to properly analyse the impact of this vulnerability one must look at the clients of this module, such as mongoose and see if attackers can realistically control the path value.
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 path setter did not reject or sanitise the special prototype key, so a path segment could reach Object.prototype.
Impact
Any property on Object.prototype could be added or overwritten, though the reporter notes the real-world impact depends on whether clients such as mongoose let attackers control the path value.
What the attacker needed
Attacker controls the path passed to set
How it was found
- Load the mpath module and create a sample object with a nested array.
- Call the set function with a path that names the prototype object and a value.
- Read the same property from a fresh empty object to see the injected value.
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 parent object called a prototype. If a library lets someone write into that shared parent, the change shows up on every object in the program, which can confuse or break other code. Here the library that reads dotted paths did not block the special name for that parent.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.