Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
rate_limit: Rate-limit password reset attempts by IP, as well.
Alex Vandiverd3ecbf96a840
diff --git a/zerver/forms.py b/zerver/forms.pyindex 66d4e6f733e..33a589127a4 100644--- a/zerver/forms.py+++ b/zerver/forms.py@@ -18,6 +18,7 @@ from jinja2.utils import Markup as mark_safefrom two_factor.forms import AuthenticationTokenForm as TwoFactorAuthenticationTokenFormfrom two_factor.utils import totp_digits+from zerver.decorator import rate_limit_request_by_ipfrom zerver.lib.actions import do_change_password, email_not_system_botfrom zerver.lib.email_validation import email_allowed_for_realmfrom zerver.lib.exceptions import JsonableError, RateLimited@@ -323,9 +324,14 @@ class ZulipPasswordResetForm(PasswordResetForm):if settings.RATE_LIMITING:try:rate_limit_password_reset_form_by_email(email)+ rate_limit_request_by_ip(request, domain="sends_email_by_ip")except RateLimited:# TODO: Show an informative, user-facing error message.- logging.info("Too many password reset attempts for email %s", email)+ logging.info(+ "Too many password reset attempts for email %s from %s",+ email,+ request.META["REMOTE_ADDR"],+ )returnuser: Optional[UserProfile] = Nonediff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 7b18da6daf7..234b1c7af83 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -586,7 +586,9 @@ class PasswordResetTest(ZulipTestCase):self.client_post("/accounts/password/reset/", {"email": email})self.assertEqual(info_logs.output,- ["INFO:root:Too many password reset attempts for email [email protected]"],+ [+ "INFO:root:Too many password reset attempts for email [email protected] from 127.0.0.1"+ ],)self.assert_length(outbox, 2)