GHSA-RXM2-55PG-68Q6

Vulnerability from github – Published: 2026-12-03 00:29 – Updated: 2026-12-03 00:29
VLAI
Summary
Mongoose: Plain objects with a forged _bsontype bypass ObjectId and String casting, leaking and replaying data from other command
Details

Summary

From 6.3.5-6.13.12, Mongoose 6 decides whether a value is a BSON type by checking only its _bsontype property. A plain object such as {"_bsontype":"ObjectID","id":""} therefore passes the ObjectId cast. bson 4.x then writes no id bytes but still advances 12 bytes in its serialization buffer, so the value sent to MongoDB is whatever the previous command left at that offset. Request bodies, cookies and Express 4 query strings can all produce such an object. sanitizeFilter doesn’t catch it because it has no $ keys.

Details

lib/helpers/isBsonType.js returned true for any object whose _bsontype matched. This led to three problems:

  1. Queries by id replay another request’s id. findById(forged) sends the _id from the last command with the same layout, such as another request’s findById on the same collection. Likewise, findByIdAndDelete(forged) and findByIdAndUpdate(forged) act on the document another request just modified with findOneAndUpdate. This works with sanitizeFilter on.
  2. Stored ObjectIds leak command bytes. create(), $set and other writes store 12 bytes of earlier commands, such as filter values and updated fields. Anyone who can read the document can read those bytes. This happens in the default configuration.
  3. Forged regexes on String paths. {"_bsontype":"BSONRegExp","pattern":"^a","options":""} passes the String query cast and is sent as a regular expression, bypassing sanitizeFilter.

mongoose.isObjectIdOrHexString() also returns true for the forged object.

The fix makes isBsonType() ignore _bsontype when it is an own property. bson defines _bsontype on the prototype (except for the Timestamp class, which Mongoose does not check), so real bson values still pass.

Proof of concept

mongoose.set('sanitizeFilter', true);
const User = mongoose.model('User', new mongoose.Schema({ email: String, password: String }));
const Comment = mongoose.model('Comment', new mongoose.Schema({ post: mongoose.ObjectId }));
const alice = await User.create({ email: 'alice@example.com', password: 'S3cret' });
const forged = () => JSON.parse('{"_bsontype":"ObjectID","id":""}');

// 1. Query by id: replays the _id from the previous command
await User.findById(alice._id); // another request
await User.findById(forged()); // alice's document

// 2. String path: forged BSONRegExp is sent as a regex
await User.findOne({ password: JSON.parse('{"_bsontype":"BSONRegExp","pattern":"^S3","options":""}') }); // alice's document

// 3. Stored value (default config): stores 12 bytes of the previous command
await User.updateOne({ email: 'victim@example.com' }, { $set: { password: 'resetcode123' } }); // another request
const c = await Comment.create({ post: forged() });
(await Comment.findById(c._id)).post.id.toString('latin1'); // 'il\x00\x13\x00\x00\x00victi'

Impact

Applications on 6.3.5 to 6.13.12 are affected if they pass request values into queries or writes on ObjectId or String paths without checking that the values are primitive values. An attacker can:

  1. read, modify or delete documents that another request just accessed, even with sanitizeFilter, express-mongo-sanitize or mongo-sanitize enabled;
  2. read fragments of other requests’ database commands, such as emails, reset codes or API keys, by storing forged ObjectIds and reading them back;
  3. run regex matches against String fields despite sanitizeFilter.

Workaround: check that request values are strings, or use mongoose.isValidObjectId(), before passing them to Mongoose.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "npm",
        "name": "mongoose"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "6.3.5"
            },
            {
              "fixed": "6.13.13"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-142608"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-843"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-12-03T00:29:57Z",
    "nvd_published_at": null,
    "severity": "LOW"
  },
  "details": "### Summary\n\nFrom 6.3.5-6.13.12, Mongoose 6 decides whether a value is a BSON type by checking only its _bsontype property. A plain object such as {\"_bsontype\":\"ObjectID\",\"id\":\"\"} therefore passes the ObjectId cast. bson 4.x then writes no id bytes but still advances 12 bytes in its serialization buffer, so the value sent to MongoDB is whatever the previous command left at that offset. Request bodies, cookies and Express 4 query strings can all produce such an object. sanitizeFilter doesn\u2019t catch it because it has no $ keys.\n\n### Details\n\n`lib/helpers/isBsonType.js` returned true for any object whose `_bsontype` matched. This led to three problems:\n\n1. Queries by id replay another request\u2019s id. findById(forged) sends the `_id` from the last command with the same layout, such as another request\u2019s `findById` on the same collection. Likewise, `findByIdAndDelete(forged)` and `findByIdAndUpdate(forged)` act on the document another request just modified with `findOneAndUpdate`. This works with `sanitizeFilter` on.\n2. Stored ObjectIds leak command bytes. `create()`, `$set` and other writes store 12 bytes of earlier commands, such as filter values and updated fields. Anyone who can read the document can read those bytes. This happens in the default configuration.\n3. Forged regexes on String paths. `{\"_bsontype\":\"BSONRegExp\",\"pattern\":\"^a\",\"options\":\"\"}` passes the String query cast and is sent as a regular expression, bypassing sanitizeFilter.\n\n`mongoose.isObjectIdOrHexString()` also returns true for the forged object.\n\nThe fix makes `isBsonType()` ignore `_bsontype` when it is an own property. bson defines `_bsontype` on the prototype (except for the `Timestamp` class, which Mongoose does not check), so real bson values still pass.\n\n### Proof of concept\n\n```javascript\nmongoose.set(\u0027sanitizeFilter\u0027, true);\nconst User = mongoose.model(\u0027User\u0027, new mongoose.Schema({ email: String, password: String }));\nconst Comment = mongoose.model(\u0027Comment\u0027, new mongoose.Schema({ post: mongoose.ObjectId }));\nconst alice = await User.create({ email: \u0027alice@example.com\u0027, password: \u0027S3cret\u0027 });\nconst forged = () =\u003e JSON.parse(\u0027{\"_bsontype\":\"ObjectID\",\"id\":\"\"}\u0027);\n\n// 1. Query by id: replays the _id from the previous command\nawait User.findById(alice._id); // another request\nawait User.findById(forged()); // alice\u0027s document\n\n// 2. String path: forged BSONRegExp is sent as a regex\nawait User.findOne({ password: JSON.parse(\u0027{\"_bsontype\":\"BSONRegExp\",\"pattern\":\"^S3\",\"options\":\"\"}\u0027) }); // alice\u0027s document\n\n// 3. Stored value (default config): stores 12 bytes of the previous command\nawait User.updateOne({ email: \u0027victim@example.com\u0027 }, { $set: { password: \u0027resetcode123\u0027 } }); // another request\nconst c = await Comment.create({ post: forged() });\n(await Comment.findById(c._id)).post.id.toString(\u0027latin1\u0027); // \u0027il\\x00\\x13\\x00\\x00\\x00victi\u0027\n```\n\n### Impact\n\nApplications on 6.3.5 to 6.13.12 are affected if they pass request values into queries or writes on ObjectId or String paths without checking that the values are primitive values. An attacker can:\n\n1. read, modify or delete documents that another request just accessed, even with sanitizeFilter, express-mongo-sanitize or mongo-sanitize enabled;\n2. read fragments of other requests\u2019 database commands, such as emails, reset codes or API keys, by storing forged ObjectIds and reading them back;\n3. run regex matches against String fields despite sanitizeFilter.\n\nWorkaround: check that request values are strings, or use `mongoose.isValidObjectId()`, before passing them to Mongoose.",
  "id": "GHSA-rxm2-55pg-68q6",
  "modified": "2026-12-03T00:29:57Z",
  "published": "2026-12-03T00:29:57Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/Automattic/mongoose/security/advisories/GHSA-rxm2-55pg-68q6"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Automattic/mongoose/commit/61d7d7829716d4728d250aa0f0c712f318cf2aad"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/Automattic/mongoose"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Mongoose: Plain objects with a forged _bsontype bypass ObjectId and String casting, leaking and replaying data from other command"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline

Sightings and recorded dates, grouped by day · UTC

JSON
How durations are calculated

Following the VTEM framework (Black Hat USA 2015), time to patch starts when the vendor or a coordinator was informed, total time to patch at discovery, and disclosure to patch at public disclosure; vendor response time runs from the report to its acknowledgement. Time to exploit and time unpatched start at the earliest discovery or report, falling back to public disclosure. Unpatched time ends at the first recorded patch, or the calculation time when no patch is recorded. Exploitation to patch shows the interval between those two events; a published proof of concept is a public exploit, not exploitation. The method is described in a publication.

Each result shows its source dates. A negative interval means the end event came first; when date-only inputs leave the order open, the result says so. Date-only inputs are approximate. The earliest evidence wins: KEV report dates and sightings are labelled as such. Records describing another vulnerability are listed but never calculated from, and a PoC alone does not establish exploitation. Missing patch evidence does not prove that no patch exists. Filters below change the event list only.

Events included in the timeline

Loading timeline…


    Loading…

    Loading…

    Loading…

    Related by attack behaviour

    Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.