Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is LDAP Injection?

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.

Illustration for the cybersecurity term LDAP Injection
Home / Blog / Cybersecurity Terms / What Is LDAP Injection?
17 November 2026

What Is LDAP Injection?

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.

The Syntax Being Abused

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.

Blind Extraction

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.

Why the Impact Is Often Underestimated

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.

Preventing It

  1. Bind as the user instead of searching for their password. The safe authentication pattern is to locate the account with a filter built from escaped input, then attempt an LDAP bind with the supplied credentials and let the directory decide. The password never appears in a filter.
  2. Escape according to the correct specification. For filters, encode the five special characters as hexadecimal sequences: \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.
  3. Validate before escaping. Usernames rarely need anything beyond letters, digits, and a couple of punctuation characters, and an allow-list removes most payloads before escaping is relied on.
  4. Restrict the service account. It should be able to read only the attributes the application needs, within the branch of the tree it needs, with no write permission. Most applications are configured with far more than this.
  5. Set a search base and a size limit so a wildcard filter cannot return the whole directory.
  6. Return generic authentication errors so the application does not become the oracle that blind extraction depends on.

Finding It

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.

FAQ – Frequently Asked Questions

Is LDAP Injection Still Relevant?

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.

How Is It Different from SQL Injection?

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.

What Is the Safest Way to Authenticate Against a Directory?

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.

Does a Web Application Firewall Help?

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.

Related Terms

You May Be Interested In These

What Is Cosign?

Cybersecurity Terms

17 November 2026

What Is Cosign?

Read More
What Is sqlmap?

Cybersecurity Terms

17 November 2026

What Is sqlmap?

Read More
What Is HMAC?

Cybersecurity Terms

17 November 2026

What Is HMAC?

Read More