Improperly implemented security check for standard
ID |
scala.ldap.scala_ldap_rule_anonymousldap |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Ldap |
Language |
Scala |
Description
Without proper access control, executing an LDAP statement that contains a user-controlled value can allow an attacker to abuse poorly configured LDAP context
Rationale
Without proper access control, executing an LDAP statement that contains a user-controlled value can allow an attacker to abuse poorly configured LDAP context
The following code illustrates a vulnerable pattern detected by this rule:
object DirectoryLookup {
private val directoryUrl = "ldaps://directory.internal/dc=directory,dc=internal"
private val factory = "com.sun.jndi.ldap.LdapCtxFactory"
@throws[Exception]
private def connect(environment: Hashtable[String, String]) = {
environment.put(Context.INITIAL_CONTEXT_FACTORY, factory)
environment.put(Context.PROVIDER_URL, directoryUrl)
// VULNERABLE: Improperly implemented security check for standard
environment.put(Context.SECURITY_AUTHENTICATION, "none")
new InitialDirContext(environment)
}
// Binding with a principal is the control: only "none" is anonymous.
@throws[Exception]
def bind(dn: String, secret: String): Boolean = {
val environment = new Hashtable[String, String]
environment.put(Context.SECURITY_AUTHENTICATION, "simple")
environment.put(Context.SECURITY_PRINCIPAL, dn)
environment.put(Context.SECURITY_CREDENTIALS, secret)
try connect(environment)
catch {
case e: javax.naming.AuthenticationException =>
return false
}
true
}
}
Remediation
Follow secure coding practices and review the references below for detailed remediation guidance.
References
-
OWASP Top 10 2025 - A05 : Injection.