A simple diagram of the LDAP Injection risk path
Risk path: an input or context crosses a security boundary.
A simple three-step test path for LDAP Injection
Testing path: establish a baseline, make one controlled change, and verify the effect.

01Issue

Overview

LDAP is a protocol applications use to search directory services for users, groups, and other records. LDAP injection occurs when input changes the meaning of an LDAP filter or name. A search for one username can become a broader query if special characters are treated as filter syntax. Escaping depends on where the value is used; escaping a filter value is different from escaping a distinguished name.

Common causes

  • The application builds an LDAP filter by concatenating user input.
  • Input is escaped for the wrong LDAP context or with a rule intended for another language.
  • One directory query path validates input while another does not.
  • The result of a broad query is trusted for authentication or authorization without checking the exact identity.

References: OWASP LDAP Injection Prevention Cheat Sheet ↗CWE-90: LDAP Injection ↗OWASP WSTG: Testing for LDAP Injection ↗

02Examples

EXAMPLE

Illustrative search field: username=alex. In a test directory, compare it with a value containing a filter character such as alex*, and inspect whether the application returns one exact match or many. A broader result is a lead; confirm whether it exposes protected records or changes an authentication decision.

03Impact

A user-controlled value must be inserted into an LDAP query without context-appropriate escaping or parameterization, and the changed query must affect returned records or a security decision.

A confirmed issue may expose additional directory results or alter an authentication or group-membership decision. A search returning multiple records is not automatically a security impact; verify which protected data or action becomes available.

04Testing

Test cases

1. Check whether input changes a directory search

Compare normal and specially structured test input against a directory with known test entries. Observe whether the result set changes beyond the intended search.

Example: A filter error suggests the input reaches the directory query. Verify the selected test entries before reporting access.

GET /api/directory?name=test%2A HTTP/1.1
Host: app.example.test

2. Compare escaping of special characters

Submit literal directory filter characters and compare the result with a normal search. Review how the server constructs the LDAP filter.

Example: A name containing an asterisk may be intended as literal text. Check the actual filter or controlled results.

GET /api/directory?name=%28test%29 HTTP/1.1
Host: app.example.test

3. Review authentication and directory permissions

Where directory searches support login or lookup, inspect each path and the directory account’s permissions. State any demonstrated authorization impact separately.

Example: A broadened lookup is not automatically a login bypass. Confirm the authenticated session if that impact is claimed.

Testing references: OWASP LDAP Injection Prevention Cheat Sheet ↗CWE-90: LDAP Injection ↗OWASP WSTG: Testing for LDAP Injection ↗

05Mitigation

Use the directory library’s safe filter-building or parameter APIs. Escape values for the exact LDAP context, validate expected formats, and keep query structure fixed in code. For authentication, compare the returned directory identity with the requested account and apply authorization using a stable identifier.

Retest

Repeat search and login checks with normal, empty, and special-character values. Confirm the query returns only intended matches and authentication remains bound to the exact test identity.