/

CVE-2026-40193

Severity:

HIGH RISK

(8.2)

LDAP Injection in maddy auth.ldap Authentication Module

CVE-2026-40193

Analyzed

Vulnerability type

Category:

LDAP Injection

CWE:

CWE-90

Impact:

Authentication Bypass and LDAP Directory Exposure

Severity:

HIGH RISK

(8.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

maddy mail server versions prior to 0.9.3 contain an LDAP injection vulnerability in the auth.ldap module, where user-supplied usernames are inserted into LDAP filters and DN strings without proper escaping.

An attacker with network access to SMTP submission or IMAP can inject arbitrary LDAP filter expressions via the username field, potentially authenticating as other users, enumerating directory contents, or inferring attribute values.

Affected context

The vulnerability occurs in maddy deployments that use the auth.ldap module for user authentication against an LDAP directory.

It manifests in three paths where the username is treated as data for LDAP operations:

  • The Lookup() search filter
  • The AuthPlain() DN template
  • The AuthPlain() search filter

The issue is present when these code paths interpolate untrusted usernames directly into LDAP filter or DN strings without applying LDAP filter escaping, and when SMTP submission or IMAP interfaces are reachable by potentially untrusted clients.

Exploit preconditions

  • Attack surface: SMTP submission and IMAP interfaces using auth.ldap for authentication.
  • Required access: Ability to initiate authentication attempts (e.g., AUTH PLAIN or LOGIN) and control the username field.
  • Trigger point: The server constructs LDAP filters and DN strings that embed the supplied username and sends them to the LDAP server.
  • Why exploitation is possible: Username values are processed with generic string replacement (strings.ReplaceAll()) instead of LDAP-aware escaping, so special characters and operators are interpreted as part of the LDAP filter language, allowing arbitrary filter manipulation and DN tampering.

Why this happens

The core issue aligns with CWE-90: Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection').

In the vulnerable code, user-controlled input (the username) is interpolated directly into LDAP filters and DN templates using string replacement operations.

Because no LDAP-specific escaping or encoding routine (such as ldap.EscapeFilter()) is applied, characters like *, ), (, &, and | are treated as control operators in the LDAP query language, not as literal data.

As a result, the authentication logic operates on attacker-defined filter expressions, enabling changes to which directory entries are matched and how identity lookups behave.

Potential impact

  • An attacker could authenticate as another user by crafting filters that match arbitrary directory entries.
  • An attacker could enumerate existing user accounts or other LDAP objects by probing for filter conditions that succeed or fail.
  • An attacker could use authentication responses as a boolean oracle to infer sensitive LDAP attributes (e.g., group membership) and potentially leverage timing differences between distinct failure paths.
  • Authentication logs and monitoring systems could be polluted with misleading or spoofed identity information.
  • The LDAP directory's structure and schema could be partially exposed through systematic probing, aiding further attacks.

General mitigation guidance

Long-term mitigation focuses on treating LDAP queries as structured operations rather than string templates:

  • Apply LDAP-aware escaping to all untrusted input embedded in filters using dedicated functions (for example, the equivalent of EscapeFilter() routines) instead of manual string concatenation or replacement.
  • Avoid building DN strings or filter expressions directly from user input; derive them from stable identifiers or lookups where possible.
  • Centralize LDAP query construction behind a small, well-reviewed API that always escapes or parameterizes user-supplied values.
  • Reduce the privileges of the LDAP bind account used by maddy so that it can only read the minimal set of attributes necessary for authentication, limiting the impact of any injection.
  • Design authentication flows so that a single, uniform failure mode and error message is used, reducing information leakage and making side-channel probing less effective.

How teams detect issues like this

Effective detection generally combines code-focused and behavior-focused techniques:

  • Static analysis and code review: Flag any LDAP filter or DN construction that uses string concatenation, formatting, or ReplaceAll() with variables derived from client input. Require that all such sites call an LDAP-specific escaping or parameterization function.
  • Configuration and policy checks: Enforce internal coding guidelines that prohibit raw string-based LDAP query construction, and integrate checks into CI/CD pipelines to catch violations.
  • Runtime monitoring: Inspect authentication logs for anomalous usernames containing LDAP metacharacters (*, (, ), &, |, \00, etc.), repeated failed authentication patterns, or unusual timing distributions that may indicate probing.
  • Security testing: Include LDAP injection tests in regular penetration testing and automated security testing suites, targeting authentication workflows that rely on directory lookups.

Sources

SourceLink
github.comgithub.com/foxcpp/maddy/commit/6a06337eb41fa87a35697366bcb71c3c962c44ba
github.comgithub.com/foxcpp/maddy/releases/tag/v0.9.3
github.comgithub.com/foxcpp/maddy/security/advisories/GHSA-5835-4gvc-32pc

Frequently asked

questions

Exploitability is limited to environments where maddy's auth.ldap module is configured and reachable over SMTP submission or IMAP, but in those cases any party able to attempt authentication can try to exploit it through crafted usernames.

No. The attacker primarily needs the ability to send AUTH PLAIN or LOGIN commands and control the username field; valid credentials are not required to attempt injection, though knowledge of the directory structure can increase the success rate.

Replace all string-based LDAP query construction that involves user input with APIs that enforce LDAP-aware escaping or parameterization, ensuring that untrusted data is always treated as literal values rather than filter syntax, and keep this logic centralized.

Adopt secure coding standards that mandate escaping for all user-controlled LDAP inputs, use well-reviewed helper functions for filter and DN construction, minimize LDAP account privileges, and integrate static analysis or code review rules that flag raw string concatenation in directory queries.

Find out what's already
exploitable in your codebase.