← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

LDAP Injection

Security CWE-90 OWASP A3:2021 CVSS 7.5 PHP 5.6+ Intermediate
debt(d5/e3/b3/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5): detection_hints lists semgrep and psalm as the tools, both specialist SAST tools rather than default linters. The code pattern (string concatenation into LDAP filters without ldap_escape()) is detectable statically but requires dedicated SAST configuration, not a default linter rule. In production, the vulnerability is silent until actively exploited.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3): The quick_fix is to replace raw concatenation with ldap_escape() calls using the correct context flag (LDAP_ESCAPE_FILTER or LDAP_ESCAPE_DN). This is a small, targeted refactor within the affected query/filter construction sites — not a one-line global patch, but also not a cross-file architectural change. Multiple call sites may need updating, keeping it at e3.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3): The vulnerability applies to web and CLI contexts but only where LDAP queries are constructed. It does not impose a persistent codebase-wide tax; only the LDAP-touching components carry the risk. Once ldap_escape() is used consistently in those components, the burden is contained.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7): The misconception field explicitly states that developers believe 'LDAP injection is rare and low impact,' when in fact it can bypass authentication entirely and enumerate sensitive directory data. This contradicts intuition shaped by familiarity with SQL injection — LDAP's filter syntax is different, the escape function (ldap_escape()) requires a context flag, and the impact (auth bypass, attribute enumeration) is underestimated by most developers. This is a well-documented but frequently missed trap.

About DEBT scoring →

Also Known As

LDAP attack directory injection

TL;DR

Unsanitised input manipulates LDAP query filters, bypassing authentication or exposing directory data.

Explanation

LDAP injection is analogous to SQL injection but targets Lightweight Directory Access Protocol queries. If user-supplied values are concatenated directly into an LDAP filter string, an attacker can alter the query logic — for example, injecting *)(&) to match all entries or bypass authentication checks. PHP applications using ldap_search() must escape special characters with ldap_escape() before building filter strings.

How It's Exploited

An attacker submits the username *)(uid=*))(|(uid=* into a login form. If the application builds the filter as (uid=<input>), the injected string collapses into a filter that always matches, granting access without a valid password.

Common Misconception

LDAP injection is rare and low impact. A successful injection can bypass authentication entirely by manipulating filter logic, enumerate directory users, and extract sensitive attributes like group memberships and email addresses.

Why It Matters

Unsanitised input in LDAP filters can bypass authentication, enumerate directory entries, or extract sensitive attributes from the directory.

Common Mistakes

  • Concatenating user input into LDAP filter strings without using ldap_escape().
  • Not specifying LDAP_ESCAPE_FILTER or LDAP_ESCAPE_DN context in ldap_escape() calls.
  • Binding to LDAP with an admin account for all operations instead of a restricted read-only account.
  • Believing that LDAP is only used for authentication and therefore less exploitable than SQL databases.

Code Examples

✗ Vulnerable
$filter = "(uid=$username)"; ldap_search($conn, $base, $filter);
✓ Fixed
$safe = ldap_escape($username, '', LDAP_ESCAPE_FILTER); ldap_search($conn, $base, "(uid=$safe)");

Added 15 Mar 2026
Edited 22 Mar 2026
Views 118
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping W 0 pings T 0 pings F 2 pings S 0 pings S 1 ping M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 1 ping W 0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 2 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
ChatGPT 14 PetalBot 13 Amazonbot 10 Ahrefs 8 SEMrush 8 Bing 8 Perplexity 4 Google 4 Scrapy 3 Claude 2 Twitter/X 2 Applebot 2 Majestic 1 Meta AI 1 Sogou 1 Unknown AI 1
crawler 75 crawler_json 7
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Use ldap_escape() with LDAP_ESCAPE_FILTER for search filters and LDAP_ESCAPE_DN for distinguished names — these escape the special characters that make LDAP injection possible
📦 Applies To
PHP 5.6+ web cli
🔗 Prerequisites
🔍 Detection Hints
LDAP filter with user input not escaped via ldap_escape(); string concatenation building LDAP filter or DN
Auto-detectable: ✓ Yes semgrep psalm
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Line
CWE-90


✓ schema.org compliant