MongoDB Python Driver: Out-of-bounds read in BSON decoding via a malformed Regex element
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.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| Python (PyPI) | pymongo | >= 3.9.0, < 4.18.3 | 4.18.3 |
References
- https://github.com/mongodb/mongo-python-driver/security/advisories/GHSA-98qm-wvgf-w4cf
- https://nvd.nist.gov/vuln/detail/CVE-2026-106435
- https://github.com/mongodb/mongo-python-driver/pull/3109
- https://github.com/mongodb/mongo-python-driver/commit/bb8d4e195275e75bd94ebeffb53cc747d357fcf4
- https://github.com/mongodb/mongo-python-driver
- https://github.com/mongodb/mongo-python-driver/releases/tag/4.18.3
- https://jira.mongodb.org/browse/PYTHON-6110
- 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
- 2017: 0
- 2018: 0
- 2019: 0
- 2020: 0
- 2021: 0
- 2022: 0
- 2023: 0
- 2024: 1
- 2025: 0
- 2026: 5
earlier: 1
-
MongoDB Python Driver: Out-of-bounds read in BSON decoding via a malformed Regex element this entry
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.