Critical

Mongoose: sanitizeFilter not applied on countDocuments

  • Disclosed: 10.11.2026
  • Updated: 11.11.2026 10:00

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:

js
mongoose.plugin(function() {
  schema.pre('countDocuments', function() {
    // This will always apply `sanitizeFilter` on `countDocuments`
    mongoose.sanitizeFilter(this.getFilter());
  });
});

What to do

Upgrade to the appropriate patched release depending on the major version of Mongoose in use:

  1. ^9.9.2
  2. ^8.24.3
  3. ^7.8.12
  4. ^6.13.11

If upgrading is not immediately possible, apply the middleware workaround:

js
mongoose.plugin(function() {
  schema.pre('countDocuments', function() {
    // This will always apply `sanitizeFilter` on `countDocuments`
    mongoose.sanitizeFilter(this.getFilter());
  });
});

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package mongoose < 6.13.11, >= 7.0.0, < 7.8.12, >= 8.0.0, < 8.24.3, >= 9.0.0, < 9.9.2 6.13.11, 7.8.12, 8.24.3, 9.9.2

References

CVSS score 9.8/10
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
Weakness (CWE)
CWE-943
Platform
npm
Package
mongoose
Disclosed
10.11.2026
Updated
11.11.2026 10:00

Sources and licenses · Edited or translated by DockRay; source rights and applicable licenses are retained.

OSV / GitHub Advisory Database - GHSA-pcrw-h46h-c93h - CC BY 4.0

Vulnerability history: mongoose

All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (14) in the archive
Total entries
14
First → latest
10.2019 11.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • Critical 5
  • High 5
  • Medium 4

Disclosures per year

  1. 2019: 1
  2. 2020: 1
  3. 2021: 0
  4. 2022: 2
  5. 2023: 1
  6. 2024: 1
  7. 2025: 1
  8. 2026: 7
Severity:
  1. High · 8.2 CVE-2026-125117 < 6.13.12, >= 7.0.0, < 7.8.13, >= 8.0.0, < 8.24.7, >= 9.0.0, < 9.11.4 6.13.12, 7.8.13, 8.24.7, 9.11.4
  2. High · 7.5 CVE-2026-125119 >= 6.0.0, < 6.13.12, >= 7.0.0, < 7.8.13, >= 8.0.0, < 8.24.7, >= 9.0.0, < 9.11.4 6.13.12, 7.8.13, 8.24.7, 9.11.4
  3. Mongoose: sanitizeFilter not applied on countDocuments this entry
    Critical · 9.8 CVE-2026-125120 < 6.13.11, >= 7.0.0, < 7.8.12, >= 8.0.0, < 8.24.3, >= 9.0.0, < 9.9.2 6.13.11, 7.8.12, 8.24.3, 9.9.2
  4. High · 7.5 CVE-2026-42334 < 6.13.9, >= 7.0.0, < 7.8.9, >= 8.0.0, < 8.22.1, >= 9.0.0, < 9.1.6 6.13.9, 7.8.9, 8.22.1, 9.1.6
  5. Critical · 9.0 CVE-2025-23061 >= 8.0.0-rc0, < 8.9.5, >= 7.0.0-rc0, < 7.8.4, < 6.13.6 8.9.5, 7.8.4, 6.13.6
  6. High · 9.8 CVE-2024-53900 >= 8.0.0-rc0, < 8.8.3, >= 7.0.0-rc0, < 7.8.3, >= 6.0.0-rc0, < 6.13.5, >= 3.6.0-rc0, < 5.13.23 8.8.3, 7.8.3, 6.13.5, 5.13.23
  7. Critical · 10.0 CVE-2023-3696 >= 7.0.0, < 7.3.3, >= 6.0.0, < 6.11.3, < 5.13.20 7.3.3, 6.11.3, 5.13.20
  8. Critical · 9.8 CVE-2022-24304 >= 6.0.0, < 6.4.6, < 5.13.15 6.4.6, 5.13.15
  9. High · 7.0 CVE-2022-2564 >= 6.0.0, < 6.4.6, < 5.13.15 6.4.6, 5.13.15
  10. Critical · 9.1 CVE-2019-17426 >= 5.0.0, < 5.7.5, < 4.13.21 5.7.5, 4.13.21

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.