new capacity bits (#67)

This commit is contained in:
Eli Peter 2026-05-07 01:29:31 -04:00 committed by GitHub
parent afaffc0df6
commit 7d0e7320e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
261 changed files with 10591 additions and 231 deletions

View file

@ -0,0 +1,10 @@
# Baseline: filter is a compile-time constant. No taint reaches `search_s` so
# no LDAP_INJECTION finding fires.
import ldap
def lookup():
conn = ldap.initialize("ldap://example.com")
return conn.search_s(
"ou=people,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(objectClass=person)"
)

View file

@ -0,0 +1,14 @@
# Safe: user-supplied substring run through `escape_filter_chars` (RFC 4515)
# before being concatenated into the filter. The sanitizer clears the
# LDAP_INJECTION cap so the sink does not fire.
import ldap
from ldap.filter import escape_filter_chars
from flask import request
def lookup():
conn = ldap.initialize("ldap://example.com")
user = request.form["user"]
safe = escape_filter_chars(user)
flt = "(uid=" + safe + ")"
return conn.search_s("ou=people,dc=example,dc=com", ldap.SCOPE_SUBTREE, flt)

View file

@ -0,0 +1,13 @@
# Unsafe: tainted form data concatenated into an LDAP filter and passed to
# python-ldap's `search_s`. The bound receiver `conn` is typed as LdapClient
# via `ldap.initialize`, and the suffix matcher on `search_s` also catches the
# call directly.
import ldap
from flask import request
def lookup():
conn = ldap.initialize("ldap://example.com")
user = request.form["user"]
flt = "(uid=" + user + ")"
return conn.search_s("ou=people,dc=example,dc=com", ldap.SCOPE_SUBTREE, flt)