- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: kotlin-security/avoid-anonymous-ldap
Language: Kotlin
Severity: Error
Category: Security
CWE: 287
This rule enforces that LDAP connections in Kotlin applications must utilize explicit user credentials for authentication. LDAP (Lightweight Directory Access Protocol) is a protocol used for accessing and maintaining distributed directory information services over an Internet Protocol (IP) network.
This rule is significant as it helps prevent unauthorized access to sensitive data. If LDAP connections are allowed to proceed without explicit user credentials, it might facilitate anonymous access, which can lead to data breaches or unauthorized modifications.
To comply with this rule, ensure that you are not enabling anonymous access when setting up LDAP connections. Instead, use methods like setUserDn(username)
and setPassword(password)
for Spring LDAP or put(Context.SECURITY_PRINCIPAL, username)
and put(Context.SECURITY_CREDENTIALS, password)
for Java’s JNDI to set explicit user credentials. This authentication process ensures that only authorized users can access the LDAP resources, thereby maintaining the security and integrity of the data.
import org.springframework.ldap.core.support.LdapContextSource
fun configureLDAP(): LdapContextSource {
return LdapContextSource().apply {
setUrl("ldap://localhost:389")
// Dangerous: Enables anonymous access
setAnonymousReadOnly(true)
afterPropertiesSet()
}
}
import javax.naming.Context
import javax.naming.directory.InitialDirContext
fun connectLDAP() {
val env = Hashtable<String, Any>()
env.apply {
put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory")
put(Context.PROVIDER_URL, "ldap://localhost:389")
// Dangerous: Anonymous bind
put(Context.SECURITY_AUTHENTICATION, "none")
}
env.put(Context.SECURITY_AUTHENTICATION, "none")
val context = InitialDirContext(env)
}
import org.springframework.ldap.core.support.LdapContextSource
fun configureLDAPSecurely(
username: String,
password: String
): LdapContextSource {
return LdapContextSource().apply {
setUrl("ldap://localhost:389")
setUserDn(username)
setPassword(password)
// Optional: Enable connection pooling for better performance
setPooled(true)
afterPropertiesSet()
}
}
import javax.naming.Context
import javax.naming.directory.InitialDirContext
fun connectLDAPSecurely(username: String, password: String) {
val env = Hashtable<String, Any>()
env.apply {
put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory")
put(Context.PROVIDER_URL, "ldap://localhost:389")
// Secure: Using explicit authentication
put(Context.SECURITY_AUTHENTICATION, "simple")
put(Context.SECURITY_PRINCIPAL, username)
put(Context.SECURITY_CREDENTIALS, password)
}
val context = InitialDirContext(env)
}