79% vs 51%: independent neobanks lag on app security. Read the report

Deep Dive

Deep Dive

Mongoose sanitizeProjection Bypass Leaks Secrets (CVE-2026-142596)

Mongoose 8.0.0 to 8.24.9 and 9.0.0 to 9.12.1 let user-controlled projections return select:false fields such as password hashes; fixed in 8.24.10 and 9.12.2.

TL;DR

  • A bypass in Mongoose's sanitizeProjection lets a user-controlled projection return fields marked select: false, including password hashes, reset tokens and API keys. The advisory was published on 2026-11-23, and the CVE record on 2026-12-02.
  • Mongoose 8.0.0 to 8.24.9 and 9.0.0 to 9.12.1 are in the advisory's affected range. The sanitizeProjection bypass applies from 8.5.0, when the protection was introduced.
  • The CVE record carries CVSS v3.1 7.5 High. The advisory includes a public proof of concept; no in-the-wild exploitation is reported, and the CVE is not in CISA KEV as of 2026-12-03.
  • Upgrade to 8.24.10 or 9.12.2, or later. "How do I fix it?" has an allowlist workaround for code that cannot upgrade yet.

Am I affected?

You are affected if a Mongoose query takes a projection from user input and relies on sanitizeProjection to hide select: false fields. All of these must hold:

  • The application uses Mongoose.
  • The version is 8.0.0 to 8.24.9, or 9.0.0 to 9.12.1. The sanitizeProjection protection starts in 8.5.0; releases before 8.5.0 do not block select: false fields at all.
  • The application passes user-controlled data to select(), find(filter, projection) or the projection option.
  • The application relies on sanitizeProjection to keep select: false fields out of the result.

Mongoose's sanitizeProjection option is meant to let an application accept a projection from a client while removing any path the schema marks select: false. APIs use it when callers choose which fields to return. The bypass matters because the fields it exposes are the ones the schema deliberately hides.

The advisory lists 8.0.0 to 8.24.9 and 9.0.0 to 9.12.1 as affected. Mongoose 6.x and 7.x are not in that range. They also lack the protection introduced in 8.5.0, so a user-controlled projection can expose the same fields there.

Branch Affected versions Fixed version
9.x 9.0.0 to 9.12.1 9.12.2
8.x 8.0.0 to 8.24.9 (the sanitizeProjection protection starts in 8.5.0) 8.24.10

Check the installed version with npm. The command prints the resolved tree, so a transitive copy is visible too:

npm ls mongoose

In a lockfile, the installed entry shows the exact version. Lockfile version 2 and 3 store it under node_modules/mongoose:

grep -A2 '"node_modules/mongoose"' package-lock.json

If the application resolves Mongoose at runtime, ask Node for the version it actually loads:

node -p "require('mongoose/package.json').version"

For pnpm or Yarn, use the package manager's own query: pnpm why mongoose or yarn why mongoose.

How do I fix it?

Upgrade to the fixed release for your branch. The fix is in 8.24.10 and 9.12.2, and later releases include it.

  1. For the 8.x branch, install mongoose@^8.24.10.
  2. For the 9.x branch, install mongoose@^9.12.2.
  3. Run npm ls mongoose and confirm that no copy resolves earlier than the fixed version.
  4. Rebuild and redeploy the application.
npm install mongoose@^8.24.10
npm install mongoose@^9.12.2

Use the command that matches the branch you run, not both. For pnpm, run pnpm update mongoose@^9.12.2; for Yarn, run yarn upgrade mongoose@^9.12.2. Adjust the range to 8.24.10 if you stay on 8.x.

If you cannot upgrade yet, stop passing user-controlled projections to the query. Build the projection from a fixed allowlist of field names and reject every other key:

const allowed = new Set(['name', 'email']);
const projection = {};
for (const key of Object.keys(userInput)) {
  if (allowed.has(key)) projection[key] = 1;
}

The allowlist covers only the code paths you change. The bypass has many forms, so treat it as a stopgap and upgrade as soon as you can. Enabling sanitizeProjection on an affected version does not close the bypass.

What is the root cause?

The sanitizeProjection helper replaced only string projection values with 1, so object and array values passed through to MongoDB and could read another field as an aggregation expression. The helper lives in lib/helpers/query/sanitizeProjection.js; at the affected tags its loop was:

const keys = Object.keys(projection);
for (let i = 0; i < keys.length; ++i) {
  if (typeof projection[keys[i]] === 'string') {
    projection[keys[i]] = 1;
  }
}

A value like { name: { $concat: ['$password'] } } is an object, so the loop left it alone. MongoDB evaluated it as an aggregation expression, read the password field and returned its value in the name field. An array value like { name: ['$password'] } did the same.

The query path had related gaps. In an exclusive projection, +password could override a schema-level select: false; select('-+password') collapsed to +password before the check. select() copied an own __proto__ key, which re-pointed the projection object's prototype and hid the exclusion.

Nested sub-projections, parent-path selection such as profile, and positional projections such as comments.$ were other ways around the check. So were $meta, $elemMatch cast errors, discriminator-specific select: false fields and schemaLevelProjections(false). The common cause is that the sanitizer recognized a narrow set of projection shapes, and the query path did not normalize the rest before MongoDB saw them.

How is it exploited?

The attacker supplies a projection form that sanitizeProjection does not recognize, and MongoDB returns a select: false field in the query result. The advisory includes a working proof of concept.

  1. The application passes a user-controlled projection to select(), find(filter, projection) or the projection option.
  2. The application enables sanitizeProjection and expects select: false fields to be removed.
  3. The attacker sends a projection the sanitizer misses, such as '-name +password' or { name: { $concat: ['$password'] } }.
  4. MongoDB evaluates the projection and reads the protected field.
  5. The application returns the document to the attacker.

The public proof of concept shows the result on an affected version:

await User.findOne().sanitizeProjection(true).select('-name +password');
// { password: '<password hash>', ... }

await User.findOne().sanitizeProjection(true).select({ name: { $concat: ['$password'] } });
// { name: '<password hash>' }

The full script, including the schema and the list of bypass forms, is in the Mongoose advisory.

How does the attack flow?

An attacker-controlled projection reaches select() or find(), the sanitizer rewrites only string values, and MongoDB returns the select: false field the application meant to hide.

flowchart LR A["Attacker controls
a projection value"] --> B["App passes it to
select() or find()"] B --> C["sanitizeProjection
replaces strings only"] C --> D["Object, array or +path
passes through"] D --> E["MongoDB returns
select:false fields"] E --> F["Attacker reads password
hashes or tokens"]

What can an attacker do?

An attacker can read fields the schema marks select: false, including password hashes, password-reset tokens, API keys and nested secrets. The attacker gets the data when the application returns the query result to the user.

The conditions are the ones in "Am I affected?": a user-controlled projection reaches select(), find(filter, projection) or the projection option, and the application relies on sanitizeProjection. The CVSS vector is CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N. It describes an unauthenticated network attacker who needs no privileges and no user interaction.

A password hash can be cracked offline, a reset token can be replayed, and an API key can be used directly. The impact depends on which select: false fields the schema stores and whether the endpoint returns them to the caller.

The advisory demonstrates read access to the protected fields. It does not show modification of data. Treat any exposed secret as compromised until it is rotated. A hash that is not rotated remains crackable. No in-the-wild exploitation is reported, and the CVE is not in CISA KEV as of 2026-12-03.

Why does the fix work?

The fix turns every object or array projection that is not a known-safe operator into an inclusion of 1, so aggregation expressions cannot read another field. The new loop in lib/helpers/query/sanitizeProjection.js is:

const value = projection[keys[i]];
if (typeof value === 'string') {
  projection[keys[i]] = 1;
  continue;
}
if (value == null || typeof value !== 'object') {
  continue;
}
const slice = value.$slice;
const isAllowedProjectionOperator = value.$meta === 'textScore' ||
  value.$elemMatch != null ||
  typeof slice === 'number' ||
  (Array.isArray(slice) && slice.every(v => typeof v === 'number'));
if (!isAllowedProjectionOperator) {
  projection[keys[i]] = 1;
}

Only $meta: 'textScore', $elemMatch, and a numeric $slice survive. A $slice whose argument is an expression becomes 1, and so do nested sub-projections, arrays and $concat expressions.

The patch also removes __proto__ in select() and deletes +path and -+path when sanitizing. It treats nested exclusion objects and $elemMatch correctly. It adds select: false exclusions for parent and nested paths, handles discriminators, and applies sanitization when schemaLevelProjections is disabled.

The fix covers the projection forms the advisory lists, and the patch adds a test file for them. It is not a promise that every future MongoDB projection operator is safe, so keep treating user-controlled projections as untrusted input.

How do I check if I was compromised?

No public indicators of compromise are published, and the exposure leaves no specific server-side trace beyond the queries. Start by finding every place that passes request data to a projection.

grep -rn "\.select(" --include='*.js' .
grep -rn "sanitizeProjection" --include='*.js' .

Review each hit and check whether the projection value can come from the request. Then search access logs for projection values that contain $ operators, + paths, __proto__, or nested objects. A hit is a lead to inspect, not proof of exploitation, because legitimate clients can send unusual projections too.

If the MongoDB profiler or slow-query log is enabled, inspect recent entries for projections that contain $ operators or + paths. The profiler records the command shape, so it can show a projection that the application log does not.

If you find a successful exposure, rotate the secrets that were returned: password hashes, reset tokens, API keys and any nested credentials. Review the affected endpoints for unusual reads. An attempt that failed may leave no trace.

Timeline

  • 2026-11-16: Mongoose releases 8.24.10 and 9.12.2 with the fix.
  • 2026-11-23: The Mongoose advisory GHSA-xfcm-rmv3-crmq is published.
  • 2026-12-02: The CVE-2026-142596 record is published.

From fixed release to CVE record in 16 days
Figure 1: Mongoose CVE-2026-142596 from the fixed releases on 2026-11-16 to the advisory on 2026-11-23 and the CVE record on 2026-12-02. Source: Mongoose advisory and CVE record, checked December 3, 2026

FAQ

Is this the same as CVE-2026-125120?

No. CVE-2026-125120 was a sanitizeFilter bypass, and this is a sanitizeProjection bypass. Both are Mongoose query options, but they protect different parts of the query and have different fixes.

Does lean() prevent the exposure?

No. The advisory's proof of concept calls .lean(), and the protected fields still come back. MongoDB applies the projection before Mongoose hydrates the result, so lean() changes the result object, not the fields the database returns.

Do I need to enable sanitizeProjection?

No, not on an affected version: enabling sanitizeProjection there does not close the bypass. An application that passes user-controlled projections without the option is exposed to the same fields, so the fix is upgrading to 8.24.10 or 9.12.2.

Is there a public exploit?

Yes. The Mongoose advisory includes a proof of concept with a schema and several bypass forms. No in-the-wild exploitation is reported, and the CVE is not in CISA KEV as of 2026-12-03.

Does sanitizeFilter protect against this?

No. sanitizeFilter handles filter values, and sanitizeProjection handles the projection. The bypass is in the projection path, so a sanitizeFilter setting does not help.

Which versions are fixed?

Mongoose 8.24.10 and 9.12.2 fix the bypass, and later releases include the fix. The advisory lists 8.0.0 to 8.24.9 and 9.0.0 to 9.12.1 as affected.

Does the fix cover find() projections?

Yes. The patch changes the query path used by select(), find(filter, projection) and the projection option, and it adds tests for the bypass forms.

Find vulnerable Mongoose versions with Ostorlab

Ostorlab's software composition analysis inventories the open-source packages in your repositories and flags the versions an advisory marks as affected. Use it to find every copy of Mongoose earlier than 8.24.10 or 9.12.2, including transitive copies, before a user-controlled projection reaches a query.

References

  • Mongoose advisory GHSA-xfcm-rmv3-crmq, 2026-11-23: https://github.com/Automattic/mongoose/security/advisories/GHSA-xfcm-rmv3-crmq (checked December 3, 2026)
  • CVE-2026-142596 record: https://www.cve.org/CVERecord?id=CVE-2026-142596 (checked December 3, 2026)
  • Mongoose fix commit c369da4: https://github.com/Automattic/mongoose/commit/c369da407ee8bea907bb5af7bb94ce5deeb3e0e4 (checked December 3, 2026)
  • Mongoose fix commit c5483b7: https://github.com/Automattic/mongoose/commit/c5483b71438ececde3a272feef65e14666614093 (checked December 3, 2026)
  • Mongoose release 8.24.10: https://github.com/Automattic/mongoose/releases/tag/8.24.10 (checked December 3, 2026)
  • Mongoose release 9.12.2: https://github.com/Automattic/mongoose/releases/tag/9.12.2 (checked December 3, 2026)
  • Mongoose package page and weekly downloads: https://www.npmjs.com/package/mongoose (checked December 3, 2026)
  • CISA Known Exploited Vulnerabilities catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog (checked December 3, 2026)

Free scan

Scan your own app for free

or book a demo

Keep reading

Related articles

Browse the blog