CVE-2022-2564: Mongoose Automattic/mongoose Vulnerable To Prototype Pollution Vulnerability

HIGH
Advisory Identifier: GHSA-f825-f98c-gj3g
CVSS 7.0
CWE-1321
Published
Advisory Summary

CVE-2022-2564 is a HIGH (CVSS 7.0) automattic/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 automattic/mongoose vulnerable to prototype pollution via schema.path. Remediation is available by upgrading affected packages to version 6.4.6, 5.13.15.

CVE-2022-2564 at a Glance

CVE Identifier CVE-2022-2564
GHSA Identifier GHSA-f825-f98c-gj3g
Severity HIGH
CVSS v3.1 Base Score 7.0
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: 7.0

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability High (A:H)

How to Fix CVE-2022-2564

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-2564, 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

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.

CVE-2022-2564 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-2564?
CVE-2022-2564 is a security vulnerability in Mongoose involving automattic/mongoose vulnerable to Prototype pollution via Schema.path 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-2564?
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-2564?
CVE-2022-2564 has a CVSS v3.1 base score of 7.0 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:H.
What CWE is associated with CVE-2022-2564?
CVE-2022-2564 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-2564?
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-f825-f98c-gj3g",
  "modified" : "2023-09-11T16:22:58Z",
  "published" : "2022-07-29T00:00:18Z",
  "aliases" : [ "CVE-2022-2564" ],
  "summary" : "automattic/mongoose vulnerable to Prototype pollution via Schema.path",
  "details" : "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.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/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-2564"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/commit/99b418941e2fc974199b8e5bd9d382bb50bf680a"
  }, {
    "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://github.com/Automattic/mongoose/blob/master/CHANGELOG.md"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/compare/6.4.5...6.4.6"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/automattic/mongoose"
  }, {
    "type" : "WEB",
    "url" : "https://huntr.dev/bounties/055be524-9296-4b2f-b68d-6d5b810d1ddd"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1321" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-08-04T14:22:23Z",
    "nvd_published_at" : "2022-07-28T20:15:00Z"
  }
}