Skip to content

Fix LDAP filter injection#1

Open
Montana wants to merge 1 commit intoStanford:masterfrom
Montana:patch-1
Open

Fix LDAP filter injection#1
Montana wants to merge 1 commit intoStanford:masterfrom
Montana:patch-1

Conversation

@Montana
Copy link
Copy Markdown

@Montana Montana commented Mar 10, 2026

Hello Stanford University,

The most critical fix is preventing LDAP filter injection. The original code built filter strings with bare f-strings like f"uid={sunetid}", which means a malicious input like *)(|(cn=* could break out of the filter and return arbitrary results.

I added import ldap.filter at the top and created a private _build_uid_filter method that runs the sunetid through ldap.filter.escape_filter_chars() before interpolating it, and wraps the result in proper parentheses as (uid=...).

All three convenience methods — sunetid_account_info, sunetid_people_info, and sunetid_info — now use this helper instead of constructing the filter inline.

Sincerely,
Michael

The most critical fix is preventing LDAP filter injection. The original code built filter strings with bare f-strings like f"uid={sunetid}", which means a malicious input like *)(|(cn=* could break out of the filter and return arbitrary results. I added import ldap.filter at the top and created a private _build_uid_filter method that runs the sunetid through ldap.filter.escape_filter_chars() before interpolating it, and wraps the result in proper parentheses as (uid=...). 

All three convenience methods,  sunetid_account_info, sunetid_people_info, and sunetid_info,  now use this helper instead of constructing the filter inline.
@Montana Montana changed the title Refactor LDAP module and fix attribute casing Fix LDAP filter injection Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant