Skip to content

LDAP Injection

Description

Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection'). All inputs passed to an LDAP query need to be passed in safely. Unfortunately, LDAP doesn't have prepared statement interfaces like SQL. Therefore, the primary defense against LDAP injection is strong input validation of any untrusted data before including it in an LDAP query.

Examples

Insecure Code

scala
def search(ctx: javax.naming.directory.DirContext, input: String): Unit = {
  ctx.search("", input, new SearchControls())
}

Secure Code

scala
def search(ctx: javax.naming.directory.DirContext, input: String): Unit = {
  val safeInput = input.replace("(*","").replace(")","")
  ctx.search("", safeInput, new SearchControls())
}

Remediation

Validate all untrusted input data before including it in an LDAP query.

Rule Details

FieldValue
IDCODE-0048
CategoryInjection
SeverityMEDIUM
CWECWE-90
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsldap, injection
OWASPN/A