Summary
OPNsense's LDAP authentication connector previously passed the supplied username directly into an LDAP search filter without escaping special characters.
This allows an unauthenticated attacker to inject LDAP filter metacharacters via the WebGUI login form to enumerate valid usernames and, in some configurations, bypass group-based access restrictions to authenticate as arbitrary LDAP users with known passwords.
Affected context
The vulnerability appears in OPNsense deployments that:
- Use LDAP as an authentication backend for the WebGUI, and
- Construct LDAP search filters from user-supplied usernames, and
- Do not escape or sanitize LDAP filter metacharacters before sending queries to the directory.
Risk is elevated when the LDAP server configuration uses an Extended Query to limit logins to members of a particular group, because the injected filter can be used to alter or neutralize the group membership restriction.
Exploit preconditions
- Attack surface: OPNsense WebGUI login endpoint using LDAP authentication.
- Required access: Network access to the firewall's management interface (WebGUI); no prior authentication required.
- Trigger point: Submission of a crafted username in the login form that is embedded directly into an LDAP search filter.
- Why exploitation is possible: The username is interpolated into the LDAP filter string without calling
ldap_escape()or equivalent encoding, allowing attacker-controlled metacharacters (e.g.,*,), logical operators) to change the intended query logic.
Why this happens
The underlying issue is improper neutralization of special elements used in an LDAP query, mapped to CWE-90: Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection').
Instead of treating the username as a pure data value, the code directly concatenates it into an LDAP filter, effectively allowing user input to participate in the filter syntax.
Without applying ldap_escape() or a similar safe encoding mechanism, the directory server receives a modified filter whose logical structure can be controlled by the attacker, enabling both enumeration of valid entries and alteration of authorization checks that depend on filter correctness.
Potential impact
- Enumeration of valid LDAP usernames configured for OPNsense authentication.
- Bypass of LDAP group-based access controls enforced via Extended Query filters.
- Authentication as any LDAP user whose password is known, regardless of group membership, when Extended Query restrictions are in use.
- Increased risk of targeted password attacks due to reliable username discovery.
General mitigation guidance
Mitigation focuses on ensuring that user-controlled data never alters LDAP query structure:
- Apply strict LDAP escaping to all user-supplied input before inserting it into filter expressions (e.g., using
ldap_escape()or language/framework equivalents). - Prefer parameterized or template-based LDAP query construction where filter syntax is fixed and only data values are substituted.
- Minimize complexity in Extended Query filters and avoid relying solely on dynamically constructed filters for critical authorization decisions.
- Layer group membership checks in the application logic using securely obtained directory attributes, instead of embedding complex logic directly in filters driven by user input.
- Restrict network access to the management interface to trusted administrative networks and enforce strong administrative authentication and MFA where possible to reduce exposure.
How teams detect issues like this
Detection can combine code-level analysis and behavioral monitoring:
- Use static analysis or secure code review to flag direct string concatenation of user input into LDAP filter strings, especially in authentication and authorization paths.
- Search for LDAP filter-building code that does not consistently apply standardized escaping utilities before inserting the username or other user-controlled fields.
- Enforce coding policies that mandate use of centralized LDAP helper functions which always escape input, and review exceptions carefully.
- Monitor authentication logs for anomalous login attempts containing LDAP meta-characters in the username field or repeated filter syntax-like patterns.
- Incorporate security testing (SAST/DAST) in CI/CD pipelines with rules targeting LDAP injection patterns.

