# GHSA-H8VQ-FPQM-595X: RUBY-3936 ExtJSON.parse accepts a non-ObjectId $dbPointer $id, emitting a malformed DBPointer that reframes the document

- Database: GitHub
- Severity: CVSS 7.5 (High)
- Published: 2026-11-25
- Modified: 2026-11-25

## Tracked as

- [CVE-2026-135226](https://cve.now/CVE-2026-135226.md): MongoDB Ruby Driver type confusion in BSON Extended JSON DBPointer parsing

## Affected versions

- bson (RubyGems): from 4.8.0, through 5.2.0

## Description

### Summary
BSON::ExtJSON.parse validated only the keys of a $dbPointer value ($ref and $id), never their types. An $id supplied as $binary parsed to a BSON::Binary, and BSON::DbPointer#to_bson serialized the id by duck typing, writing an int32 length, a subtype byte and an arbitrary payload where the DBPointer wire format requires a string followed by exactly 12 raw bytes. The enclosing document's length prefix is stamped after serialization and therefore stays consistent, so nothing downstream can detect the mismatch: every conforming parser, including this library's own DbPointer.from_bson, consumes 12 bytes as the ObjectId and reinterprets the remaining attacker bytes as further elements of the document. An application that parses untrusted Extended JSON and then writes the parsed value as BSON emits a document containing fields it never set, and can lose fields that it did set. Affected: bson 4.8.0 through 5.2.0 and current master; fixed by RUBY-3936.

### Proof of Concept
Proof of concept
The input is a single $dbPointer whose $id is a generic binary whose payload is chosen by the attacker. In the payload below, the Binary header (4-byte length 21, subtype 0, then 7 zero bytes of filler) exactly fills the 12 bytes the reader consumes as the ObjectId; the next bytes are a well-formed BSON int32 element named injected with value 42:

```ruby
json = %({"a":{"$dbPointer":{"$ref":"coll","$id":{"$binary":{"base64":"AAAAAAAAABBpbmplY3RlZAAqAAAA","subType":"00"}}}}})
parsed = BSON::ExtJSON.parse(json)
BSON::Document.from_bson(BSON::ByteBuffer.new({ 'a' => parsed['a'] }.to_bson.to_s))
# => {"a"=>#<BSON::DbPointer ... @ref="coll", @id=BSON::ObjectId('150000000000000000000000')>, "injected"=>42}
```

The parsed value is a BSON::DbPointer with a 21-byte BSON::Binary id. The serialized document is 43 bytes and its length prefix (43) matches its size, so it is a valid BSON document by construction; reading it back yields the pointer plus "injected" => 42, a field the application never wrote. The same works for a pointer nested inside a subdocument.

When application fields follow the value, a different payload replaces them instead of adding to them: with {"a" => pointer, "b" => "secret", "c" => 1}, a payload declaring a string element whose length spans the trailing bytes reads back as {"a" => pointer, "injected" => "\x02b\x00\x07\x00\x00\x00secret\x00\x10c\x00\x01\x00\x00"}, and b and c are gone.

### Impact
An application that parses untrusted Extended JSON and serializes the result writes documents whose field set is chosen by the attacker, which is persistent document forgery, and the same reframing applies to any BSON the application serializes, including a query filter built from parsed Extended JSON, where forged sibling fields change which documents match.

## References

- https://github.com/mongodb/bson-ruby/security/advisories/GHSA-h8vq-fpqm-595x

Page: https://cve.now/GHSA-H8VQ-FPQM-595X

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
