Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
LDAP injection abuses applications that build directory search filters from user input, allowing authentication bypass and extraction of data from Active Directory or another LDAP service.

What Is LDAP Injection?
LDAP injection, catalogued as CWE-90, is what happens when an application builds a directory search filter by concatenating user input. The attacker supplies characters that the directory server reads as filter syntax rather than as a value, and the query that executes is not the one the developer wrote. Because the directory is usually Active Directory, and because the application often binds to it with a privileged service account, the consequences reach beyond the application itself.
LDAP search filters, defined in RFC 4515, use prefix notation and a small set of operators: & for conjunction, | for disjunction, ! for negation, * as a wildcard, and parentheses for grouping. A login routine might assemble:
(&(uid=USERNAME)(userPassword=PASSWORD))
Supplying a username of admin)(&) produces (&(uid=admin)(&))(userPassword=anything)). The server evaluates the first complete filter, which matches the administrator and nothing else, and the password clause has been pushed outside it. Supplying a single asterisk as the username matches every account in scope, which is how an attacker enumerates the directory from a login form.
Distinguished name injection is a related variant. Where input is placed into a DN rather than a filter, the escaping rules come from RFC 4514 instead and the dangerous characters differ, including the comma, plus sign, backslash, and leading or trailing spaces. An escaping routine written for one will not protect the other.
Few applications display directory errors or raw results, so attackers work by inference. A filter can be made to ask whether an attribute begins with a particular character, and the application’s behaviour, a successful login, a different message, or a changed response time, answers the question. Iterating character by character recovers attribute values such as employee numbers, group memberships, and in poorly configured directories, password hashes stored in custom attributes. The technique is identical in shape to blind SQL injection, and the same automation applies.
A directory holds the organisation’s identity data: usernames, email addresses, job titles, telephone numbers, managers, and group memberships. That is reconnaissance material for spear phishing and for mapping privileged groups before an attack on identity and access management systems. Authentication bypass against a directory-backed login usually yields access to every application sharing that directory, not just the vulnerable one. Where the exposed attributes include personal data about employees, UK GDPR obligations follow in the same way as for customer records.
\28, \29, \2a, \5c, and \00. For distinguished names, apply the RFC 4514 rules. Use a library function such as Spring Security’s encoder or OWASP’s ESAPI rather than writing the routine yourself.Static analysis catches the concatenation pattern where the directory API is recognised, and it is worth adding a rule for your own LDAP helper classes during secure code review. Dynamically, the probes are simple: submit *, then )(&), then a filter fragment that should always be true, and compare the responses. Anywhere a directory is queried deserves the test, which includes login pages, user search features, address book lookups, and self-service password reset. Our web application security testing covers directory-backed authentication alongside the rest of the application’s input handling.
Yes, wherever an application authenticates against Active Directory or another directory service, which covers most internal enterprise software. It is less common than SQL injection largely because fewer applications query directories, not because the pattern is better understood. Legacy intranet applications and self-service portals are where it most often appears in assessments.
The idea is the same and the details differ in ways that matter. LDAP filters use prefix notation with parentheses and logical operators, so the payloads look nothing like SQL. There is no equivalent of a parameterised query in most LDAP libraries, so correct escaping carries more of the defensive weight, and the escaping rules differ between search filters and distinguished names.
Search for the account using an escaped filter to obtain its distinguished name, then perform an LDAP bind using that DN and the password the user supplied. The directory validates the credential, so the password is never placed in a filter and never compared by your code. Close the connection afterwards and do not reuse the privileged search binding for the user’s session.
A little. Rules can flag obvious filter metacharacters such as unbalanced parentheses and asterisks in a username field, which catches unsophisticated attempts. They also produce false positives on legitimate values and are bypassed by encoding and by blind techniques that use only ordinary characters. Treat it as temporary cover while the code is corrected.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.