PyMongo: PYTHON-5986 Host injection in PyMongo connection string parsing via percent-encoded delimiters
What fixes it
- 4.18.2pymongo, pipGitHub
- 4.18.2Python DriverCVE List
- 4.18.2pymongo, PyPIOSV
pip install "pymongo>=4.18.2"
A fixed version on one release line is not the upgrade target for every line. Check your exact version and any vendor backports.
Description
Summary
PyMongo percent-decoded the entire host section of a connection string before splitting it into individual host:port entries. A percent-encoded , or : in a hostname therefore decoded into a real delimiter, injecting an additional attacker-chosen host and port into the client's seed list.
Impact
An application that interpolates untrusted input into a MongoDB connection string -- for example, a tenant name or hostname fragment taken from a request -- could be made to add an attacker-controlled server to the seed list. Because %2C and %3A survive most URL-safety checks and only become delimiters inside PyMongo's parser, input that looks like a single hostname to the application becomes two hosts to the driver. The client may then perform topology discovery and authentication against the attacker's host, exposing credentials, or route operations to it.
Unix domain socket paths, the only host identifiers that legitimately require percent-encoding, are not affected.
Patches
Fixed in PyMongo 4.18.2. Percent-decoding was moved into split_hosts and now applies only to Unix domain socket paths, identified by an unescaped .sock suffix before decoding, and only after splitting on ,.
Workarounds
Do not interpolate untrusted input into the host portion of a connection string. If unavoidable, reject or percent-decode-and-validate the value before building the URI.
Details
The decoding was introduced in PyMongo 3.5.0 (PYTHON-1282), where unquote_plus was applied to the whole host section in _validate_uri and, later, _parse_srv, before the string was split on , and :.
Text from GitHub Advisory Database
Affected versions 53
- pymongo, pip>= 3.5.0, <= 4.18.1GitHub
- Python Driveraffected: all versions before 4.18.2CVE List
- pymongo, PyPIfrom 3.5.0, fixed in 4.18.2OSV
- pymongo, PyPI3.10.0OSV
- pymongo, PyPI3.10.1OSV
- pymongo, PyPI3.11.0OSV
- pymongo, PyPI3.11.1OSV
- pymongo, PyPI3.11.2OSV
- pymongo, PyPI3.11.3OSV
- pymongo, PyPI3.11.4OSV
- pymongo, PyPI3.12.0OSV
- pymongo, PyPI3.12.1OSV
- pymongo, PyPI3.12.2OSV
- pymongo, PyPI3.12.3OSV
- pymongo, PyPI3.13.0OSV
- pymongo, PyPI3.5.0OSV
- pymongo, PyPI3.5.1OSV
- pymongo, PyPI3.6.0OSV
- pymongo, PyPI3.6.1OSV
- pymongo, PyPI3.7.0OSV
- pymongo, PyPI3.7.1OSV
- pymongo, PyPI3.7.2OSV
- pymongo, PyPI3.8.0OSV
- pymongo, PyPI3.9.0OSV
- pymongo, PyPI4.0OSV
- pymongo, PyPI4.0.1OSV
- pymongo, PyPI4.0.2OSV
- pymongo, PyPI4.1.0OSV
- pymongo, PyPI4.1.1OSV
- pymongo, PyPI4.10.0OSV
- pymongo, PyPI4.10.1OSV
- pymongo, PyPI4.11OSV
- pymongo, PyPI4.11.1OSV
- pymongo, PyPI4.11.2OSV
- pymongo, PyPI4.11.3OSV
- pymongo, PyPI4.12.0OSV
- pymongo, PyPI4.12.1OSV
- pymongo, PyPI4.13.0OSV
- pymongo, PyPI4.13.0.dev0OSV
- pymongo, PyPI4.13.1OSV
- pymongo, PyPI4.13.2OSV
- pymongo, PyPI4.14.0OSV
- pymongo, PyPI4.14.1OSV
- pymongo, PyPI4.15.0OSV
- pymongo, PyPI4.15.1OSV
- pymongo, PyPI4.15.2OSV
- pymongo, PyPI4.15.3OSV
- pymongo, PyPI4.15.4OSV
- pymongo, PyPI4.15.5OSV
- pymongo, PyPI4.16.0OSV
- pymongo, PyPI4.16.0.dev0OSV
- pymongo, PyPI4.17.0OSV
- pymongo, PyPI4.18.0OSV
References 9
- github.com/mongodb/mongo-python-driver/commit/1e7a56db4649b14c4c9a6ac20aa4a8d0d1bb238aFixvia GitHub
- github.com/mongodb/mongo-python-driver/commit/640dd2383a1a2fb1a10e5222d50ebc0b22a61bd7Fixvia GitHub
- github.com/mongodb/mongo-python-driver/blob/4.18.2/doc/changelog.rstFixvia CVE List
- github.com/mongodb/mongo-python-driver/releases/tag/4.18.2Fixvia CVE List
- github.com/mongodb/mongo-python-driver/security/advisories/GHSA-vp6j-j7w5-5xjjAdvisoryvia CVE List
- github.com/advisories/GHSA-vp6j-j7w5-5xjjAdvisoryvia GitHub
- nvd.nist.gov/vuln/detail/CVE-2026-96748Referencevia GitHub
- github.com/mongodb/mongo-python-driver/pull/3066Referencevia GitHub
- mongodb.com/community/forums/t/pymongo-4-18-2-released/343732Referencevia GitHub