CVE-2026-142595: CVE-2026-142595: NoSQL Query Operator Injection via Incomplete Denylist in Automattic Mongoose sanitizeFilter
CVE-2026-142595: NoSQL Query Operator Injection via Incomplete Denylist in Automattic Mongoose sanitizeFilter Vulnerability ID: CVE-2026-142595 CVSS Score: 6.5 Published: 2026-12-04 CVE-2026-142595 is a NoSQL query
CVE-2026-142595: NoSQL Query Operator Injection via Incomplete Denylist in Automattic Mongoose sanitizeFilter
Vulnerability ID: CVE-2026-142595
CVSS Score: 6.5
Published: 2026-12-04
CVE-2026-142595 is a NoSQL query operator injection vulnerability in Automattic Mongoose caused by an incomplete denylist in the sanitizeFilter query sanitization utility. Prior to the patched versions, sanitizeFilter blocked only four specific top-level operators ($jsonSchema, $where, $expr, and $text), allowing unrecognized or internal MongoDB operators such as $_internalSchemaXor and $_internalSchemaCond to pass through unsanitized. Attackers capable of supplying top-level filter keys can inject arbitrary nested query selectors to bypass authentication, extract sensitive data via boolean inference, or modify database records.
TL;DR
An incomplete denylist in Mongoose's sanitizeFilter function permits internal top-level MongoDB operators like $_internalSchemaXor and $_internalSchemaCond to bypass sanitization. Applications passing raw user-supplied objects into Mongoose queries with sanitizeFilter enabled are vulnerable to NoSQL injection, authentication bypass, and blind data exfiltration. Upgrade to Mongoose 6.13.13, 7.8.14, 8.24.10, or 9.12.2.
β οΈ Exploit Status: POC
Technical Details
- CVE / Advisory ID: CVE-2026-142595 / GHSA-25v4-hrwm-qj9f
- Weakness Class: CWE-943: Improper Neutralization of Special Elements in Data Query Logic
- CVSS v3.1 Score: 6.5 Medium (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:N)
- EPSS Score: 0.56% (48.20th Percentile)
- Attack Vector: Network (NoSQL operator smuggling via $_internalSchemaXor / $_internalSchemaCond)
- Primary Impact: Authentication bypass, blind data extraction via regex/boolean inference, and unauthorized document modification
- Exploit Status: Proof-of-Concept available in upstream commit test suite; not in CISA KEV
- Patched Versions: Mongoose 6.13.13, 7.8.14, 8.24.10, and 9.12.2
Affected Systems
- Automattic Mongoose (npm package: mongoose) 6.0.0 through 6.13.12
- Automattic Mongoose (npm package: mongoose) 7.0.0 through 7.8.13
- Automattic Mongoose (npm package: mongoose) 8.0.0 through 8.24.9
- Automattic Mongoose (npm package: mongoose) 9.0.0 through 9.12.1
-
mongoose: >= 6.0.0, < 6.13.13 (Fixed in:
6.13.13) -
mongoose: >= 7.0.0, < 7.8.14 (Fixed in:
7.8.14) -
mongoose: >= 8.0.0, < 8.24.10 (Fixed in:
8.24.10) -
mongoose: >= 9.0.0, < 9.12.2 (Fixed in:
9.12.2)
Code Analysis
Commit: 34e7694
Disallow all top-level $ operators in sanitizeFilter except $and, $or, and $nor (Mongoose 8.x/9.x)
--- a/lib/helpers/query/sanitizeFilter.js
+++ b/lib/helpers/query/sanitizeFilter.js
@@ -24,7 +24,7 @@ module.exports = function sanitizeFilter(filter) {
if (key === '$and' || key === '$or' || key === '$nor') {
sanitizeFilter(value);
continue;
- } else if (key === '$jsonSchema' || key === '$where' || key === '$expr' || key === '$text') {
+ } else if (key[0] === '$') {
throw new MongooseError(key + ' is not allowed with sanitizeFilter');
}
Commit: 3e5f4c8
Backport sanitizeFilter top-level '$' operator restriction to Mongoose 7.x
Commit: 4627d2f
Backport sanitizeFilter top-level '$' operator restriction to Mongoose 6.x
Commit: c6a4c95
Additional hardening for top-level operator handling and empty filter checks
Exploit Details
- GitHub: Official Mongoose fix commit containing reproduction test cases using $_internalSchemaXor and $_internalSchemaCond to smuggle $regex and $alwaysFalse operators past sanitizeFilter.
Mitigation Strategies
- Upgrade Mongoose to a patched version (6.13.13, 7.8.14, 8.24.10, or 9.12.2) to enforce fail-closed validation on all top-level keys starting with '$'.
- Refactor application query logic to explicitly construct query filters from primitive scalar types rather than passing raw req.body or req.query objects into Mongoose query functions.
- Enforce strict input schema validation using libraries such as Zod, Joi, or Ajv on all incoming API endpoints to reject unexpected object keys and nested objects.
- Deploy WAF or application middleware filters to block incoming HTTP requests containing JSON keys prefixed with '$' or matching '$_internalSchema'.
Remediation Steps:
- Audit package.json and package-lock.json across all Node.js services to identify Mongoose installations within the vulnerable ranges (>=6.0.0 <6.13.13, >=7.0.0 <7.8.14, >=8.0.0 <8.24.10, >=9.0.0 <9.12.2).
- Run 'npm install [email protected]', 'npm install [email protected]', 'npm install [email protected]', or 'npm install [email protected]' according to your active major release branch.
- Search the codebase for usages of 'sanitizeFilter' (both 'mongoose.sanitizeFilter()' and '.setOptions({ sanitizeFilter: true })') and verify whether any legitimate code relies on top-level '$' operators other than '$and', '$or', or '$nor'; if so, wrap those developer-controlled values in 'mongoose.trusted()'.
- Execute automated test suites and redeploy updated application builds to production.
References
- GitHub Security Advisory GHSA-25v4-hrwm-qj9f
- NVD Vulnerability Detail: CVE-2026-142595
- CVE.org Record: CVE-2026-142595
- GitHub Commit 34e76947cc8a9ceb916c233aec01aea060bc3dba (Mongoose 8.x/9.x Fix)
- GitHub Commit 3e5f4c8b30ef42db1ab9f2794dc77c95f21d3835 (Mongoose 7.x Fix)
- GitHub Commit 4627d2fc572a943ee7afe26a1bcebe493dbd2508 (Mongoose 6.x Fix)
- GitHub Commit c6a4c95f9b15d81a352f2934c91b64ece583c2db
- Mongoose Release 9.12.2
- Mongoose Release 8.24.10
- Mongoose Release 7.8.14
- CVEListV5 JSON Definition for CVE-2026-142595
Read the full report for CVE-2026-142595 on our website for more details including interactive diagrams and full exploit analysis.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.