CVE-2022-24304: Mongoose Mongoose Vulnerable To Prototype Pollution Vulnerability
CRITICALCVE-2022-24304 is a CRITICAL (CVSS 9.8) mongoose vulnerable to prototype pollution vulnerability (CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')) affecting Mongoose libraries in the npm ecosystem. The issue involves mongoose vulnerable to prototype pollution in schema object. Remediation is available by upgrading affected packages to version 6.4.6, 5.13.15.
CVE-2022-24304 at a Glance
Security Impact
CVSS: 9.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2022-24304
To remediate this vulnerability, upgrade all affected Mongoose dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install mongoose@6.4.6
npm install mongoose@5.13.15
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls mongoose
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2022-24304, inspect your project dependencies using npm:
npm ls mongoose
Analyze the terminal output to locate any version of Mongoose in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.4.6), your application is affected.
Note: The npm ls mongoose command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution'), where the product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype. In Mongoose, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2022-24304 Affected Mongoose Versions
2 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
mongoose
|
npm |
≥ 6.0.0
< 6.4.6
|
6.4.6
|
|
mongoose
|
npm |
< 5.13.15
|
5.13.15
|
References
Frequently Asked Questions
What is CVE-2022-24304?
Which Mongoose versions are affected?
What version fixes CVE-2022-24304?
Is mongoose affected?
What is the CVSS score of CVE-2022-24304?
What CWE is associated with CVE-2022-24304?
How can I check npm dependencies for CVE-2022-24304?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-h8hf-x3f4-xwgp",
"modified" : "2024-04-22T23:17:47Z",
"published" : "2022-08-27T00:00:54Z",
"aliases" : [ "CVE-2022-24304" ],
"summary" : "Mongoose Vulnerable to Prototype Pollution in Schema Object",
"details" : "### Description\nMongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.\n\nAffected 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.\n\n### Proof of Concept\n```js\n// poc.js\nconst mongoose = require('mongoose');\nconst schema = new mongoose.Schema();\n\nmalicious_payload = '__proto__.toString'\n\nschema.path(malicious_payload, [String])\n\nx = {}\nconsole.log(x.toString()) // crashed (Denial of service (DoS) attack)\n```\n\n### Impact\nThis vulnerability can be manipulated to exploit other types of attacks, such as Denial of service (DoS), Remote Code Execution, or Property Injection.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "mongoose"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.0.0"
}, {
"fixed" : "6.4.6"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "mongoose"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "5.13.15"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-24304"
}, {
"type" : "WEB",
"url" : "https://github.com/Automattic/mongoose/issues/12085"
}, {
"type" : "WEB",
"url" : "https://github.com/Automattic/mongoose/commit/6a197316564742c0422309e1b5fecfa4faec126e"
}, {
"type" : "WEB",
"url" : "https://github.com/Automattic/mongoose/commit/a45cfb6b0ce0067ae9794cfa80f7917e1fb3c6f8"
}, {
"type" : "WEB",
"url" : "https://github.com/Automattic/mongoose/blob/51e758541763b6f14569744ced15cc23ab8b50c6/lib/schema.js#L88-L141"
}, {
"type" : "WEB",
"url" : "https://huntr.dev/bounties/055be524-9296-4b2f-b68d-6d5b810d1ddd"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-1321" ],
"severity" : "CRITICAL",
"github_reviewed" : true,
"github_reviewed_at" : "2024-04-22T23:17:47Z",
"nvd_published_at" : "2022-08-26T05:15:00Z"
}
}