---
id: "CVE-2026-106435"
kind: "vulnerability"
aliases: ["CVE-2026-106435", "GHSA-98qm-wvgf-w4cf"]
title: "MongoDB Python Driver: Out-of-bounds read in BSON decoding via a malformed Regex element"
severity: "high"
cvss: 5.9
epss: 0.00093
exploited: false
status: "open"
category: "package"
products: [{"name": "pymongo", "fixed": ["4.18.3"], "affected": ">= 3.9.0, <= 4.18.2", "ecosystem": "pypi"}, {"name": "mongodb python driver", "fixed": ["4.18.3"], "affected": "< 4.18.3", "ecosystem": "vendor"}]
ecosystems: ["pypi", "vendor"]
tags: ["bson", "cwe-125", "mongodb", "package", "pymongo", "python"]
not_affected_if: ["nul-terminated-buffers", "pure-python-install", "trusted-input-only"]
published_at: "2026-10-08T21:17:51+00:00"
first_seen_at: "2026-10-27T15:39:16+00:00"
updated_at: "2026-10-27T16:03:35+00:00"
sources: [{"source": "ghsa", "url": "https://github.com/advisories/GHSA-98qm-wvgf-w4cf", "first_seen_at": "2026-10-27T15:39:16+00:00"}, {"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-106435", "first_seen_at": "2026-10-27T16:03:35+00:00"}]
---

# MongoDB Python Driver: Out-of-bounds read in BSON decoding via a malformed Regex element

PyMongo's C BSON decoder reads past the end of the caller's buffer when a Regex element is truncated, because it scans for a NUL terminator before checking the remaining length. An attacker who can supply untrusted BSON decoded from mmap or array buffers can crash the process with SIGSEGV, a denial of service; the out-of-bounds bytes are not returned.

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

## Affected

- pypi:pymongo affected >= 3.9.0, <= 4.18.2 fixed 4.18.3
- vendor:mongodb python driver affected < 4.18.3 fixed 4.18.3

## How to check

- Run `pip show pymongo` and confirm the installed version is `4.18.2` or lower, which is affected when the C extension is loaded.
- Search the codebase for `bson.decode` or `bson.decode_all` calls that take mmap or array input from untrusted sources.

## Fix

- Upgrade PyMongo to `4.18.3` or later.
- Until upgraded, decode untrusted BSON only from `bytes` or `bytearray`, and copy mmap input first, e.g. `bytes(mm[:size])`.

## Timeline

- 2026-10-27T15:39:16+00:00 ghsa https://github.com/advisories/GHSA-98qm-wvgf-w4cf
- 2026-10-27T16:03:35+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-106435

## From the sources

### Impact
The C extension's BSON decoder scans a Regex element's pattern and flags strings with strlen before checking the document's remaining length, so a crafted truncated Regex element can read past the end of the caller's buffer. bson.decode and bson.decode_all accept mmap and array buffers, which carry no NUL sentinel; the read can cross into unmapped memory and kill the process with an uncatchable SIGSEGV. Any application decoding untrusted BSON from such buffers is affected — impact is availability only, since the out-of-bounds bytes are never returned as content. NUL-terminated buffers (bytes, bytearray) raise `InvalidBSON` at worst; the driver's own transport and pure-Python installs are not affected. All releases through 4.18.2 are affected when the C extension is loaded.

### Patches
Fixed in PyMongo 4.18.3. Malformed Regex elements now raise InvalidBSON on every accepted buffer type; valid documents decode unchanged.

###  Workarounds
Decode untrusted BSON only from NUL-terminated buffers — bytes or bytearray — and copy mmap input first, e.g. bytes(mm[:size]).

---

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