High

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

  • Disclosed: 27.10.2026
  • Updated: 01.11.2026 10:00

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]).

What to do

Upgrade to PyMongo 4.18.3 or later. If upgrading is not immediately possible, decode untrusted BSON exclusively from NUL-terminated buffers (bytes or bytearray), copying mmap input first (e.g. bytes(mm[:size])).

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) pymongo >= 3.9.0, < 4.18.3 4.18.3

References

CVSS score -
CVSS vector
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
Weakness (CWE)
CWE-125
Platform
Python (PyPI)
Package
pymongo
Disclosed
27.10.2026
Updated
01.11.2026 10:00

Sources and licenses · Edited or translated by DockRay; source rights and applicable licenses are retained.

OSV / GitHub Advisory Database - GHSA-98qm-wvgf-w4cf - CC BY 4.0

Vulnerability history: pymongo

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
7
First → latest
08.2013 10.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • High 3
  • Medium 4

Disclosures per year

  1. 2017: 0
  2. 2018: 0
  3. 2019: 0
  4. 2020: 0
  5. 2021: 0
  6. 2022: 0
  7. 2023: 0
  8. 2024: 1
  9. 2025: 0
  10. 2026: 5

earlier: 1

  1. MongoDB Python Driver: Out-of-bounds read in BSON decoding via a malformed Regex element this entry
    High CVE-2026-106435 >= 3.9.0, < 4.18.3 4.18.3
  2. Medium · 4.7 CVE-2024-5629 < 4.6.3 4.6.3

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.