Configuring an LDAP context source with an ldap:// URL transmits bind credentials and directory data over an unencrypted channel. An attacker positioned on the network can intercept the service-account password and the contents of every directory query and response.
Use ldaps:// (LDAP over TLS) or enable STARTTLS so that the connection to the directory server is encrypted and authenticated. Store the bind password outside source control (for example in a secret manager or environment variable).
The following example configures a Spring LdapContextSource with a cleartext ldap:// URL, so the bind credentials cross the network in the clear.
@Bean
public LdapContextSource ldapContextSource() {
LdapContextSource ctx = new LdapContextSource();
// BAD: cleartext ldap:// transmits the bind password unencrypted.
ctx.setUrl("ldap://ldap.corp.example.com:389");
ctx.setUserDn("cn=svc-app,ou=ServiceAccounts,dc=corp,dc=example,dc=com");
ctx.setPassword(System.getenv("LDAP_PASSWORD"));
ctx.afterPropertiesSet();
return ctx;
}Use ldaps://ldap.corp.example.com:636 instead.
- OWASP: Transport Layer Protection Cheat Sheet.
- Common Weakness Enumeration: CWE-319.