# Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection') (CWE-90) The product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended LDAP query. **Stack:** Python - Prevalence: Hoch Häufig ausgenutzt - Impact: Hoch 3 Regeln mit hohem Schweregrad - Prevention: Dokumentiert 3 Fix-Beispiele **OWASP:** Injection (A03:2021-Injection) - #3 ## Description If user input is incorporated into an LDAP query without proper sanitization, an attacker can inject LDAP commands that could read or modify sensitive directory information. ## Prevention Präventionsstrategien für LDAP Injection basierend auf 1 Shoulder-Erkennungsregeln. ### Python Escape LDAP special characters using escape_filter_chars() before constructing filters ## Warning Signs - [HIGH] LDAP queries constructed with unsanitized user input ## Consequences - Anwendungsdaten lesen - Anwendungsdaten ändern - Schutzmechanismus umgehen ## Mitigations - Verwende, wann immer möglich, parametrisierte LDAP-Abfragen - Maskiere oder encodiere alle Benutzereingaben in LDAP-Abfragen - Validiere Eingaben gegen eine Allowlist akzeptabler Zeichen ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Python (1 rules) - **LDAP Injection** [HIGH]: Detects LDAP queries constructed with unsanitized user input. - Remediation: Escape LDAP special characters using escape_filter_chars(). ```python from ldap3.utils.conv import escape_filter_chars safe_username = escape_filter_chars(username) ``` Learn more: https://shoulder.dev/learn/python/cwe-90/ldap-injection