This vulnerability occurs when an application builds an LDAP query using untrusted user input without properly sanitizing it. An attacker can inject special characters or commands to alter the query's logic, potentially gaining unauthorized access to, modifying, or extracting sensitive directory information.
LDAP Injection happens much like SQL injection, but targets Lightweight Directory Access Protocol queries. When user input from a form, URL parameter, or API request is directly concatenated into an LDAP search filter (like `(cn=` + userInput + `)`), an attacker can insert characters like `*`, `(`, `)`, `\`, or `null` to break the query's structure. This allows them to bypass authentication, escalate privileges, or dump the entire contents of the directory by creating filters like `*)(uid=*))(|(uid=*` that always return results. To prevent this, developers should never construct LDAP filters by simple string concatenation. Instead, use parameterized queries or the encoding functions provided by your LDAP library (like `escapeLDAPSearchFilter` in Java or `ldap_escape` in PHP) to properly neutralize special characters. Always apply the principle of least privilege to the LDAP binding account and validate all input against a strict allow-list of expected characters before it reaches the query builder.
Impact: Execute Unauthorized Code or CommandsRead Application DataModify Application Data
An attacker could include input that changes the LDAP query which allows unintended commands or code to be executed, allows sensitive data to be read or modified or causes other unintended behavior.
Strategy: Input Validation
java