CVE-2026-142595: Mongoose `sanitizeFilter` Bypass Vulnerability

MODERATE
Advisory Identifier: GHSA-25v4-hrwm-qj9f
CVSS 6.5
CWE-943
Published
Advisory Summary

CVE-2026-142595 is a MODERATE (CVSS 6.5) `sanitizefilter` bypass vulnerability (CWE-943: Improper Neutralization of Special Elements in Data Query Logic) affecting Mongoose libraries in the npm ecosystem. The issue involves `sanitizefilter` bypass via mongodb internal top-level query operators such as `$_internalschemaxor`. Remediation is available by upgrading affected packages to version 6.13.13, 7.8.14, 8.24.10, 9.12.2.

CVE-2026-142595 at a Glance

CVE Identifier CVE-2026-142595
GHSA Identifier GHSA-25v4-hrwm-qj9f
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-943: Improper Neutralization of Special Elements in Data Query Logic
Affected Product Mongoose
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.5

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

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

How to Fix CVE-2026-142595

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: 6.13.13
npm install mongoose@6.13.13
mongoose fixed: 7.8.14
npm install mongoose@7.8.14
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-142595, 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 6.13.13), 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-943: Improper Neutralization of Special Elements in Data Query Logic, where the product generates a query intended to access or manipulate data in a data store such as a database, but it does not neutralize or incorrectly neutralizes special elements that can modify the intended logic of the query. 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 Mongoose's `sanitizeFilter` option is meant to block query selector injection. Before this fix, it only refused four top-level operators by name: `$jsonSchema`, `$where`, `$expr` and `$text`. Any other top-level `$` operator was passed to MongoDB unchanged. That includes undocumented internal operators like `$_internalSchemaXor` and `$_internalSchemaCond`, which take sub-filters, and `sanitizeFilter` never inspected those sub-filters. An attacker who controls the keys of a query filter could use them to slip arbitrary query selectors like `$ne` or `$regex` past `sanitizeFilter`. ### Details With `sanitizeFilter` enabled, Mongoose: - wraps any object value containing `$` keys in `$eq`, so `{ password: { $ne: null } }` becomes `{ password: { $eq: { $ne: null } } }`; - recurses into `$and`, `$or` and `$nor`; - throws on `$jsonSchema`, `$where`, `$expr` and `$text` unless the value is wrapped in `mongoose.trusted()`. Every other top-level key starting with `$` was left alone. MongoDB accepts several internal match expressions at the top level that contain nested filters, for example: - `$_internalSchemaXor: [filter1, filter2]` - `$_internalSchemaCond: [ifFilter, thenFilter, elseFilter]` Because `sanitizeFilter` doesn't recurse into these, the nested filters can contain any query selector. The fix makes `sanitizeFilter` refuse every top-level key that starts with `$`, except `$and`, `$or` and `$nor`, which it recurses into, and values wrapped in `mongoose.trusted()`. Nested `$and`/`$or`/`$nor` filters are checked the same way. This also means `sanitizeFilter` now refuses: - **`$comment`:** a user-supplied comment ends up in MongoDB's profiler and logs. Use `Query.prototype.comment()` instead, which sets the comment outside the filter. - **`$sampleRate`, `$alwaysTrue`, `$alwaysFalse`, and top-level `$ref`/`$id`/`$db`.** A top-level `$`-prefixed field name can't be queried with a plain equality filter in the first place: MongoDB rejects `{ $userId: 42 }` with "unknown top level operator". So the fix doesn't prevent any query that previously worked. ### Proof of concept ```javascript 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`. ### Impact Applications are affected if they rely on `sanitizeFilter` to protect queries whose filter keys come from users. Common patterns are `Model.find(req.body)` and `Model.find({ ...req.query, owner: userId })`. An attacker can inject any query selector, which allows: - **Authentication bypass:** match a user record without knowing the password, as in the `$ne` example above. - **Data extraction:** use `$regex` as a boolean oracle to recover field values, such as password hashes or tokens, one character at a time. - **Unintended writes:** make `updateOne()`, `deleteMany()` and similar operations match documents the attacker shouldn't be able to target. Applications that build filters from individual values, like `{ username: req.body.username }`, are not affected. `sanitizeFilter` already wraps those values in `$eq`, so an attacker can't add top-level keys.

CVE-2026-142595 Affected Mongoose Versions

4 component(s)
Fixed Versions:
6.13.137.8.148.24.109.12.2
Product / Package Ecosystem Affected Versions Fixed Version
mongoose
npm
< 6.13.13
6.13.13
mongoose
npm
≥ 7.0.0
< 7.8.14
7.8.14
mongoose
npm
≥ 8.0.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-142595?
CVE-2026-142595 is a security vulnerability in Mongoose involving `sanitizeFilter` bypass via MongoDB internal top-level query operators such as `$_internalSchemaXor` under CWE-943: Improper Neutralization of Special Elements in Data Query Logic.
Which Mongoose versions are affected?
Affected versions include releases prior to 6.13.13, 7.8.14, 8.24.10, 9.12.2 across affected packages: mongoose.
What version fixes CVE-2026-142595?
Upgrading to 6.13.13, 7.8.14, 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 6.13.13, 7.8.14, 8.24.10, 9.12.2. Upgrade your dependency to 6.13.13, 7.8.14, 8.24.10, 9.12.2 or later.
What is the CVSS score of CVE-2026-142595?
CVE-2026-142595 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:N.
What CWE is associated with CVE-2026-142595?
CVE-2026-142595 is classified under CWE-943: Improper Neutralization of Special Elements in Data Query Logic (The product generates a query intended to access or manipulate data in a data store such as a database, but it does not neutralize or incorrectly neutralizes special elements that can modify the intended logic of the query.).
How can I check npm dependencies for CVE-2026-142595?
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-25v4-hrwm-qj9f",
  "modified" : "2026-12-04T00:05:04Z",
  "published" : "2026-12-04T00:05:04Z",
  "aliases" : [ "CVE-2026-142595" ],
  "summary" : "Mongoose: `sanitizeFilter` bypass via MongoDB internal top-level query operators such as `$_internalSchemaXor`",
  "details" : "### Summary\n\nMongoose's `sanitizeFilter` option is meant to block query selector injection. Before this fix, it only refused four top-level operators by name: `$jsonSchema`, `$where`, `$expr` and `$text`. Any other top-level `$` operator was passed to MongoDB unchanged. That includes undocumented internal operators like `$_internalSchemaXor` and `$_internalSchemaCond`, which take sub-filters, and `sanitizeFilter` never inspected those sub-filters. An attacker who controls the keys of a query filter could use them to slip arbitrary query selectors like `$ne` or `$regex` past `sanitizeFilter`.\n\n### Details\n\nWith `sanitizeFilter` enabled, Mongoose:\n\n- wraps any object value containing `$` keys in `$eq`, so `{ password: { $ne: null } }` becomes `{ password: { $eq: { $ne: null } } }`;\n- recurses into `$and`, `$or` and `$nor`;\n- throws on `$jsonSchema`, `$where`, `$expr` and `$text` unless the value is wrapped in `mongoose.trusted()`.\n\nEvery other top-level key starting with `$` was left alone. MongoDB accepts several internal match expressions at the top level that contain nested filters, for example:\n\n- `$_internalSchemaXor: [filter1, filter2]`\n- `$_internalSchemaCond: [ifFilter, thenFilter, elseFilter]`\n\nBecause `sanitizeFilter` doesn't recurse into these, the nested filters can contain any query selector.\n\nThe fix makes `sanitizeFilter` refuse every top-level key that starts with `$`, except `$and`, `$or` and `$nor`, which it recurses into, and values wrapped in `mongoose.trusted()`. Nested `$and`/`$or`/`$nor` filters are checked the same way. This also means `sanitizeFilter` now refuses:\n\n- **`$comment`:** a user-supplied comment ends up in MongoDB's profiler and logs. Use `Query.prototype.comment()` instead, which sets the comment outside the filter.\n- **`$sampleRate`, `$alwaysTrue`, `$alwaysFalse`, and top-level `$ref`/`$id`/`$db`.**\n\nA top-level `$`-prefixed field name can't be queried with a plain equality filter in the first place: MongoDB rejects `{ $userId: 42 }` with \"unknown top level operator\". So the fix doesn't prevent any query that previously worked.\n\n### Proof of concept\n\n```javascript\nconst User = mongoose.model('User', new mongoose.Schema({ username: String, password: String }));\nawait User.create({ username: 'admin', password: 'hunter2' });\n\n// Attacker controls the filter, e.g. `User.findOne(req.body)`\nconst login = filter => User.findOne(filter).setOptions({ sanitizeFilter: true });\n\n// Blocked as expected: `$ne` is wrapped in `$eq`, so no match\nawait login({ username: 'admin', password: { $ne: null } }); // null\n\n// Bypass: login without the password\nawait login({\n  username: 'admin',\n  $_internalSchemaXor: [{ password: { $ne: null } }, { $alwaysFalse: 1 }]\n}); // { username: 'admin', password: 'hunter2', ... }\n\n// Bypass: extract the password one character at a time\nawait login({\n  username: 'admin',\n  $_internalSchemaXor: [{ password: { $regex: '^h' } }, { $alwaysFalse: 1 }]\n}); // matches, so password starts with 'h'\n```\n\nTested against MongoDB 9.0.2. `$_internalSchemaCond` works the same way, and both operators also work inside `$and`/`$or`/`$nor`.\n\n### Impact\n\nApplications are affected if they rely on `sanitizeFilter` to protect queries whose filter keys come from users. Common patterns are `Model.find(req.body)` and `Model.find({ ...req.query, owner: userId })`. An attacker can inject any query selector, which allows:\n\n- **Authentication bypass:** match a user record without knowing the password, as in the `$ne` example above.\n- **Data extraction:** use `$regex` as a boolean oracle to recover field values, such as password hashes or tokens, one character at a time.\n- **Unintended writes:** make `updateOne()`, `deleteMany()` and similar operations match documents the attacker shouldn't be able to target.\n\nApplications that build filters from individual values, like `{ username: req.body.username }`, are not affected. `sanitizeFilter` already wraps those values in `$eq`, so an attacker can't add top-level keys.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongoose"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "6.13.13"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongoose"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "7.0.0"
      }, {
        "fixed" : "7.8.14"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "mongoose"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "8.0.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-25v4-hrwm-qj9f"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-142595"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/commit/34e76947cc8a9ceb916c233aec01aea060bc3dba"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/commit/3e5f4c8b30ef42db1ab9f2794dc77c95f21d3835"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/commit/4627d2fc572a943ee7afe26a1bcebe493dbd2508"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/commit/c6a4c95f9b15d81a352f2934c91b64ece583c2db"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Automattic/mongoose"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Automattic/mongoose/releases/tag/7.8.14"
  }, {
    "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-943" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-12-04T00:05:04Z",
    "nvd_published_at" : "2026-12-02T22:18:36Z"
  }
}