The vulnerability is an LDAP injection in the Maddy Mail Server's auth.ldap module. The root cause is the direct use of unsanitized user-supplied usernames in LDAP search filters and DN templates. The provided patch 6a06337eb41fa87a35697366bcb71c3c962c44ba clearly shows that the username variable was being used without escaping in internal/auth/ldap/ldap.go.
Two functions are identified as vulnerable:
Auth.Lookup: This function was vulnerable to LDAP filter injection because it used strings.ReplaceAll to substitute the username directly into the filter. The patch fixes this by wrapping the username with ldap.EscapeFilter.
Auth.AuthPlain: This function contained two injection points. If a dn_template was configured, it was vulnerable to DN injection, fixed by using ldap.EscapeDN. Otherwise, it was vulnerable to the same LDAP filter injection as Auth.Lookup, fixed by using ldap.EscapeFilter.
An attacker could exploit this by providing a crafted username during SMTP (AUTH PLAIN) or IMAP (LOGIN) authentication. This could lead to identity spoofing, enumeration of LDAP directory contents, and extraction of sensitive attributes through boolean-based blind or timing-based side-channel attacks. The identified functions, Auth.Lookup and Auth.AuthPlain, are the direct entry points for this vulnerability and would appear in a runtime profile during an exploitation attempt.