python-ldap has sanitization bypass in ldap.filter.escape_filter_charsGHSA-r7r6-cc7p-4v5m
Fix: python-ldap/python-ldap@3957526GHSA-r7r6-cc7p-4v5m is a CWE-75 vulnerability in python-ldap. A fix is available for python-ldap — see the affected versions and patch details below.
Exploitation Status
Proof-of-concept exploit code exists
- CISA’s SSVC triage found public proof-of-concept exploit code for this CVE, though no confirmed active exploitation.
Exploitation and automatability from CISA’s SSVC triage for GHSA-r7r6-cc7p-4v5m.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
Real-World Exposure
python-ldapReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
Description
Summary
The sanitization method ldap.filter.escape_filter_chars can be tricked to skip escaping of special characters when a crafted list or dict is supplied as the assertion_value parameter, and the non-default escape_mode=1 is configured.
Details
The method ldap.filter.escape_filter_chars supports 3 different escaping modes. escape_mode=0 (default) and escape_mode=2 happen to raise exceptions when a list or dict object is supplied as the assertion_value parameter. However, escape_mode=1 happily computes without performing adequate logic to ensure a fully escaped return value.
PoC
>>> import ldap.filter
Exploitable
>>> ldap.filter.escape_filter_chars(["abc@*()/xyz"], escape_mode=1)
'abc@*()/xyz'
>>> ldap.filter.escape_filter_chars({"abc@*()/xyz": 1}, escape_mode=1)
'abc@*()/xyz'
Not exploitable
>>> ldap.filter.escape_filter_chars("abc@*()/xyz", escape_mode=1)
'abc@\\2a\\28\\29\\2fxyz'
>>> ldap.filter.escape_filter_chars(["abc@*()/xyz"], escape_mode=0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib64/python3.12/site-packages/ldap/filter.py", line 41, in escape_filter_chars
s = assertion_value.replace('\\', r'\5c')
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'replace'
>>> ldap.filter.escape_filter_chars(["abc@*()/xyz"], escape_mode=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib64/python3.12/site-packages/ldap/filter.py", line 36, in escape_filter_chars
r.append("\\%02x" % ord(c))
^^^^^^
TypeError: ord() expected a character, but string of length 11 found
Impact
If an application relies on the vulnerable method in the python-ldap library to escape untrusted user input, an attacker might be able to abuse the vulnerability to launch ldap injection attacks which could potentially disclose or manipulate ldap data meant to be inaccessible to them.
With Python being a dynamically typed language, and the commonly used JSON format supporting list and dict, it is to be expected that Python applications may commonly forward unchecked and potentially malicious list and dict objects to the vulnerable sanitization method.
The vulnerable escape_mode=1 configuration does not appear to be widely used.
Suggested Fix
Add a type check at the start of the ldap.filter.escape_filter_chars method to raise an exception when the supplied assertion_value parameter is not of type str.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | python-ldap | all versions | 3.4.5pip install --upgrade 'python-ldap==3.4.5' |
Affected Products
python-ldappython-ldapDetection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for python-ldap, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update python-ldap to 3.4.5 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-r7r6-cc7p-4v5m is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
Fixing This On Your OS
If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.
This issue is rated Moderate severity because exploitation allows unauthorized manipulation or disclosure of LDAP data, but requires the library to be used in a specific manner (escape_mode=1 and supplying a list or dict). Typical deployments using default escape_mode=0 or escape_mode=2 are not exposed to this…
No mitigation is currently available that meets Red Hat Product Security’s standards for usability, deployment, applicability, or stability. As an interim precaution, avoid using escape_mode=1 unless absolutely required.Source: Red Hat security advisory for GHSA-r7r6-cc7p-4v5m (CC BY 4.0)
Frequently Asked Questions
Is GHSA-r7r6-cc7p-4v5m in your dependencies?
Find it across PyPI, including transitive dependencies.