Mongoose: sanitizeFilter not applied on countDocumentsGHSA-pcrw-h46h-c93h
CRITICALFix: Automattic/mongoose@7e912afGHSA-pcrw-h46h-c93h is a critical-severity (CVSS 9.8) CWE-943 vulnerability in mongoose. A fix is available for mongoose — see the affected versions and patch details below.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
Where this sits among everything scored
Real-World Exposure
How broadly this vulnerability is actually deployed: weekly install volume shows current usage, and reverse-dependency count shows how many other packages break if it stays unpatched.
mongoosenpmDescription
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());
});
});
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | mongoose | all versions | 6.13.11npm install mongoose@6.13.11 |
| 📦npm | mongoose | ≥ 7.0.0&&< 7.8.12 | 7.8.12npm install mongoose@7.8.12 |
| 📦npm | mongoose | ≥ 8.0.0&&< 8.24.3 | 8.24.3npm install mongoose@8.24.3 |
| 📦npm | mongoose | ≥ 9.0.0&&< 9.9.2 | 9.9.2npm install mongoose@9.9.2 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for mongoose, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update mongoose to 6.13.11 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-pcrw-h46h-c93h is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
Frequently Asked Questions
Is GHSA-pcrw-h46h-c93h in your dependencies?
Find it across npm, including transitive dependencies.