All posts

Mongoose’s five new advisories: upgrade, and check where you use sanitizeFilter.

Five Mongoose advisories, one Critical (CVSS 9.8): sanitizeFilter was skipped on countDocuments and on the connection-level option. Patched versions and how to check.

Published
Reading time
7 min
By
Girish Babu GV

What happened#

Mongoose is the widely used MongoDB object-modelling library for Node.js. The advisories were published by the maintainer on GitHub on 2 November 2026, added to the NVD on 9 November, and to GitHub’s advisory database on 10 November, which is why they are showing up now. Three researchers are credited: koyokr for the two sanitizeFilter issues, Linus-Shyu for the virtual() one and Fcmam5 for the discriminator one. The inherited-properties advisory names no finder.

sanitizeFilter is a Mongoose option meant to stop “query selector injection”, where user-supplied input that is really an object of MongoDB operators changes what a query matches. Three of the five advisories are about places where that protection, or the object model underneath it, did not do what developers would expect.

The five advisories#

Mongoose advisories published 10 November 2026 (as shown on the advisory pages)
IssueIDSeverityFixed in
sanitizeFilter not applied on countDocuments()CVE-2026-125120Critical, 9.86.13.11, 7.8.12, 8.24.3, 9.9.2
Connection-level sanitizeFilter not appliedCVE-2026-125119High, 7.56.13.12, 7.8.13, 8.24.7, 9.11.4
Inherited properties walked when hydrating, setting and merging (denial of service, shared schema state)CVE-2026-125117High, 8.26.13.12, 7.8.13, 8.24.7, 9.11.4
Prototype pollution via Schema.prototype.virtual()CVE-2026-125118Moderate, 6.56.13.12, 7.8.13, 8.24.7, 9.11.4
Discriminator key values that match inherited propertiesCVE-2026-125116Moderate, 4.86.13.12, 7.8.13, 8.24.7, 9.11.4

In plain terms, per the advisories:

  • countDocuments (Critical). sanitizeFilter protects against selector injection, but older versions did not apply it to countDocuments() queries. The advisory’s vector is network-reachable, no privileges, no user interaction.
  • Connection-level option (High). If you set sanitizeFilter: true on the connection (in mongoose.connect() or createConnection()), the connection reports it as enabled, but queries do not apply it. The advisory says this has been the case since 6.0.0 and was still present in 9.11.2. It says setting it globally with mongoose.set() or per query with .sanitizeFilter() is not affected.
  • Inherited properties (High). Three code paths wrote into inherited properties without checking they were the object’s own. The advisory says a crafted key such as toString can break every later query in the process until restart, including queries on unrelated models, and that on strict: false subdocuments an attacker who controls the path passed to doc.set() could change shared schema state, such as removing a required validator for all documents.
  • Schema.virtual() (Moderate). Fixes from 2022 covered Schema.path() and add() but not virtual(). The advisory says the risk is highest where field names are attacker-influenced, such as dynamic schemas or CMS form builders.
  • Discriminator keys (Moderate). Values like constructor in the discriminator key resolve to inherited members. The advisory says this can make requests fail or let a raw document be stored without casting (with bulkWrite() and skipValidation: true), and that queries returning that document then fail until it is deleted in the database. It says this does not allow modifying shared state.

Am I affected?#

All five share the same affected ranges as far as the pages I read show: below 6.13.12, 7.0.0 to below 7.8.13, 8.0.0 to below 8.24.7, and 9.0.0 to below 9.11.4. The Critical advisory’s own ranges are slightly older (below 6.13.11, 7.8.12, 8.24.3 and 9.9.2), because that fix shipped first.

  • You use Mongoose at all: check your version. Anything below the versions above is in range for at least some of these.
  • You build query filters from request data: look for sanitizeFilter in your code. If you relied on it, check where you set it. The connection-level form was not applied on any version before the patches.
  • You call countDocuments() with user-influenced filters: the Critical advisory is about exactly that call.
  • Users can influence schema field names or the names of fields in stored documents: the three object-model advisories matter most there. The advisories do not say a typical app with fixed schemas is exposed to the prototype-pollution one.

What to do now#

  1. Find your version in every project, including monorepo packages and anything that pulls Mongoose in indirectly.
  2. Upgrade to the newest release on your major line. On the registry’s tags at the time I checked, that is 6.13.12 (6.x), 7.8.13 (7.x), 8.24.8 (8.x) and 9.12.1 (9.x). All are at or above the patched versions listed above.
  3. Check how you use sanitizeFilter. If it is set on the connection, also set it globally or per query until you have upgraded and tested. Those two forms are the ones the advisory says are unaffected.
  4. If you cannot upgrade a Critical-affected version yet, the advisory gives a workaround: a plugin that adds a pre("countDocuments") hook calling mongoose.sanitizeFilter(this.getFilter()). It notes its snippet is a rough sketch that needs adapting, so test it before relying on it.
  5. Validate input at the edge too. Do not depend on one Mongoose option as the only guard: check that values you expect to be strings are strings before they reach a query.
Check your version, then upgrade
# Which Mongoose versions are installed (direct and indirect)?
npm ls mongoose

# Upgrade within your current major line, for example:
npm install mongoose@^9.12.1   # 9.x
npm install mongoose@^8.24.8   # 8.x

# Find where sanitizeFilter is configured in your code
grep -rn "sanitizeFilter" src/ app/ lib/ 2>/dev/null

Mongoose 9 may have changes that affect your app, so read its release notes before a major jump, and test after any upgrade.

How I checked this site#

This site is a Next.js project on Vercel. I searched its package.json and package-lock.json for mongoose and found no match, so it does not use Mongoose. That covers this repository only.

What the sources don’t say#

  • Whether anyone has exploited any of these. The pages I read do not claim exploitation. The Critical advisory shows an EPSS score of 0.566%, which is a probability estimate, not evidence.
  • Why the Critical fix (August 2026 releases, per the registry) was disclosed on 2 November. The advisories do not explain the gap, and I will not guess.
  • How many real apps are exposed. That depends on whether they use sanitizeFilter and what reaches countDocuments().
  • I did not read independent coverage. My second source is the npm registry, for versions and release dates.

My take#

My own opinion, not from the advisories.

The lesson I take from the sanitizeFilter pair is that a safety option you set once and trust is only as good as its test. A connection that reports the option as enabled while queries ignore it is a quiet failure. If your app depends on a guard like this, write one test that sends an operator object where a string should be and confirm it is rejected, on every query path you care about, including counts.

Sources#

Keep reading

Esc