Skip to content

Commit 01c60cd

Browse files
authored
Quote username in SCRAM auth (aio-libs#1043)
1 parent e2afc03 commit 01c60cd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

aiokafka/conn.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,13 @@ def __init__(
719719
self._authenticator = self.authenticator_scram()
720720

721721
def first_message(self):
722-
client_first_bare = f"n={self._sasl_plain_username},r={self._nonce}"
722+
# The characters ',' or '=' in usernames are sent as '=2C' and
723+
# '=3D' respectively.
724+
# https://datatracker.ietf.org/doc/html/rfc5802#section-5.1
725+
quoted_username = (
726+
self._sasl_plain_username.replace("=", "=3D").replace( ",", "=2C")
727+
) # fmt: skip
728+
client_first_bare = f"n={quoted_username},r={self._nonce}"
723729
self._auth_message += client_first_bare
724730
return "n,," + client_first_bare
725731

0 commit comments

Comments
 (0)