Summary
Mongoose: Discriminator key values matching inherited properties (e.g. __t: 'constructor') bypass schema casting and can poison collections
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 globalObjectfunction. Mongoose then callsnew 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
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
// 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
TypeErroror a non-document object returned to application code. Ways in includeModel.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 tobulkWrite()insertOnewithskipValidation: true, the raw object is stored without casting orstrictfiltering. Fields the schema would normally strip are persisted, such as anisAdminthat 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.
An object is accessed using a type that is incompatible with its actual type, causing the runtime to interpret memory incorrectly. Typical impact: memory safety violations, unexpected behavior, or code execution.
CVE-2026-125116 has a CVSS score of 4.8 (Medium). The vector is network-reachable, no privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (6.13.12, 7.8.13, 8.24.7, 9.11.4); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
mongoose to 6.13.12 or later; mongoose to 7.8.13 or later; mongoose to 8.24.7 or later; mongoose to 9.11.4 or later
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is CVE-2026-125116? CVE-2026-125116 is a medium-severity type confusion vulnerability in mongoose (npm), affecting versions < 6.13.12. It is fixed in 6.13.12, 7.8.13, 8.24.7, 9.11.4. An object is accessed using a type that is incompatible with its actual type, causing the runtime to interpret memory incorrectly.
- How severe is CVE-2026-125116? CVE-2026-125116 has a CVSS score of 4.8 (Medium). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which versions of mongoose are affected by CVE-2026-125116? mongoose (npm) versions < 6.13.12 is affected.
- Is there a fix for CVE-2026-125116? Yes. CVE-2026-125116 is fixed in 6.13.12, 7.8.13, 8.24.7, 9.11.4. Upgrade to this version or later.
- Is CVE-2026-125116 exploitable, and should I be worried? Whether CVE-2026-125116 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2026-125116 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2026-125116?
- Upgrade
mongooseto 6.13.12 or later - Upgrade
mongooseto 7.8.13 or later - Upgrade
mongooseto 8.24.7 or later - Upgrade
mongooseto 9.11.4 or later
- Upgrade