CVE-2025-23061: Mongoose search injection vulnerability via $where operator

CVE-2025-23061 · Severity: low · CVSS 3.1 · Published 2025-01-15

Mongoose is a popular JavaScript library for interacting with MongoDB databases. This vulnerability allows attackers to inject and execute arbitrary JavaScript code through improper handling of the $where operator in database queries, potentially enabling unauthorized access to or modification of database records. The flaw is particularly dangerous in applications that accept user input in search or filter operations.

Technologies: mongoose (npm). Vendors: npm.

Quick answers

Is CVE-2025-23061 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2025-23061 being exploited in the wild.
How severe is CVE-2025-23061?
Low severity, with a CVSS score of 3.1, published 15 January 2025.
Which products and versions are affected?
mongoose (npm) SEMVER:introduced=8.0.0-rc0,fixed=8.9.5.
Is there a fix for CVE-2025-23061?
Yes. mongoose (npm): upgrade to 8.9.5 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2025-23061 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2025-23061?
Check whether you run mongoose (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • mongoose (npm): upgrade to 8.9.5 or later
    npm install mongoose@8.9.5

Technical details

The vulnerability stems from incomplete input validation of the $where operator in Mongoose query construction, specifically in the populate() match functionality. The $where clause in MongoDB allows arbitrary JavaScript execution, and Mongoose failed to properly sanitize nested $where expressions. An attacker can craft a malicious query with nested $where operators to execute arbitrary JavaScript code within MongoDB's JavaScript context, potentially achieving code injection and unauthorized data access or manipulation. Patches are available in versions 6.13.6, 7.8.4, and 8.9.5, which disallow nested $where operators in populate match filters.

Affected products

  • Automattic Mongoose Prior to 6.13.6, 7.8.4, and 8.9.5

Identifiers

  • CVE-2025-23061
  • GHSA-vg7j-7cwx-8wgw

Timeline

  • 2025-01-15: disclosed: Vulnerability disclosed
  • 2025-01-15: patched: Patches released in versions 6.13.6, 7.8.4, and 8.9.5

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.