Packages / mongoose / Security

CriticalVulnerabilityGHSA-pcrw-h46h-c93hCVE-2026-125120Published 10 Nov 2026

Mongoose: sanitizeFilter not applied on countDocuments

Your version

Affected releases · mongoose

  • 9.x9.0.0 – 9.9.1Fixed in 9.9.2
  • 8.x8.0.0 – 8.24.2Fixed in 8.24.3
  • 7.x7.0.0 – 7.8.11Fixed in 7.8.12
  • 6.x6.0.0 – 6.13.10Fixed in 6.13.11
  • 5.x and older0.0.1 – 5.13.23No fix, no longer updated

On 9.x, the newest line:

npm install mongoose@9.9.2
Every release on a timeline
9.x
  1. Affected

    9.0.0 – 9.9.1

    35 releases

  2. Fixed

    9.9.2 – 9.12.3

    18 releases

8.x
  1. Affected

    8.0.0 – 8.24.2

    104 releases

  2. Fixed

    8.24.3 – 8.24.10

    8 releases

7.x
  1. Affected

    7.0.0 – 7.8.11

    57 releases

  2. Fixed

    7.8.12 – 7.8.14

    3 releases

6.x
  1. Affected

    6.0.0 – 6.13.10

    120 releases

  2. Fixed

    6.13.11 – 6.13.13

    3 releases

5.x
  1. Affected

    5.0.0 – 5.13.23

    255 releases

4.x
  1. Affected

    4.0.0 – 4.13.21

    164 releases

3.x
  1. Affected

    3.0.0 – 3.9.7

    104 releases

2.x
  1. Affected

    2.0.0 – 2.9.10

    84 releases

1.x
  1. Affected

    1.0.0 – 1.8.4

    64 releases

0.x
  1. Affected

    0.0.1 – 0.0.6

    6 releases

1025 stable releases of mongoose, oldest to newest, one row per major.

What happens

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());
  });
});

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.