Aller au contenu

LDAP injection (ARCH2107)

Ce contenu n’est pas encore disponible dans votre langue.

Key python.security.ldap-injection · Severity error · Category security · CWE CWE-90

Building LDAP search filters from unescaped user input lets an attacker manipulate the filter to bypass authentication or reach unauthorized data.

def find_user(conn, username):
flt = f"(uid={username})"
conn.search("ou=people,dc=example,dc=com", flt)
from ldap3.utils.conv import escape_filter_chars
def find_user(conn, username):
flt = f"(uid={escape_filter_chars(username)})"
conn.search("ou=people,dc=example,dc=com", flt)

Escape filter values with escape_filter_chars; never embed raw user input in the filter.