CVE-2026-106435: MongoDB Python Driver: Out-of-bounds read in BSON decoding via a malformed Regex element
PyMongo 3.9.0 through 4.18.2 can crash the Python process when its C extension decodes a crafted BSON Regex element from an mmap or array buffer. The decoder reads past the end of the buffer and may hit unmapped memory. The impact is a denial of service. Upgrade to pymongo 4.18.3.
Published Oct 27, 2026 · Analysis Nov 1, 2026
What an attacker can do
The C extension BSON decoder scans the pattern and flags strings of a Regex element with strlen before it checks how much of the document is left. A truncated Regex element therefore makes strlen run past the end of the caller buffer. Bytes and bytearray buffers end with a NUL, so strlen stops and the decoder raises InvalidBSON at worst. mmap and array buffers have no NUL sentinel, so the read can cross into unmapped memory and kill the process with an uncatchable SIGSEGV.
The attacker needs the application to pass untrusted BSON to bson.decode or bson.decode_all from such a buffer, for example a service that memory-maps uploaded BSON files or reads dumps from shared storage. The out-of-bounds bytes are never returned as content, so nothing leaks. The effect is availability only.
The driver own network transport and pure-Python installs, which lack the C extension, are not affected. A crash from SIGSEGV skips Python exception handlers, so a worker or the whole service restarts and a repeating input can keep it down.
Who is affected
Affected: pymongo from 3.9.0 up to and including 4.18.2, when the C extension is loaded and the app decodes untrusted BSON from mmap or array buffers. Check the version and whether the extension is present:
pip show pymongo
python -c "import bson; print(bson.has_c())"If has_c() prints False, you run the pure-Python decoder and this flaw does not apply.
pymongo
- Ecosystem
- PyPI
- Affected
- >= 3.9.0, <= 4.18.2
- Fixed in
- 4.18.3
- Check
pip show pymongo
How to fix it
Upgrade to pymongo 4.18.3.
pip install --upgrade pymongo==4.18.3In the fixed release, malformed Regex elements raise InvalidBSON on every accepted buffer type, and valid documents decode as before. The advisory workaround: decode untrusted BSON only from NUL-terminated buffers, bytes or bytearray, and copy mmap input first, for example with bytes(mm[:size]).
How to tell if you were hit
Look for worker processes that exit with signal 11 or a segmentation fault shortly after reading BSON input, with core dumps or kernel log lines naming the Python binary. Search your code for bson.decode and bson.decode_all calls that receive an mmap or array object. After upgrading, bad input shows up as InvalidBSON exceptions, which you can log and alert on.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
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]).
Questions
- Does the normal MongoDB connection path expose me?
No. The advisory says the driver own transport is not affected. The risk is code that calls bson.decode or bson.decode_all on untrusted data held in mmap or array buffers.
- Can this leak memory contents?
No. The advisory says the out-of-bounds bytes are never returned as content. The impact is availability only.
- Which version fixes CVE-2026-106435?
pymongo 4.18.3. Versions from 3.9.0 through 4.18.2 are affected when the C extension is loaded.
References
Read for this analysis:
- 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/releases/tag/4.18.3
- https://jira.mongodb.org/browse/PYTHON-6110
- https://github.com/advisories/GHSA-98qm-wvgf-w4cf
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More PyPI vulnerabilities
All PyPI entriesCVE-2026-88029
pymongo: PYTHON-5994 Use exact match for file ID in GridFS delete methods
medium6.1Oct 5, 2026CVE-2026-96747
PyMongo: PYTHON-5990 Forced Unix domain socket connection via a .sock KMS endpoint in client-side field level encryption
medium5.0Oct 5, 2026CVE-2026-96748
PyMongo: PYTHON-5986 Host injection in PyMongo connection string parsing via percent-encoded delimiters
high6.5Oct 5, 2026CVE-2026-96749
PyMongo: PYTHON-5996 Heap out-of-bounds write via signed size overflow in BSON document encoding
high8.4Oct 5, 2026CVE-2024-5629
PyMongo Out-of-bounds Read in the bson module
medium4.7Jun 5, 2024
