CVE-2022-2564: Prototype Pollution in mongoose
Summary
CVE-2022-2564: automattic/mongoose vulnerable to Prototype pollution via Schema.path. Affects mongoose across 2 version ranges.
< 5.13.15
>= 6.0.0, < 6.4.6
Fixed in 5.13.15 or 6.4.6, depending on the release line you run. How to fix ↓
Also tracked for
- mongoose · Bitnami
The same CVE-2022-2564 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
Mongoose is an object modeling tool for MongoDB designed to work in an asynchronous environment. It provides a schema-based solution for modeling application data. The vulnerability affects versions 0 to 5.13.15 and 6.0.0 to 6.4.6 of the mongoose package. Mongoose's Schema.path() function is vulnerable to prototype pollution when setting the schema object. This vulnerability allows an attacker to modify the Object prototype, potentially leading to a Denial of Service (DoS) attack.
Vulnerability Detail
The vulnerability in mongoose arises from the insecure handling of the Schema.path() function. By manipulating the schema object, an attacker can pollute the prototype of the Object, enabling them to modify the behavior of all objects in the application. This can have severe consequences, including the ability to execute arbitrary code, bypass security measures, or cause a DoS attack. The vulnerability has a CVSS score of 7.0, indicating a high severity level.
How To Fix
Latest published version: 9.11.3 as of 23 Oct 2026
npm install mongoose@9.11.3
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 5.13.155.13.15npm install mongoose@5.13.15 -
>= 6.0.0, < 6.4.66.4.6npm install mongoose@6.4.6
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a temporary workaround, developers can sanitize user input and validate the schema object before passing it to the Schema.path() function. This can help prevent the injection of malicious code and reduce the risk of prototype pollution. Here's an example of how to sanitize the schema object:
const schema = sanitizeSchema(userInput);
Schema.path(schema);
Conclusion
The vulnerability in mongoose (CVE-2022-2564) exposes applications to the risk of prototype pollution. It is crucial to update to the recommended versions or apply the provided workaround to mitigate the vulnerability. Regularly monitoring for vulnerabilities using tools like Vulert can help ensure the security of your application. For further support and assistance in vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for mongoose →
FAQ
Mongoose is an object modeling tool for MongoDB that provides a schema-based solution for modeling application data. It simplifies the interaction with MongoDB and allows developers to define schemas, perform validations, and create queries.
Prototype pollution is a vulnerability that occurs when an attacker can modify the prototype of an object, leading to unexpected behavior and potential security issues. In the case of mongoose, the vulnerability allows an attacker to modify the Object prototype, enabling them to manipulate the behavior of all objects in the application.
The consequences of this vulnerability can be severe. An attacker can exploit prototype pollution to execute arbitrary code, bypass security measures, or cause a Denial of Service (DoS) attack. It is crucial to patch this vulnerability to prevent these potential risks.
You can use Vulert's playground (https://vulert.com/scanner) to check if your application is affected by this vulnerability. Vulert monitors and alerts in real-time for open-source vulnerabilities, using just the package-lock.json file. It provides an easy way to assess the security of your application without requiring code access or installation.
You can find more information about this vulnerability, including its technical details and affected versions, in the advisory published by GitHub at the following link: https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2022/07/GHSA-f825-f98c-gj3g/GHSA-f825-f98c-gj3g.json
References
Related vulnerabilities
Recent vulnerabilities recorded for mongoose.