# CVE-2026-125116: Mongoose: Discriminator key values matching inherited properties (e.g. \_\_t: 'constructor') bypass schema casting and can poison collections

- **Severity:** MEDIUM 4.8
- **CVSS:** 4.8 (v3.1, GitHub) `CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:L`
- **CVSS metrics:** Attack vector: Network; Attack complexity: High; Privileges required: None; User interaction: None; Scope: Unchanged; Confidentiality impact: None; Integrity impact: Low; Availability impact: Low
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Remote, no login needed
- **EPSS:** 0.51% (percentile 37, 2026-11-28)
- **CWE:** CWE-843
- **Aliases:** GHSA-wr5m-5jph-8m96
- **Published:** 2026-11-10T20:57:18.000Z
- **Modified:** 2026-11-10T20:57:19.000Z

## Who should check

- Projects that depend on npm package mongoose (\< 6.13.12)

## Description

\#\#\# Summary

Mongoose chooses which discriminator model or schema to use by looking up the discriminator key value (\`\_\_t\` by default) in a plain object of registered discriminators, for example \`Model.discriminators\[doc.\_\_t\]\`. That value comes from user documents and query filters. Because the lookup did not check own properties, a value that names a property inherited from \`Object.prototype\` resolves to that inherited value instead of a discriminator. Examples are \`'constructor'\`, \`'toString'\` and \`'hasOwnProperty'\`.

- \`\_\_t: 'constructor'\` resolves to the global \`Object\` function. Mongoose then calls \`new Object(doc)\`, which returns the raw user object where a Mongoose document is expected.
- \`\_\_t: 'toString'\` and similar names resolve to built-in functions that throw when used as a constructor or schema.

The most serious effect: through \`bulkWrite()\` \`insertOne\` with \`skipValidation: true\`, the raw user object is stored as-is, without schema casting or \`strict\` filtering. After that, every query that returns the stored document throws, until the document is removed from the database.

\#\#\# Details

The registries that hold discriminators are plain objects: \`Model.discriminators\`, \`schema.discriminators\`, and the embedded discriminator registries on document arrays and single nested subdocuments. Several code paths indexed them directly with a value taken from the document or filter:

\| Code path \| Input \|
\|---\|---\|
\| Model constructor (\`new Model(doc)\`) \| document \|
\| \`Model.create()\`, \`insertMany()\`, \`bulkWrite()\`, \`bulkSave()\` \| documents \|
\| Hydrating query results (\`find()\`, \`findOne()\`, etc.) and \`Model.hydrate()\` \| stored documents \|
\| Casting query filters, including flat paths such as \`'events.\_\_t'\` and \`$elemMatch\` \| query filter \|
\| Casting updates and array filters \| update filter, \`arrayFilters\` \|
\| Document array \`push()\` / \`create()\`, document array and single nested casting \| subdocuments \|
\| Populate on embedded discriminators \| stored subdocuments \|

\`getDiscriminatorByValue()\` already iterated the registry's own keys safely. But most callers tried the direct lookup first and only fell back to it afterwards, so a truthy inherited value took precedence.

The lookups only read inherited properties. They do not write to \`Object.prototype\` or any other shared object, and they do not change in-memory state that affects other requests. This is NOT a prototype pollution vector.

\#\#\# Proof of concept

\`\`\`js
const mongoose = require('mongoose');

const Base = mongoose.model('Base', new mongoose.Schema({ name: String, age: Number }));
Base.discriminator('Child', new mongoose.Schema({ extra: String }));

// Type confusion: the "document" is the raw input object
const doc = new Base({ name: 'x', \_\_t: 'constructor' });
console.log(doc instanceof mongoose.Document); // false
\`\`\`

\`\`\`js
// Schema bypass and persistent poison document via bulkWrite + skipValidation
await Base.bulkWrite(\[{
  insertOne: { document: { name: 'x', age: 'not a number', notInSchema: true, \_\_t: 'constructor' } }
}\], { skipValidation: true });
// Stored verbatim: { age: 'not a number', notInSchema: true, \_\_t: 'constructor', ... }

await Base.find(); // throws: Cannot read properties of undefined (reading 'eachPath')
\`\`\`

\#\#\# Impact

- \*\*Crashing the request.\*\* An attacker who controls the discriminator key of a document or filter can make the request fail. In most code paths that sent the value, this means a \`TypeError\` or a non-document object returned to application code. Ways in include \`Model.create(req.body)\`, \`new Model(req.body)\`, \`Model.find(req.query)\`-style filters, and pushing user input onto embedded discriminator arrays. The effect is limited to the request carrying the value.
- \*\*Schema bypass on \`bulkWrite({ skipValidation: true })\`.\*\* When an application passes untrusted documents to \`bulkWrite()\` \`insertOne\` with \`skipValidation: true\`, the raw object is stored without casting or \`strict\` filtering. Fields the schema would normally strip are persisted, such as an \`isAdmin\` that isn't in the schema. Fields with wrong types are also persisted.
- \*\*Persistent denial of service for queries.\*\* A stored document with such a discriminator key value makes hydration throw. Every query that returns that document fails, for all users, until the document is deleted directly in the database. Besides the \`bulkWrite()\` path above, the document can get into the collection through another application, the raw MongoDB driver, or any other writer that does not go through Mongoose casting.

This issue doesn't let an attacker modify \`Object.prototype\`, built-in functions, schemas or other shared in-memory state. The schema bypass requires the application to opt in to \`skipValidation\` with untrusted input.

## Affected and fixed versions

- npm `mongoose`: affected \< 6.13.12; fixed 6.13.12, 7.8.13, 8.24.7, 9.11.4 (ghsa)

## Technologies

npm packages

## Mitigation

- Upgrade mongoose to one of 6.13.12, 7.8.13, 8.24.7, 9.11.4 (or later in the same release line).

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2026-125116. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2026-125116.md
Affected: mongoose < 6.13.12
Fixed in: 6.13.12, 7.8.13, 8.24.7, 9.11.4

Steps:
1. Search this machine and project for mongoose (npm): dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2026-125116 being exploited?

There is no confirmed exploitation: CVE-2026-125116 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.51% chance of exploitation in the next 30 days (as of 2026-11-28).

### How serious is CVE-2026-125116?

Medium: CVSS 4.8 (v3.1, scored by GitHub). Remote, no login needed. The attack needs conditions outside the attacker's control, which makes it harder.

### Which versions are affected by CVE-2026-125116?

mongoose \< 6.13.12.

### Is there a fix for CVE-2026-125116?

Yes. Fixed in 6.13.12, 7.8.13, 8.24.7, 9.11.4. Upgrade mongoose to one of 6.13.12, 7.8.13, 8.24.7, 9.11.4 (or later in the same release line).

### How do I check if I'm affected by CVE-2026-125116?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- vendor: <https://github.com/Automattic/mongoose/security/advisories/GHSA-wr5m-5jph-8m96>
- patch: <https://github.com/Automattic/mongoose/commit/0ecd8040d9b446f36535d79938c130c800f91766>
- patch: <https://github.com/Automattic/mongoose/commit/18afab75bea861f625b7c5b54635c84567ec566c>
- patch: <https://github.com/Automattic/mongoose/commit/390453c8ce1b36b6cfd1e63432a910da1f3d81d5>
- patch: <https://github.com/Automattic/mongoose/commit/8cee51beead554df1f3d05645edb439c69eb2a9b>
- patch: <https://github.com/Automattic/mongoose/commit/b26c43554233134ea978c5852babe13be858b2cf>
- patch: <https://github.com/Automattic/mongoose/commit/b68f90734b50cd22c89a669c8ca1469d7234b296>
- other: <https://nvd.nist.gov/vuln/detail/CVE-2026-125116>
- other: <https://github.com/Automattic/mongoose/releases/tag/6.13.12>
- other: <https://github.com/Automattic/mongoose/releases/tag/7.8.13>
- other: <https://github.com/Automattic/mongoose/releases/tag/8.24.7>
- other: <https://github.com/Automattic/mongoose/releases/tag/9.11.4>
- other: <https://github.com/advisories/GHSA-wr5m-5jph-8m96>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- GitHub Advisory Database: CC-BY 4.0 <https://github.com/advisories/GHSA-wr5m-5jph-8m96> (license: <https://creativecommons.org/licenses/by/4.0/>)
- FIRST EPSS: EPSS scores by FIRST <https://www.first.org/epss/>

HTML: <https://flawdb.com/CVE-2026-125116> · JSON: <https://flawdb.com/api/v1/entries/CVE-2026-125116>
