Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit cb64c95

Browse files
committed
Comment cleanups, log on KeyError during login
1 parent f240a8d commit cb64c95

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

synapse/handlers/auth.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ async def check_auth(
396396
# otherwise use whatever was last provided.
397397
#
398398
# This was designed to allow the client to omit the parameters
399-
# and just supply the session in subsequent calls so it split
399+
# and just supply the session in subsequent calls. So it splits
400400
# auth between devices by just sharing the session, (eg. so you
401401
# could continue registration from your phone having clicked the
402402
# email auth link on there). It's probably too open to abuse
@@ -876,7 +876,8 @@ async def validate_login(
876876
m.login.password auth types.
877877
878878
Args:
879-
username: username supplied by the user
879+
username: a localpart or fully qualified user ID - what is provided by the
880+
client
880881
login_submission: the whole of the login submission
881882
(including 'type' and other relevant fields)
882883
Returns:
@@ -888,10 +889,10 @@ async def validate_login(
888889
LoginError if there was an authentication problem.
889890
"""
890891

891-
if username.startswith("@"):
892-
qualified_user_id = username
893-
else:
894-
qualified_user_id = UserID(username, self.hs.hostname).to_string()
892+
# We need a fully qualified User ID for some method calls here
893+
qualified_user_id = username
894+
if not qualified_user_id.startswith("@"):
895+
qualified_user_id = UserID(qualified_user_id, self.hs.hostname).to_string()
895896

896897
login_type = login_submission.get("type")
897898
known_login_type = False

synapse/rest/client/v1/login.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ async def on_POST(self, request):
111111
result = await self.do_token_login(login_submission)
112112
else:
113113
result = await self._do_other_login(login_submission)
114-
except KeyError:
114+
except KeyError as e:
115+
logger.debug("KeyError during login: %s", e)
115116
raise SynapseError(400, "Missing JSON keys.")
116117

117118
well_known_data = self._well_known_builder.get_well_known()
@@ -181,8 +182,8 @@ async def _do_other_login(self, login_submission):
181182
except LoginError:
182183
# The user has failed to log in, so we need to update the rate
183184
# limiter. Using `can_do_action` avoids us raising a ratelimit
184-
# exception and masking the LoginError. The actual ratelimiting
185-
# should have happened above.
185+
# exception and masking the LoginError. This just records the attempt.
186+
# The actual rate-limiting happens above
186187
self._failed_attempts_ratelimiter.can_do_action(username.lower())
187188
raise
188189

@@ -195,10 +196,10 @@ async def _complete_login(
195196
self, user_id, login_submission, callback=None, create_non_existent_users=False
196197
):
197198
"""Called when we've successfully authed the user and now need to
198-
actually login them in (e.g. create devices). This gets called on
199-
all succesful logins.
199+
actually log them in (e.g. create devices). This gets called on
200+
all successful logins.
200201
201-
Applies the ratelimiting for succesful login attempts against an
202+
Applies the ratelimiting for successful login attempts against an
202203
account.
203204
204205
Args:

0 commit comments

Comments
 (0)