---
id: "CVE-2026-118581"
kind: "vulnerability"
aliases: ["CVE-2026-118581"]
title: "MongoDB Java Driver: BSON raw documents accepted with mismatched length, altering commands"
severity: "medium"
cvss: 6.9
epss: null
exploited: false
status: "open"
category: "package"
products: []
ecosystems: []
tags: ["backend", "java", "mongodb", "package"]
not_affected_if: ["no-untrusted-raw-bson", "trusted-input-only"]
published_at: "2026-10-28T17:18:26+00:00"
first_seen_at: "2026-10-28T17:34:09+00:00"
updated_at: "2026-10-28T17:34:32+00:00"
sources: [{"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-118581", "first_seen_at": "2026-10-28T17:34:09+00:00"}]
---

# MongoDB Java Driver: BSON raw documents accepted with mismatched length, altering commands

The MongoDB Java Driver's BSON encoder does not check that a raw document's declared length matches the bytes supplied. An application that wraps untrusted raw bytes in such a document can let an attacker append fields to the command the database executes, changing what data is read or written under the application's credentials.

_Summary, check and fix written by a model from the sources; labelled as such._

## How to check

- Search the project for uses of `RawBsonDocument` or `RawBsonDocument.parse` built from untrusted or user-influenced bytes that are embedded in database commands
- Check the driver version in the build file (for example `mongodb-driver-sync` or `mongo-java-driver` in pom.xml or build.gradle) against the fixed release, which the sources do not name: unknown

## Fix

- Upgrade the MongoDB Java Driver (`mongodb-driver-sync`, `mongodb-driver-core`) to the fixed release listed in the advisory: unknown
- Until upgraded, do not embed untrusted raw BSON bytes directly in commands; validate or rebuild them as typed documents first

## Timeline

- 2026-10-28T17:34:09+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-118581

## From the sources

A BSON encoding component of the MongoDB Java Driver does not verify that an externally supplied raw document's self-declared length agrees with the extent of the byte range it is given before that range is copied into an outgoing database command. An application that wraps untrusted raw bytes in such a document and uses it as part of a command can therefore emit a structurally inconsistent message, causing the database to interpret attacker-supplied trailing content as additional fields of the surrounding command. No authentication to the driver or database is required beyond the ability to influence those bytes through the victim application, and no user interaction is needed. The result is unintended modification of the command actually executed, which can alter the data read or written under the application's credentials.

---

_Free to read at a human pace. An API with keys and an MCP server are in preparation; early access: hello@infrastack.ai_
