HIGH ldap injectionfeathersjsbasic auth

Ldap Injection in Feathersjs with Basic Auth

Ldap Injection in Feathersjs with Basic Auth — how this specific combination creates or exposes the vulnerability

LDAP Injection is a server-side injection risk that occurs when an application constructs LDAP queries using unsanitized user input. In FeathersJS, this risk can manifest when the service uses Basic Auth and builds LDAP filter strings dynamically. Basic Auth typically sends credentials as base64-encoded username:password pairs; FeathersJS does not inherently sanitize these values before they are used in an LDAP query, so if the developer builds an LDAP filter using string concatenation or interpolation, attacker-controlled input can alter the filter syntax.

For example, consider a FeathersJS service that performs user authentication by querying an LDAP directory. If the service constructs a filter like (uid=${username}) without validation or escaping, an attacker can supply a username such as admin)(objectClass=*), which changes the logical structure of the LDAP filter and may bypass intended access controls. This is an instance of LDAP Injection in the context of Basic Auth because the credentials are passed in the Authorization header, and if the server uses those credentials to build LDAP queries unsafely, injection becomes feasible.

Additionally, if FeathersJS exposes an endpoint that accepts user-supplied search bases or filter components alongside Basic Auth credentials, the combination increases the attack surface. An attacker may attempt to manipulate the scope or return sensitive entries by injecting wildcard characters or control sequences. Because FeathersJS is often used with LDAP integrations for centralized authentication, improper handling of input in filter construction can lead to unauthorized data retrieval or authentication bypass. The risk is compounded when the LDAP server is reachable from the same network as the FeathersJS application, as injection results may be returned directly to the service.

OpenAPI/Swagger analysis can help identify endpoints that accept authentication inputs and pass them into LDAP-related operations. By correlating runtime findings with spec definitions, middleBrick can highlight areas where user-controlled data is used in LDAP filter construction, supporting the detection of potential LDAP Injection paths even in unauthenticated scans.

Basic Auth-Specific Remediation in Feathersjs — concrete code fixes

To mitigate LDAP Injection in FeathersJS with Basic Auth, avoid building LDAP filters via string concatenation. Use parameterized queries or an LDAP library that supports safe filter escaping. Validate and normalize credentials before using them in directory queries, and ensure that user input never directly influences the structure of the LDAP filter.

Below are concrete code examples for secure Basic Auth handling in FeathersJS.

  • Secure authentication using a parameterized LDAP client (pseudocode-style with comments):
const { AuthenticationClient } = require('some-ldap-client');

app.use('/auth', {
  async create(data, params) {
    const { username, password } = data;
    // Validate input: allow only expected characters for username
    if (!/^[
a-zA-Z0-9._-]+$/.test(username)) {
      throw new Error('Invalid username format');
    }
    // Use a library that supports escaping or parameterized binds
    const client = new AuthenticationClient({ url: 'ldap://ldap.example.com' });
    try {
      // Bind with escaped DN — library should handle escaping
      await client.bind(`uid=${escapeDN(username)},ou=users,dc=example,dc=com`, password);
      return { authenticated: true };
    } catch (err) {
      throw new Error('Authentication failed');
    }
  }
});
  • Using an escaped filter with a safe helper (if constructing filter strings is unavoidable):

function escapeLDAPFilter(input) {
  // Basic escape for LDAP filter special characters: * ( ) \00
  return input.replace(/([*\\()\x00])/g, '\\$1');
}

app.use('/users', {
  async get(id, params) {
    const safeFilter = `(uid=${escapeLDAPFilter(id)})`;
    // Use safeFilter with LDAP search — ensure id is not used to alter filter structure
    const results = await ldapSearch(safeFilter);
    return results;
  }
});
  • Enforce strict content-type and avoid parsing credentials from query strings or body fields that could be concatenated into LDAP filters.

middleBrick’s scans can verify whether endpoints that use Basic Auth also handle input safely by checking for patterns where user data reaches LDAP filter construction. Its findings include severity, remediation guidance, and mapping to frameworks such as OWASP API Top 10 to help prioritize fixes.

Frequently Asked Questions

How can I test if my FeathersJS Basic Auth endpoint is vulnerable to LDAP Injection?
Send crafted input such as username: admin)(objectClass=*) in the Basic Auth header and observe authentication behavior or LDAP query errors. Do not rely on automated guessing in production; use a controlled test environment and review server logs for unexpected filter evaluation.
Does middleBrick detect LDAP Injection in FeathersJS scans?
middleBrick runs checks including Input Validation and Property Authorization that can surface patterns where user-controlled data may influence LDAP queries. Findings are provided with severity and remediation guidance, and OpenAPI/Swagger analysis helps correlate runtime behavior with spec-defined endpoints.