Skip to content

Commit

Permalink
Escape all user- or ldap-provided strings in search queries to preven…
Browse files Browse the repository at this point in the history
…t malformed LDAP filters
  • Loading branch information
m-erhardt committed Jul 9, 2024
1 parent ba1e059 commit d5e2fc2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def resolve_username(self, username_supplied_by_user):
return (None, None)

search_filter = self.lookup_dn_search_filter.format(
login_attr=self.user_attribute, login=username_supplied_by_user
login_attr=self.user_attribute, login=escape_filter_chars(username_supplied_by_user)
)
msg = "\n".join(
[
Expand Down Expand Up @@ -396,7 +396,7 @@ def authenticate(self, handler, data):

if self.search_filter:
search_filter = self.search_filter.format(
userattr=self.user_attribute, username=username
userattr=self.user_attribute, username=escape_filter_chars(username)
)
conn.search(
search_base=self.user_search_base,
Expand Down Expand Up @@ -434,7 +434,10 @@ def authenticate(self, handler, data):
"(memberUid={uid})"
")"
)
group_filter = group_filter.format(userdn=userdn, uid=username)
group_filter = group_filter.format(
userdn=escape_filter_chars(userdn),
uid=escape_filter_chars(username)
)
group_attributes = ["member", "uniqueMember", "memberUid"]
found = conn.search(
group,
Expand Down

0 comments on commit d5e2fc2

Please sign in to comment.