CVE-2022-24304: Mongoose Mongoose Vulnerable To Prototype Pollution Vulnerability

CRITICAL
Advisory Identifier: GHSA-h8hf-x3f4-xwgp
CVSS 9.8
CWE-1321
Published
Advisory Summary

CVE-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

CVE Identifier CVE-2022-24304
GHSA Identifier GHSA-h8hf-x3f4-xwgp
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')
Affected Product Mongoose
Package Ecosystem npm
Published Date
Last Updated

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).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (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.

mongoose fixed: 6.4.6
npm install mongoose@6.4.6
mongoose fixed: 5.13.15
npm install mongoose@5.13.15
Verify Direct and Transitive Dependencies

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

### 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 ```js // 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.

CVE-2022-24304 Affected Mongoose Versions

2 component(s)
Fixed Versions:
6.4.65.13.15
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?
CVE-2022-24304 is a security vulnerability in Mongoose involving Mongoose Vulnerable to Prototype Pollution in Schema Object under CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution').
Which Mongoose versions are affected?
Affected versions include releases prior to 6.4.6, 5.13.15 across affected packages: mongoose.
What version fixes CVE-2022-24304?
Upgrading to 6.4.6, 5.13.15 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mongoose affected?
Yes, mongoose is affected in releases prior to 6.4.6, 5.13.15. Upgrade your dependency to 6.4.6, 5.13.15 or later.
What is the CVSS score of CVE-2022-24304?
CVE-2022-24304 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-24304?
CVE-2022-24304 is classified under CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution') (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.).
How can I check npm dependencies for CVE-2022-24304?
Run the dependency tree command: 'npm ls mongoose'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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"
  }
}