Packages / mongoose / Security
Mongoose: Prototype pollution in mongoose update casting via __proto__-prefixed dotted path (Schema._getSchema/path getter)
Affected releases · mongoose
- 9.x9.0.0 – 9.7.1Fixed in 9.7.2
- 8.x8.0.0 – 8.24.0Fixed in 8.24.1
- 7.x7.0.0 – 7.8.9Fixed in 7.8.10
- 6.x6.0.0 – 6.13.9Fixed in 6.13.10
- 5.x and older0.0.1 – 5.13.23No fix, no longer updated
On 9.x, the newest line:
npm install mongoose@9.7.2Every release on a timeline
Affected
9.0.0 – 9.7.1
28 releases
Fixed
9.7.2 – 9.11.4
21 releases, latest
Affected
8.0.0 – 8.24.0
102 releases
Fixed
8.24.1 – 8.24.7
7 releases
Affected
7.0.0 – 7.8.9
55 releases
Fixed
7.8.10 – 7.8.13
4 releases
Affected
6.0.0 – 6.13.9
119 releases
Fixed
6.13.10 – 6.13.12
3 releases
Affected
5.0.0 – 5.13.23
255 releases
Affected
4.0.0 – 4.13.21
164 releases
Affected
3.0.0 – 3.9.7
104 releases
Affected
2.0.0 – 2.9.10
84 releases
Affected
1.0.0 – 1.8.4
64 releases
Affected
0.0.1 – 0.0.6
6 releases
What happens
Impact
What kind of vulnerability is it? Who is impacted?
Prototype pollution in update casting: passing a user-controlled update to a Mongoose update, like MyModel.updateOne(filter, req.body), can cause Mongoose to set $fullPath and $parentSchemaDocArray on Object.prototype.
Example:
const mongoose = require('mongoose');
console.log('before:', Object.prototype.$fullPath); // undefined
const User = mongoose.model('User', new mongoose.Schema({ name: String }));
const malicious = JSON.parse('{"$set": {"__proto__.x": "anything"}}'); // attacker-controlled update
const q = User.updateOne({}, {});
try { q._castUpdate(malicious); } catch (e) { /* throws AFTER the pollution side-effect */ }
console.log('after :', Object.prototype.$fullPath); // "__proto__"
console.log('enumerable:', Object.prototype.propertyIsEnumerable('$fullPath')); // true
console.log('fresh {}:', ({}).$fullPath); // "__proto__"Patches
Has the problem been patched? What versions should users upgrade to?
9.7.2, 8.24.1. 7.8.10, 6.13.10
Workarounds
Is there a way for users to fix or remediate the vulnerability without upgrading?
Check user-controlled updates for own __proto__ properties before passing to Mongoose
References
Are there any links users can visit to find out more?