CVE-2026-125119: Mongoose: Connection-level sanitizeFilter not applied
Summary sanitizeFilter exists to stop query selector injection: it wraps operator objects such as { $ne: null } in filter values in $eq, so they are matched literally. Set on a connection with mongoose.connect() or createConnection(uri, { sanitizeFilter: true }), the connection reports it as enabled but queries never apply it.
Published Nov 10, 2026
Affected packages
mongoose
- Ecosystem
- npm
- Affected
- >= 6.0.0, < 6.13.12
- Fixed in
- 6.13.12
- Check
npm ls mongoose
mongoose
- Ecosystem
- npm
- Affected
- >= 7.0.0, < 7.8.13
- Fixed in
- 7.8.13
- Check
npm ls mongoose
mongoose
- Ecosystem
- npm
- Affected
- >= 8.0.0, < 8.24.7
- Fixed in
- 8.24.7
- Check
npm ls mongoose
mongoose
- Ecosystem
- npm
- Affected
- >= 9.0.0, < 9.11.4
- Fixed in
- 9.11.4
- Check
npm ls mongoose
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
Summary
sanitizeFilter exists to stop query selector injection: it wraps operator objects such as { $ne: null } in filter values in $eq, so they are matched literally. Set on a connection with mongoose.connect() or createConnection(uri, { sanitizeFilter: true }), the connection reports it as enabled but queries never apply it. An application that relies on the connection-level option and passes an attacker-controlled object into a filter therefore remains open to selector injection, and a password value of { $ne: null } returns the account record without the password.
Details
NativeConnection#createClient() at lib/drivers/node-mongodb-native/connection.js:270-272 moves options.sanitizeFilter into Connection.config and deletes the original option. Query#_castConditions() at lib/query.js:2413-2423 checks Connection.options, the global options, and the per-query options, but never Connection.config. The defense therefore does not run even though Connection#get('sanitizeFilter') returns true. This storage was introduced in Mongoose 6.0.0 and the same mismatch is present in 9.11.2.
Proof of concept
import mongoose from 'mongoose'
const conn = await mongoose.createConnection('<MONGODB_URI>', { sanitizeFilter: true }).asPromise()
const User = conn.model('User', new mongoose.Schema({
username: String,
password: String,
marker: String
}))
await User.create({
username: 'victim',
password: 'correct-password',
marker: 'PROTECTED_RECORD'
})
const filter = { username: 'victim', password: { $ne: null } }
console.log(conn.get('sanitizeFilter'))
console.log((await User.findOne(filter).lean()).marker)A control query with a literal wrong password returned no document in the same run, confirming the filter is otherwise enforced.
Impact
Connection-level sanitizeFilter option is not respected. Any user that relies on connection-level config and sanitizeFilter to defend against query selector injection is affected. Users that set sanitizeFilter globally using mongoose.set('sanitizeFilter') or on specific queries using Model.find().sanitizeFilter() are not affected.
Credited to koyokr.
References
- https://github.com/Automattic/mongoose/security/advisories/GHSA-gg4r-jv3p-qx3c
- https://nvd.nist.gov/vuln/detail/CVE-2026-125119
- https://github.com/Automattic/mongoose/commit/4bb659478be2f30655a7bdd78bc251bdf111cd29
- https://github.com/Automattic/mongoose/commit/4f4f9a79f860786a54133bee2c9af967ec691491
- https://github.com/Automattic/mongoose/commit/83eda6af1489e9ef60bb8eee8cf9ee005771b9d5
- https://github.com/Automattic/mongoose/commit/b8970c25998c23fbccd17f76c0398b902ff4911d
- https://github.com/Automattic/mongoose/releases/tag/6.13.12
- https://github.com/Automattic/mongoose/releases/tag/7.8.13
- https://github.com/Automattic/mongoose/releases/tag/8.24.7
- https://github.com/Automattic/mongoose/releases/tag/9.11.4
- https://github.com/advisories/GHSA-gg4r-jv3p-qx3c
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More npm vulnerabilities
All npm entriesCVE-2026-125116
Mongoose: Discriminator key values matching inherited properties (e.g. __t: 'constructor') bypass schema casting and can poison collections
medium4.8Nov 10, 2026CVE-2026-125117
Mongoose walks into inherited properties when hydrating, setting, and merging, allowing overwrites of built-in functions (denial of service) and shared schema state
high8.2Nov 10, 2026CVE-2026-125118
Mongoose: Prototype pollution via Schema.prototype.virtual()
medium6.5Nov 10, 2026CVE-2026-125120
Mongoose: sanitizeFilter not applied on countDocuments
critical9.8Nov 10, 2026CVE-2026-73562
Mongoose: Prototype pollution in mongoose update casting via __proto__-prefixed dotted path (Schema._getSchema/path getter)
medium6.5Jul 24, 2026CVE-2026-42334
Mongoose's Improper Sanitization of $nor in sanitizeFilter May Allow NoSQL Injection
high7.5May 5, 2026
