NIST deprecates RSA-2048 from 2030. Find every one of them before attackers do.
📦
📦 npm
Not in CISA KEV
MEDIUM severity

CVE-2026-142595 — mongoose

MEDIUMFix: Automattic/mongoose@34e7694

CVE-2026-142595 is a medium-severity (CVSS 6.5) CWE-943 vulnerability in mongoose. A fix is available for mongoose — see the affected versions and patch details below.

Mongoose: `sanitizeFilter` bypass via MongoDB internal top-level query operators such as `$_internalSchemaXor`

Also known asGHSA-25v4-hrwm-qj9f
Published
Updated
Affected
4 pkgs
Patched
4 / 4
Exploits
None indexed
Exploitation data as of Dec 3, 2026 · OSV.dev, NVD, FIRST.org (EPSS)

Exploitation Status

Proof-of-concept exploit code exists

  • CISA’s SSVC triage found public proof-of-concept exploit code for this CVE, though no confirmed active exploitation.

Exploitation and automatability from CISA’s SSVC triage for CVE-2026-142595.

Real-World Exposure

4 pkgs affected

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.

21Kother npm packages depend on this — each one inherits the vulnerability until it's patched upstream
mongoosenpm
8.6Mdownloads / week

Description

Summary

Mongoose's sanitizeFilter option is meant to block query selector injection. Before this fix, it only refused four top-level operators by name: $jsonSchema, $where, $expr and $text. Any other top-level $ operator was passed to MongoDB unchanged. That includes undocumented internal operators like $_internalSchemaXor and $_internalSchemaCond, which take sub-filters, and sanitizeFilter never inspected those sub-filters. An attacker who controls the keys of a query filter could use them to slip arbitrary query selectors like $ne or $regex past sanitizeFilter.

Details

With sanitizeFilter enabled, Mongoose:

  • wraps any object value containing $ keys in $eq, so { password: { $ne: null } } becomes { password: { $eq: { $ne: null } } };
  • recurses into $and, $or and $nor;
  • throws on $jsonSchema, $where, $expr and $text unless the value is wrapped in mongoose.trusted().

Every other top-level key starting with $ was left alone. MongoDB accepts several internal match expressions at the top level that contain nested filters, for example:

  • $_internalSchemaXor: [filter1, filter2]
  • $_internalSchemaCond: [ifFilter, thenFilter, elseFilter]

Because sanitizeFilter doesn't recurse into these, the nested filters can contain any query selector.

The fix makes sanitizeFilter refuse every top-level key that starts with $, except $and, $or and $nor, which it recurses into, and values wrapped in mongoose.trusted(). Nested $and/$or/$nor filters are checked the same way. This also means sanitizeFilter now refuses:

  • $comment: a user-supplied comment ends up in MongoDB's profiler and logs. Use Query.prototype.comment() instead, which sets the comment outside the filter.
  • $sampleRate, $alwaysTrue, $alwaysFalse, and top-level $ref/$id/$db.

A top-level $-prefixed field name can't be queried with a plain equality filter in the first place: MongoDB rejects { $userId: 42 } with "unknown top level operator". So the fix doesn't prevent any query that previously worked.

Proof of concept

const User = mongoose.model('User', new mongoose.Schema({ username: String, password: String }));
await User.create({ username: 'admin', password: 'hunter2' });

// Attacker controls the filter, e.g. `User.findOne(req.body)`
const login = filter => User.findOne(filter).setOptions({ sanitizeFilter: true });

// Blocked as expected: `$ne` is wrapped in `$eq`, so no match
await login({ username: 'admin', password: { $ne: null } }); // null

// Bypass: login without the password
await login({
  username: 'admin',
  $_internalSchemaXor: [{ password: { $ne: null } }, { $alwaysFalse: 1 }]
}); // { username: 'admin', password: 'hunter2', ... }

// Bypass: extract the password one character at a time
await login({
  username: 'admin',
  $_internalSchemaXor: [{ password: { $regex: '^h' } }, { $alwaysFalse: 1 }]
}); // matches, so password starts with 'h'

Tested against MongoDB 9.0.2. $_internalSchemaCond works the same way, and both operators also work inside $and/$or/$nor.

Impact

Applications are affected if they rely on sanitizeFilter to protect queries whose filter keys come from users. Common patterns are Model.find(req.body) and Model.find({ ...req.query, owner: userId }). An attacker can inject any query selector, which allows:

  • Authentication bypass: match a user record without knowing the password, as in the $ne example above.
  • Data extraction: use $regex as a boolean oracle to recover field values, such as password hashes or tokens, one character at a time.
  • Unintended writes: make updateOne(), deleteMany() and similar operations match documents the attacker shouldn't be able to target.

Applications that build filters from individual values, like { username: req.body.username }, are not affected. sanitizeFilter already wraps those values in $eq, so an attacker can't add top-level keys.

Affected Packages

4 total 4 fixed
EcosystemPackageVulnerable rangeFix
📦npmmongooseall versions6.13.13npm install mongoose@6.13.13
📦npmmongoose≥ 7.0.0&&< 7.8.147.8.14npm install mongoose@7.8.14
📦npmmongoose≥ 8.0.0&&< 8.24.108.24.10npm install mongoose@8.24.10
📦npmmongoose≥ 9.0.0&&< 9.12.29.12.2npm install mongoose@9.12.2

Detection & mitigation playbook

Open-source dependency
  1. Detect

    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.

  2. Fix

    Update mongoose to 6.13.13 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2026-142595 is resolved across your whole dependency graph.

  3. Workarounds

    Put an independent control in front of the weakness: restrict the affected endpoint or interface to trusted networks, require an additional authentication factor or proxy-level check, and invalidate existing sessions and credentials in case the flaw has already been used.

Frequently Asked Questions

### Summary Mongoose's `sanitizeFilter` option is meant to block query selector injection. Before this fix, it only refused four top-level operators by name: `$jsonSchema`, `$where`, `$expr` and `$text`. Any other top-level `$` operator was passed to MongoDB unchanged. That includes undocumented internal operators like `$_internalSchemaXor` and `$_internalSchemaCond`, which take sub-filters, and `sanitizeFilter` never inspected those sub-filters. An attacker who controls the keys of a query filter could use them to slip arbitrary query selectors like `$ne` or `$regex` past `sanitizeFilter`.
O3 Security · Impact-Aware SCA

Is CVE-2026-142595 in your dependencies?

Find it across npm, including transitive dependencies.