Skip to content

Commit

Permalink
Escape comma in resolved_username
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirschf committed Jun 6, 2018
1 parent 1bb93f3 commit c881a9f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _server_port_default(self):
Unicode Example:
uid={username},ou=people,dc=wikimedia,dc=org
List Example:
[
uid={username},ou=people,dc=wikimedia,dc=org,
Expand Down Expand Up @@ -260,8 +260,8 @@ def escape_userdn_if_needed(self, userdn):
config=True,
help="List of attributes to be searched"
)


@gen.coroutine
def authenticate(self, handler, data):
username = data['username']
Expand All @@ -284,7 +284,7 @@ def getConnection(userdn, username, password):
auto_bind=ldap3.AUTO_BIND_TLS_BEFORE_BIND,
)
return conn

# Protect against invalid usernames as well as LDAP injection attacks
if not re.match(self.valid_username_regex, username):
self.log.warn('username:%s Illegal characters in username, must match regex %s', username, self.valid_username_regex)
Expand All @@ -302,6 +302,8 @@ def getConnection(userdn, username, password):
if resolved_username is None:
return None

resolved_username = re.subn(r"[^\\],", r"\,", resolved_username)[0]

bind_dn_template = self.bind_dn_template
if isinstance(bind_dn_template, str):
# bind_dn_template should be of type List[str]
Expand All @@ -317,15 +319,15 @@ def getConnection(userdn, username, password):
msg += '\n{exc_type}: {exc_msg}'.format(
exc_type=exc.__class__.__name__,
exc_msg=exc.args[0] if exc.args else ''
)
)
else:
isBound = conn.bind()
msg = msg.format(
username=username,
userdn=userdn,
isBound=isBound
)
self.log.debug(msg)
self.log.debug(msg)
if isBound:
break

Expand Down

0 comments on commit c881a9f

Please sign in to comment.