Coverage area · Partly checked automatically

Active Directory and LDAP integration security

Applications that authenticate against Active Directory or query LDAP carry directory credentials and build directory queries. This page covers the mistakes in that integration code that expose your directory, and which of them OpenRouting checks today.

what to look for · Active Directory
[ ] Bind credentials hard-coded?
[ ] Cleartext LDAP instead of LDAPS?
[ ] Is filter input escaped?
fix: use LDAPS, load bind creds from a vault
$ 

A manual checklist for this area. The example below isn't flagged by a stock rule; see what is checked today.

What OpenRouting checks today

Partly checked automatically

Semgrep's default ruleset flags LDAP injection and anonymous binds in Java and Kotlin and binds without a password in PHP; the directory agent reviews them. Committed credentials in a known token format are flagged by the secret rules. Not checked: Python LDAP code like the ldap3 example below, cleartext ldap:// connections, PowerShell scripts, and anything in git history (only the current files are scanned).

Why this area matters

Active Directory is often the identity backbone of a company, so the service accounts and queries applications use against it are high-value. LDAP injection (CWE-90) can bypass login checks or expose directory data, and a service-account password committed to a repository (CWE-798) is a direct path into the domain.

Generic scanners see an LDAP call but not whether its filter is escaped or whether the connection is LDAPS. When Semgrep flags one, the directory review agent checks the filter construction, the transport and where the bind credentials come from.

What goes wrong in real applications

  • LDAP filter injection

    User input placed into an LDAP filter without escaping can change the query's logic, bypassing authentication checks or returning objects the user shouldn't see.

  • Cleartext binds

    Binding over ldap:// without StartTLS sends credentials across the network readable by anyone on the path.

  • Hard-coded service-account credentials

    Bind passwords in source or config files end up in every clone, fork and backup of the repository, and they stay in its history after deletion.

  • Over-privileged service accounts

    Applications binding as a domain admin or highly privileged account turn any application bug into a directory-wide compromise.

Sample: the risky pattern and the fix

Riskyauth/directory.py
from ldap3 import Server, Connection

server = Server("ldap://dc01.corp.example")
conn = Connection(server, user="[email protected]",
                  password="••••••••", auto_bind=True)

def find_user(username):
    flt = f"(&(objectClass=user)(sAMAccountName={username}))"
    conn.search("dc=corp,dc=example", flt, attributes=["mail"])
    return conn.entries
Saferauth/directory.py
import os
from ldap3 import Server, Connection
from ldap3.utils.conv import escape_filter_chars

server = Server("ldaps://dc01.corp.example", use_ssl=True)
conn = Connection(server, user=os.environ["LDAP_BIND_USER"],
                  password=os.environ["LDAP_BIND_PASSWORD"], auto_bind=True)

def find_user(username):
    safe = escape_filter_chars(username)
    flt = f"(&(objectClass=user)(sAMAccountName={safe}))"
    conn.search("dc=corp,dc=example", flt, attributes=["mail"])
    return conn.entries

The original binds over cleartext LDAP with a password committed to the repository, and pastes the username into the filter unescaped, so special characters change the query. The fix uses LDAPS, loads the bind credentials from the environment (backed by a secrets manager), and escapes filter input.

Illustrative code, simplified for clarity — not taken from a customer repository.

What to look for in your code

  • LDAP filters and DNs built from request input without escaping
  • ldap:// connections without StartTLS, and disabled certificate validation
  • Bind DNs and passwords in source and config files, and in past commits
  • PowerShell, GPO and provisioning scripts committed to the repo that embed credentials

Scope and limits

  • It never connects to domain controllers, enumerates your directory or tests Kerberos — it reviews the code and scripts in your repository that integrate with it.
  • Directory permissions and group memberships live in AD itself, so whether a service account is over-privileged can only be judged from how the code uses it.

The checklist above is broader than what runs automatically; see what OpenRouting checks today. Where a scanner does run, it surfaces candidates and a review agent decides whether each one is real — it doesn't promise to find every issue.

Review agents for this area

These agents give the verdict and fix when a scanner raises a finding here.

  • Directory & LDAP integration — Reviews Active Directory and LDAP code for injection, cleartext binds and hard-coded credentials.
  • Secrets & data exposure — Judges whether a flagged value is really a secret and whether sensitive data leaks through logs or errors.
  • Authentication & JWT — Checks that identity, tokens and sessions are actually verified and hardened.

Common questions

Does OpenRouting audit my Active Directory?

No. It doesn't touch your domain. It reviews application code and scripts that talk to AD or LDAP, where injection, cleartext binds and committed credentials are introduced.

If a bind password was deleted from the code, am I safe?

No. It stays in the repository's history and every clone. OpenRouting scans the current files only, so it won't report a deleted password; rotate it rather than just deleting the line.