1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41: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:
Natalia
2024-08-19 14:47:38 -03:00
parent 320dd27412
commit 8c35a0a903
8 changed files with 83 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import logging
import unicodedata
from django import forms
@@ -16,6 +17,7 @@ from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
UserModel = get_user_model()
logger = logging.getLogger("django.contrib.auth")
def _unicode_ci_compare(s1, s2):
@@ -418,7 +420,12 @@ class PasswordResetForm(forms.Form):
html_email = loader.render_to_string(html_email_template_name, context)
email_message.attach_alternative(html_email, "text/html")
email_message.send()
try:
email_message.send()
except Exception:
logger.exception(
"Failed to send password reset email to %s", context["user"].pk
)
def get_users(self, email):
"""Given an email, return matching user(s) who should receive a reset.