Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

auth: Don't log email when user tried authing to the wrong subdomain.

Mateusz Mandera71f6f2310c61
diff --git a/zerver/forms.py b/zerver/forms.py
index 65eb4e96987..12691fc5ac3 100644
--- a/zerver/forms.py
+++ b/zerver/forms.py
@@ -460,7 +460,9 @@ class OurAuthenticationForm(AuthenticationForm):
if return_data.get("invalid_subdomain"):
logging.warning(
- "User %s attempted password login to wrong subdomain %s", username, subdomain
+ "User attempted password login to wrong subdomain %s. Matching accounts: %s",
+ subdomain,
+ return_data.get("matching_user_ids_in_different_realms"),
)
error_message = _(
"Your Zulip account {username} is not a member of the "
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
index c932ddc756e..14b47a45b47 100644
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -821,13 +821,15 @@ class LoginTest(ZulipTestCase):
self.assert_logged_in_user_id(None)
def test_login_wrong_subdomain(self) -> None:
- email = self.mit_email("sipbtest")
+ user_profile = self.mit_user("sipbtest")
+ email = user_profile.delivery_email
with self.assertLogs(level="WARNING") as m:
result = self.login_with_return(email, "xxx")
+ matching_accounts_dict = {"realm_id": user_profile.realm_id, "id": user_profile.id}
self.assertEqual(
m.output,
[
- "WARNING:root:User [email protected] attempted password login to wrong subdomain zulip"
+ f"WARNING:root:User attempted password login to wrong subdomain zulip. Matching accounts: [{matching_accounts_dict}]"
],
)
self.assertEqual(result.status_code, 200)
diff --git a/zproject/backends.py b/zproject/backends.py
index abb4b130f56..f460794a058 100644
--- a/zproject/backends.py
+++ b/zproject/backends.py
@@ -219,6 +219,9 @@ def common_get_active_user(
return None
if return_data is not None:
return_data["invalid_subdomain"] = True
+ return_data["matching_user_ids_in_different_realms"] = list(
+ UserProfile.objects.filter(delivery_email__iexact=email).values("realm_id", "id")
+ )
return None
if not is_user_active(user_profile, return_data):
return None