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

Commit 18c5166

Browse files
Return a different error from Invalid Password when a user is deactivated (#5674)
Return `This account has been deactivated` instead of `Invalid password` when a user is deactivated.
1 parent d863213 commit 18c5166

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

changelog.d/5674.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Return "This account has been deactivated" when a deactivated user tries to login.

synapse/api/errors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ def error_dict(self):
139139
return cs_error(self.msg, self.errcode, consent_uri=self._consent_uri)
140140

141141

142+
class UserDeactivatedError(SynapseError):
143+
"""The error returned to the client when the user attempted to access an
144+
authenticated endpoint, but the account has been deactivated.
145+
"""
146+
147+
def __init__(self, msg):
148+
"""Constructs a UserDeactivatedError
149+
150+
Args:
151+
msg (str): The human-readable error message
152+
"""
153+
super(UserDeactivatedError, self).__init__(
154+
code=http_client.FORBIDDEN, msg=msg, errcode=Codes.UNKNOWN
155+
)
156+
157+
142158
class RegistrationError(SynapseError):
143159
"""An error raised when a registration event fails."""
144160

synapse/handlers/auth.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
LoginError,
3636
StoreError,
3737
SynapseError,
38+
UserDeactivatedError,
3839
)
3940
from synapse.api.ratelimiting import Ratelimiter
4041
from synapse.logging.context import defer_to_thread
@@ -623,6 +624,7 @@ def check_user_exists(self, user_id):
623624
Raises:
624625
LimitExceededError if the ratelimiter's login requests count for this
625626
user is too high too proceed.
627+
UserDeactivatedError if a user is found but is deactivated.
626628
"""
627629
self.ratelimit_login_per_account(user_id)
628630
res = yield self._find_user_id_and_pwd_hash(user_id)
@@ -838,6 +840,13 @@ def _check_local_password(self, user_id, password):
838840
if not lookupres:
839841
defer.returnValue(None)
840842
(user_id, password_hash) = lookupres
843+
844+
# If the password hash is None, the account has likely been deactivated
845+
if not password_hash:
846+
deactivated = yield self.store.get_user_deactivated_status(user_id)
847+
if deactivated:
848+
raise UserDeactivatedError("This account has been deactivated")
849+
841850
result = yield self.validate_hash(password, password_hash)
842851
if not result:
843852
logger.warn("Failed password login for user %s", user_id)

0 commit comments

Comments
 (0)