CVE-2022-24304 is a critical-severity (CVSS 9.8) remote code execution vulnerability in mongoose. A fix is available for mongoose — see the affected versions and patch details below.
Mongoose Vulnerable to Prototype Pollution in Schema Object
Real-World Exposure
mongoose📦mongooseReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects npm packages — download data is not available via public APIs for these ecosystems.
Description
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.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | mongoose | ≥ 6.0.0&&< 6.4.6 | 6.4.6npm install mongoose@6.4.6 |
| 📦npm | mongoose | all versions | 5.13.15npm install mongoose@5.13.15 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for mongoose, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update mongoose to 6.4.6 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2022-24304 is resolved across your whole dependency graph.
Workarounds
Cap what an attacker can consume: apply request size, rate and timeout limits in front of the affected component, and run it with memory and CPU limits so exhaustion degrades one worker rather than the whole service.
Frequently Asked Questions
Is CVE-2022-24304 in your dependencies?
Find it across npm, including transitive dependencies.