Summary
Mongoose: sanitizeFilter not applied on countDocuments
Advisory details
Impact
sanitizeFilter is Mongoose's mechanism for protecting against query selector injection attacks. In older versions of Mongoose, sanitizeFilter was not applied for countDocuments() queries.
Patches
Patches have been released for all supported Mongoose major release lines. Please upgrade to the following versions depending on which major version of Mongoose applications are using.
^9.9.2^8.24.3^7.8.12^6.13.11
Workarounds
Middleware:
mongoose.plugin(function() {
schema.pre('countDocuments', function() {
// This will always apply `sanitizeFilter` on `countDocuments`
mongoose.sanitizeFilter(this.getFilter());
});
});
References
- https://github.com/advisories/GHSA-pcrw-h46h-c93h
- https://github.com/Automattic/mongoose/security/advisories/GHSA-pcrw-h46h-c93h
- https://nvd.nist.gov/vuln/detail/CVE-2026-125120
- https://github.com/Automattic/mongoose/commit/7e912af3fac52cb0eea4cd71e24d65318916831a
- https://github.com/Automattic/mongoose/commit/8b10d5760bb181f5bf5d01495cde161c8aed0557
- https://github.com/Automattic/mongoose/commit/b1df045aab076b740fdaec14a15a44c694b85b7d
- https://github.com/Automattic/mongoose/commit/b5003d3915db1cf9209c38a4b93cf3a92cddd710
- https://github.com/Automattic/mongoose/releases/tag/6.13.11
Related vulnerabilities
All Supply chain →- HIGHCVE-2026-61689
XWiki Platform: HQL injection in search allows unauthenticated database extraction including password hashes
- HIGHCVE-2026-125119
Mongoose: Connection-level sanitizeFilter not applied
- MEDIUMGHSA-jf75-q64q-g65r
Waline login accepts a non-string email as a match-all MongoDB query
- HIGHCVE-2026-114510
Flexible GraphRAG: Cypher/Graph Injection via broken string-escaping in FalkorDB adapter (_escape()) - full graph wipe from ingested-document content
- MEDIUMCVE-2026-103288
Ghost: Authorization Bypass in Comment Like Feature
- MEDIUMCVE-2026-113662
ApostropheCMS import-export: NoSQL injection via update-key value lets a crafted import match and overwrite an unidentified document