CVE-2025-61911: python-ldap has sanitization bypass in ldap.filter.escape_filter_chars
Summary The sanitization method ldap.filter.escapefilterchars can be tricked to skip escaping of special characters when a crafted list or dict is supplied as the assertionvalue parameter, and the non-default escapemode=1 is configured.
Details The method ldap.filter.escapefilterchars supports 3 different escaping modes. escapemode=0 (default) and escapemode=2 happen to raise exceptions when a list or dict object is supplied as the assertionvalue parameter. However, escapemode=1 happily computes without performing adequate logic to ensure a fully escaped return value.
PoC >>> import ldap.filter Exploitable >>> ldap.filter.escapefilterchars(["abc@()/xyz"], escapemode=1) 'abc@()/xyz' >>> ldap.filter.escapefilterchars({"abc@()/xyz": 1}, escapemode=1) 'abc@()/xyz' Not exploitable >>> ldap.filter.escapefilterchars("abc@()/xyz", escapemode=1) 'abc@\\2a\\28\\29\\2fxyz' >>> ldap.filter.escapefilterchars(["abc@()/xyz"], escapemode=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 escapefilterchars s = assertionvalue.replace('\\', r'\5c') ^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'list' object has no attribute 'replace' >>> ldap.filter.escapefilterchars(["abc@()/xyz"], escapemode=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 escapefilterchars 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 escapemode=1 configuration does not appear to be widely used.
Suggested Fix Add a type check at the start of the ldap.filter.escapefilterchars method to raise an exception when the supplied assertionvalue parameter is not of type str.
Other sources
python-ldap is a lightweight directory access protocol (LDAP) client API for Python. In versions prior to 3.4.5, the sanitization method ldap.filter.escapefilterchars can be tricked to skip escaping of special characters when a crafted list or dict is supplied as the assertionvalue parameter, and the non-default escapemode=1 is configured. The method ldap.filter.escapefilterchars supports 3 different escaping modes. escapemode=0 (default) and escapemode=2 happen to raise exceptions when a list or dict object is supplied as the assertionvalue parameter. However, escapemode=1 computes without performing adequate logic to ensure a fully escaped return value. 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. Version 3.4.5 fixes the issue by adding a type check at the start of the ldap.filter.escapefilterchars method to raise an exception when the supplied assertionvalue parameter is not of type str.
— MITRE
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2025-61911?
The severity of CVE-2025-61911 is currently classified as moderate.
How do I fix CVE-2025-61911?
To fix CVE-2025-61911, upgrade to python-ldap version 3.4.5 or later.
What causes CVE-2025-61911?
CVE-2025-61911 is caused by a flaw in the `ldap.filter.escape_filter_chars` method that can be exploited with crafted input.
Which software is affected by CVE-2025-61911?
CVE-2025-61911 affects python-ldap versions prior to 3.4.5.
Is CVE-2025-61911 critical?
CVE-2025-61911 is not classified as critical but it poses a risk due to potential exploitation.