Prototype Pollution Vulnerability in cached-path-relative Package
The cached-path-relative package used a plain object as its memoisation cache, so a key of __proto__ caused writes to land on Object.prototype. An attacker who controls both arguments could add arbitrary properties that every JavaScript object then inherits.
Originally disclosed on HackerOne
- Triaged in 26 days
- Fixed in 3 months
- Disclosed after 3 months
I would like to report a prototype pollution attack in cached-path-relative. It allows an attacker to inject properties on Object.prototype which are then inherited by all the JS objects through the prototype chain.
Module
module name: cached-path-relative
version: 1.0.1
npm page: https://www.npmjs.com/package/cached-path-relative
Module Description
Memoize the results of the path.relative function. path.relative can be an expensive operation if it happens a lot, and its results shouldn't change for the same arguments.
Module Stats
352,446 downloads in the last week
Vulnerability
Vulnerability Description
If the attacker can control both the path and the cached value, she can deploy a prototype pollution attack and thus overwrite arbitrary properties on Object.prototype.
Steps To Reproduce:
var relative = require('cached-path-relative');
relative('__proto__', 'x');
console.log({}.x);
Patch
Initialize the cache using Object.create(null) or use the Map data structure.
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
I am not sure how clients of this module use the API, but if attacker can control both the values passed to cached-path-relative, the attacker can write arbitrary properties on Object.prototype.
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 cache was a normal object, so a __proto__ key was treated as a reference to Object.prototype rather than as an ordinary entry.
Impact
If an attacker can control both arguments, they could write arbitrary properties onto Object.prototype, though the report does not show a concrete downstream exploit.
What the attacker needed
Attacker controls both arguments; application uses the package
How it was found
- Load the cached-path-relative module.
- Call it with __proto__ as the first argument and a value as the second.
- Read the property from a fresh empty object to see the pollution.
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 hidden parent object called the prototype. If a program lets user input become a property name on that shared parent, every object in the program gains that property, which can change how the code behaves. Here a small caching library did exactly that when given a special key.
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.