GHSA-r7r6-cc7p-4v5m

Suggest an improvement
Source
https://github.com/advisories/GHSA-r7r6-cc7p-4v5m
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2025/10/GHSA-r7r6-cc7p-4v5m/GHSA-r7r6-cc7p-4v5m.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-r7r6-cc7p-4v5m
Aliases
Downstream
CGA (2)
ECHO (1)
Published
2025-10-10T22:51:28Z
Modified
2026-09-10T03:50:30Z
Severity
  • 5.5 (Medium) CVSS_V4 - CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N/E:P CVSS Calculator
Summary
python-ldap has sanitization bypass in ldap.filter.escape_filter_chars
Details

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.

Database specific
{
    "cwe_ids":  [
        "CWE-75",
        "CWE-843"
    ],
    "github_reviewed":  true,
    "github_reviewed_at":  "2025-10-10T22:51:28Z",
    "nvd_published_at":  "2025-10-10T22:15:37Z",
    "severity":  "MODERATE"
}
References

Affected packages

PyPI / python-ldap

Package

Name
python-ldap
View open source insights on deps.dev
Purl
pkg:pypi/python-ldap

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0 Unknown introduced version / All previous versions are affected
Fixed
3.4.5

Affected versions

2.*
2.3.13
2.4.0
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.4.7
2.4.8
2.4.9
2.4.10
2.4.12
2.4.13
2.4.14
2.4.15
2.4.16
2.4.17
2.4.18
2.4.19
2.4.20
2.4.21
2.4.22
2.4.25
2.4.26
2.4.27
2.4.28
2.4.29
2.4.30
2.4.31
2.4.32
2.4.33
2.4.35
2.4.36
2.4.37
2.4.38
2.4.39
2.4.40
2.4.41
2.4.42
2.4.43
2.4.44
2.4.45
2.5.1
2.5.2
3.*
3.0.0b1
3.0.0b2
3.0.0b3
3.0.0b4
3.0.0
3.1.0
3.2.0
3.3.0
3.3.1
3.4.0
3.4.2
3.4.3
3.4.4

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2025/10/GHSA-r7r6-cc7p-4v5m/GHSA-r7r6-cc7p-4v5m.json"