Critical · 9.8 Node.js & npm GHSA-pcrw-h46h-c93h CVE-2026-125120
Mongoose countDocuments() Bypasses sanitizeFilter Protection (CVE-2026-125120)
Mongoose's sanitizeFilter query injection defense is not applied to countDocuments(), allowing attacker-controlled filter objects to be processed as query operators instead of literal values. This can distort counts used for authorization or application logic.
By PatchBriefing · ·
Produced automatically from official sources with the help of AI. How we work →
AI summary
A vulnerability has been identified in Mongoose, a MongoDB object modeling tool for Node.js. The issue affects the countDocuments() method, which does not apply the sanitizeFilter protection that is designed to prevent query selector injection. Applications that rely on sanitizeFilter and pass user-controlled input to countDocuments() may be affected. Fixed versions are available.
What happened
A vulnerability was disclosed in Mongoose affecting the countDocuments() method. Mongoose offers a sanitizeFilter option intended to neutralize query selector injection by treating attacker-supplied objects as literal values rather than MongoDB query operators. This protection was not applied when countDocuments() was used, meaning that even with sanitizeFilter enabled, filter values passed to countDocuments() could still be interpreted as operators.
Technical cause
The vulnerability is classified as CWE-943, improper neutralization of special elements in data query logic. countDocuments() did not route attacker-controlled filter objects through the sanitizeFilter sanitization step that other Mongoose query methods apply. As a result, an object containing MongoDB query operators (rather than a plain value) could be passed in as a filter and be evaluated as an operator, altering which documents are counted as matching.
Why it matters
Applications often use countDocuments() for logic such as checking whether a record exists, verifying uniqueness, or making authorization decisions based on a count (for example, confirming that exactly one record matches certain attacker-independent conditions). If an attacker can inject query operators into the filter, the count can be manipulated to include documents that should not match, which may lead to incorrect authorization decisions or flawed application logic.
Affected versions
The issue affects Mongoose versions prior to 6.13.11, versions from 7.0.0 up to (not including) 7.8.12, versions from 8.0.0 up to (not including) 8.24.3, and versions from 9.0.0 up to (not including) 9.9.2.
Fixes and mitigation
The issue is fixed in Mongoose versions 6.13.11, 7.8.12, 8.24.3, and 9.9.2. Applications using an affected version and relying on sanitizeFilter together with countDocuments() should update to one of these fixed versions.
Recommended action
Update Mongoose to version 6.13.11, 7.8.12, 8.24.3, or 9.9.2, depending on the major version line in use. Review any code paths that pass user-controlled input into countDocuments() filters, even where sanitizeFilter is enabled, and confirm that counts used for authorization or business logic are validated after updating.
PatchBriefing score
9.8 / 10 · Critical
Official CVSS: 9.8
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
EPSS 0.0094 (59 percentile)
Why this score
The PatchBriefing score equals the official CVSS score; when this article covers several vulnerabilities, the highest one. Signals such as known exploitation and EPSS are listed separately and do not change the score.
Affected versions
- mongoose >= 9.0.0, < 9.9.2
- vulnerable
- mongoose ≥ 9.0.0 < 9.9.2
- vulnerable
- ≥ 6.13.11
- patched
- ≥ 7.8.12
- patched
- ≥ 8.24.3
- patched
- ≥ 9.9.2
- patched
Reported fixes
The issue is fixed in Mongoose versions 6.13.11, 7.8.12, 8.24.3, and 9.9.2. Applications using an affected version and relying on sanitizeFilter together with countDocuments() should update to one of these fixed versions.
How this was built
4 source records were collected, matched and used to prepare the report above.
-
CVE.org database
-
NVD (NIST) database
-
GitHub Advisory Database database
-
OSV.dev database
Revision history
- Published
- Generated
- Published
- Generated