CVE-2025-23061: Mongoose Mongoose Search Injection Vulnerability Vulnerability

CRITICAL
Advisory Identifier: GHSA-vg7j-7cwx-8wgw
CVSS 9.0
CWE-94
Published
Advisory Summary

CVE-2025-23061 is a CRITICAL (CVSS 9.0) mongoose search injection vulnerability vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Mongoose libraries in the npm ecosystem. The issue involves mongoose search injection vulnerability. Remediation is available by upgrading affected packages to version 8.9.5, 7.8.4, 6.13.6.

CVE-2025-23061 at a Glance

CVE Identifier CVE-2025-23061
GHSA Identifier GHSA-vg7j-7cwx-8wgw
Severity CRITICAL
CVSS v3.1 Base Score 9.0
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Mongoose
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 9.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:C/C:H/I:H/A:H).

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

How to Fix CVE-2025-23061

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: 8.9.5
npm install mongoose@8.9.5
mongoose fixed: 7.8.4
npm install mongoose@7.8.4
mongoose fixed: 6.13.6
npm install mongoose@6.13.6
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-2025-23061, 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 8.9.5), 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-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. 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 versions prior to 8.9.5, 7.8.4, and 6.13.6 are vulnerable to improper use of the `$where` operator. This vulnerability arises from the ability of the `$where` clause to execute arbitrary JavaScript code in MongoDB queries, potentially leading to code injection attacks and unauthorized access or manipulation of database data. NOTE: this issue exists because of an incomplete fix for CVE-2024-53900.

CVE-2025-23061 Affected Mongoose Versions

3 component(s)
Fixed Versions:
8.9.57.8.46.13.6
Product / Package Ecosystem Affected Versions Fixed Version
mongoose
npm
≥ 8.0.0-rc0
< 8.9.5
8.9.5
mongoose
npm
≥ 7.0.0-rc0
< 7.8.4
7.8.4
mongoose
npm
< 6.13.6
6.13.6

References

Frequently Asked Questions

What is CVE-2025-23061?
CVE-2025-23061 is a security vulnerability in Mongoose involving Mongoose search injection vulnerability under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Mongoose versions are affected?
Affected versions include releases prior to 8.9.5, 7.8.4, 6.13.6 across affected packages: mongoose.
What version fixes CVE-2025-23061?
Upgrading to 8.9.5, 7.8.4, 6.13.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mongoose affected?
Yes, mongoose is affected in releases prior to 8.9.5, 7.8.4, 6.13.6. Upgrade your dependency to 8.9.5, 7.8.4, 6.13.6 or later.
What is the CVSS score of CVE-2025-23061?
CVE-2025-23061 has a CVSS v3.1 base score of 9.0 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2025-23061?
CVE-2025-23061 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check npm dependencies for CVE-2025-23061?
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-vg7j-7cwx-8wgw",
  "modified" : "2025-10-03T15:40:22Z",
  "published" : "2025-01-15T06:30:49Z",
  "aliases" : [ "CVE-2025-23061" ],
  "summary" : "Mongoose search injection vulnerability",
  "details" : "Mongoose versions prior to 8.9.5, 7.8.4, and 6.13.6 are vulnerable to improper use of the `$where` operator. This vulnerability arises from the ability of the `$where` clause to execute arbitrary JavaScript code in MongoDB queries, potentially leading to code injection attacks and unauthorized access or manipulation of database data.\n\nNOTE: this issue exists because of an incomplete fix for CVE-2024-53900.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongoose"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "8.0.0-rc0"
      }, {
        "fixed" : "8.9.5"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongoose"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "7.0.0-rc0"
      }, {
        "fixed" : "7.8.4"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongoose"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "6.13.6"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-23061"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/commit/64a9f9706f2428c49e0cfb8e223065acc645f7bc"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Automattic/mongoose"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/blob/master/CHANGELOG.md"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/compare/6.13.5...6.13.6"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/compare/7.8.3...7.8.4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/compare/8.9.4...8.9.5"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/releases/tag/6.13.6"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/releases/tag/7.8.4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/releases/tag/8.9.5"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-m7xq-9374-9rvx"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/package/mongoose?activeTab=versions"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-01-16T14:02:22Z",
    "nvd_published_at" : "2025-01-15T05:15:10Z"
  }
}