# CVE-2025-23061: Mongoose search injection vulnerability

> Attackers can execute arbitrary code via search injection in Mongoose ODM using nested $where filters with populate().

- **Severity:** Critical 9.0 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 15 Jan 2025
- **Updated:** 15 Jan 2025
- **Also known as:** BIT-mongoose-2025-23061, CLSA-2026-1774916722, CLSA-2026-1777250310, GHSA-vg7j-7cwx-8wgw, ROOT-APP-NPM-CVE-2025-23061

## What is CVE-2025-23061?

CVE-2025-23061 is a critical code injection vulnerability in mongoosejs Mongoose, published on 15 Jan 2025. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Mongoose before 8.9.5 can improperly use a nested $where filter with a populate() match, leading to search injection. NOTE: this issue exists because of an incomplete fix for CVE-2024-53900.

Weakness: CWE-94 (Improper Control of Generation of Code)

## Which versions are affected by CVE-2025-23061?

7 open source packages ship an affected version, including mongoose. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `mongoose` | Bitnami | From 6.0.0 | 6.13.6, 7.8.4, 8.9.5 |
| `mongoose` | npm | All versions | 6.13.6 |
| `mongoose` | npm | All versions | 6.13.6 |
| `mongoose` | npm | From 7.0.0-rc0 | 7.8.4 |
| `mongoose` | npm | From 7.0.0-rc0 | 7.8.4 |
| `mongoose` | npm | From 8.0.0-rc0 | 8.9.5 |
| `mongoose` | npm | From 8.0.0-rc0 | 8.9.5 |

Products: Mongoosejs Mongoose.

## How do I fix CVE-2025-23061?

Upgrade mongoose to a fixed version for your release line: 6.13.6, 7.8.4 or 8.9.5.

## Is CVE-2025-23061 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2025-23061 exists.

Public exploit code:

- CVE-2025-23061 - Mongoose Command Injection (github_poc): https://github.com/open-flaw/CVE-2025-23061
- https://github.com/amikanev/CVE-2025-23061-LAB (github_poc): https://github.com/amikanev/CVE-2025-23061-LAB
- Mongoose - NoSQL Injection (nuclei): http/cves/2025/CVE-2025-23061.yaml

## Other vulnerabilities in mongoosejs Mongoose

- [CVE-2023-3696](https://insights.sbomify.com/CVE-2023-3696/): Prototype Pollution in automattic/mongoose (critical 10.0)
- [CVE-2024-53900](https://insights.sbomify.com/CVE-2024-53900/): Mongoose search injection vulnerability (critical 9.1)
- [CVE-2019-17426](https://insights.sbomify.com/CVE-2019-17426/): Improper Input Validation in Automattic Mongoose (critical 9.1)
- [CVE-2026-42334](https://insights.sbomify.com/CVE-2026-42334/): Mongoose: Improper Sanitization of $nor in sanitizeFilter May Allow NoSQL Injection (high 7.5)
- [CVE-2022-2564](https://insights.sbomify.com/CVE-2022-2564/): Prototype Pollution in automattic/mongoose (high 7.0)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-23061 and fix it if it is affected.

What it is: CVE-2025-23061 is a critical code injection vulnerability in mongoosejs Mongoose, published on 15 Jan 2025. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2025-23061 exists.

Affected packages and fixed versions:
- mongoose (Bitnami): affected from 6.0.0; fixed in 6.13.6, 7.8.4, 8.9.5
- mongoose (npm): affected all versions; fixed in 6.13.6
- mongoose (npm): affected all versions; fixed in 6.13.6
- mongoose (npm): affected from 7.0.0-rc0; fixed in 7.8.4
- mongoose (npm): affected from 7.0.0-rc0; fixed in 7.8.4
- mongoose (npm): affected from 8.0.0-rc0; fixed in 8.9.5
- mongoose (npm): affected from 8.0.0-rc0; fixed in 8.9.5

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2025-23061/ (Markdown: https://insights.sbomify.com/CVE-2025-23061/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2025-23061
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2025-23061
- OSV: https://osv.dev/vulnerability/CVE-2025-23061

---
From sbomify Insights: https://insights.sbomify.com/CVE-2025-23061/
Summaries are generated and may contain mistakes; the official description above is the record.
