mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed CVE-2024-45231 -- Avoided server error on password reset when email sending fails.
On successful submission of a password reset request, an email is sent to the accounts known to the system. If sending this email fails (due to email backend misconfiguration, service provider outage, network issues, etc.), an attacker might exploit this by detecting which password reset requests succeed and which ones generate a 500 error response. Thanks to Thibaut Spriet for the report, and to Mariusz Felisiak, Adam Johnson, and Sarah Boyce for the reviews.
This commit is contained in:
@@ -1357,6 +1357,27 @@ class PasswordResetFormTest(TestDataMixin, TestCase):
|
||||
)
|
||||
)
|
||||
|
||||
@override_settings(EMAIL_BACKEND="mail.custombackend.FailingEmailBackend")
|
||||
def test_save_send_email_exceptions_are_catched_and_logged(self):
|
||||
(user, username, email) = self.create_dummy_user()
|
||||
form = PasswordResetForm({"email": email})
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
with self.assertLogs("django.contrib.auth", level=0) as cm:
|
||||
form.save()
|
||||
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
self.assertEqual(len(cm.output), 1)
|
||||
errors = cm.output[0].split("\n")
|
||||
pk = user.pk
|
||||
self.assertEqual(
|
||||
errors[0],
|
||||
f"ERROR:django.contrib.auth:Failed to send password reset email to {pk}",
|
||||
)
|
||||
self.assertEqual(
|
||||
errors[-1], "ValueError: FailingEmailBackend is doomed to fail."
|
||||
)
|
||||
|
||||
@override_settings(AUTH_USER_MODEL="auth_tests.CustomEmailField")
|
||||
def test_custom_email_field(self):
|
||||
email = "test@mail.com"
|
||||
|
||||
Reference in New Issue
Block a user