Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
CVE-2024-56136: Don't leak information via "invalid subdomain" error.
Mateusz Manderad1cbb0dd59c1
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex 806f0c7901e..393a1a62560 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -5029,6 +5029,22 @@ class FetchAPIKeyTest(ZulipTestCase):)self.assert_json_error(result, "Invalid subdomain", 404)+ def test_login_wrong_subdomain(self) -> None:+ user = self.mit_user("starnine")+ result = self.client_post(+ "/api/v1/fetch_api_key",+ dict(username=user.email, password=initial_password(user.email)),+ subdomain="zulip",+ )+ self.assert_json_error(result, "Your username or password is incorrect", 401)++ result = self.client_post(+ "/api/v1/fetch_api_key",+ dict(username=user.email, password="wrongpass"),+ subdomain="zulip",+ )+ self.assert_json_error(result, "Your username or password is incorrect", 401)+def test_password_auth_disabled(self) -> None:with mock.patch("zproject.backends.password_auth_enabled", return_value=False):result = self.client_post(@@ -7781,7 +7797,7 @@ class JWTFetchAPIKeyTest(ZulipTestCase):web_token = jwt.encode(payload, key, algorithm)req_data = {"token": web_token}result = self.client_post("/api/v1/jwt/fetch_api_key", req_data)- self.assert_json_error_contains(result, "Invalid subdomain", 404)+ self.assert_json_error_contains(result, "Your username or password is incorrect", 401)class LDAPGroupSyncTest(ZulipTestCase):diff --git a/zerver/views/auth.py b/zerver/views/auth.pyindex f46f617fc60..27cc02dd827 100644--- a/zerver/views/auth.py+++ b/zerver/views/auth.py@@ -1034,7 +1034,10 @@ def get_api_key_fetch_authenticate_failure(return_data: dict[str, bool]) -> Jsonif return_data.get("password_reset_needed"):return PasswordResetRequiredError()if return_data.get("invalid_subdomain"):- raise InvalidSubdomainError+ # We must not report invalid_subdomain here; that value is intended only for informing server logs,+ # and should never be exposed to end users, since it would leak whether there exists+ # an account in a different organization with the same email address.+ return AuthenticationFailedError()return AuthenticationFailedError()