Mongoose: sanitizeFilter not applied on countDocuments
Published 10 Nov 2026 · Updated 10 Nov 2026
Is your project on an affected mongoose?
Affected packages
- Affected
- <6.13.11
- Fixed in
- 6.13.11
npm install mongoose@6.13.11- Affected
- >=7.0.0 <7.8.12
- Fixed in
- 7.8.12
npm install mongoose@7.8.12- Affected
- >=8.0.0 <8.24.3
- Fixed in
- 8.24.3
npm install mongoose@8.24.3- Affected
- >=9.0.0 <9.9.2
- Fixed in
- 9.9.2
npm install mongoose@9.9.2Details
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.
1. ^9.9.2
2. ^8.24.3
3. ^7.8.12
4. ^6.13.11
Workarounds
Middleware:
mongoose.plugin(function() {
schema.pre('countDocuments', function() {
// This will always apply `sanitizeFilter` on `countDocuments`
mongoose.sanitizeFilter(this.getFilter());
});
});Is GHSA-pcrw-h46h-c93h in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected mongoose, and gives you the command that fixes it.
More advisories for mongoose
- MediumCVE-2026-125116Mongoose: Discriminator key values matching inherited properties (e.g. __t: 'constructor') bypass schema casting and can poison collections · 10 Nov 2026
- HighCVE-2026-125117Mongoose walks into inherited properties when hydrating, setting, and merging, allowing overwrites of built-in functions (denial of service) and shared schema state · 10 Nov 2026
- MediumCVE-2026-125118Mongoose: Prototype pollution via Schema.prototype.virtual() · 10 Nov 2026
- HighCVE-2026-125119Mongoose: Connection-level sanitizeFilter not applied · 10 Nov 2026
- MediumCVE-2026-73562Mongoose: Prototype pollution in mongoose update casting via __proto__-prefixed dotted path (Schema._getSchema/path getter) · 24 Jul 2026
- HighCVE-2026-42334Mongoose's Improper Sanitization of $nor in sanitizeFilter May Allow NoSQL Injection · 5 May 2026
References
- Linkgithub.com/Automattic/mongoose/security/advisories/GHSA-pcrw-h46h-c93h
- Advisorynvd.nist.gov/vuln/detail/CVE-2026-125120
- Linkgithub.com/Automattic/mongoose/commit/7e912af3fac52cb0eea4cd71e24d65318916831a
- Linkgithub.com/Automattic/mongoose/commit/8b10d5760bb181f5bf5d01495cde161c8aed0557
- Linkgithub.com/Automattic/mongoose/commit/b1df045aab076b740fdaec14a15a44c694b85b7d
- Linkgithub.com/Automattic/mongoose/commit/b5003d3915db1cf9209c38a4b93cf3a92cddd710
- Packagegithub.com/Automattic/mongoose
- Linkgithub.com/Automattic/mongoose/releases/tag/6.13.11
- Linkgithub.com/Automattic/mongoose/releases/tag/7.8.12
- Linkgithub.com/Automattic/mongoose/releases/tag/8.24.3
- Linkgithub.com/Automattic/mongoose/releases/tag/9.9.2
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.