Opened 17 minutes ago
Last modified 15 minutes ago
#37515 new Bug
DomainNameValidator accepts Unicode line/paragraph separators in domains
| Reported by: | Shai Berger | Owned by: | |
|---|---|---|---|
| Component: | Forms | Version: | 6.1 |
| Severity: | Normal | Keywords: | not-security |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
django/core/validators.py builds hostname_re / domain_re / tld_re using the raw codepoint range [a-z\u00a1-\uffff0-9-]. That range includes
Unicode line and paragraph separators and several invisible space characters (U+2028, U+2029, U+1680, U+2000–200A, U+3000, U+FEFF), so they are accepted whenever they appear in a non-final domain label.
EmailValidator and URLValidator reuse these regexes, so EmailField.is_valid() returns True for such values.
Two consequences:
send_mail()on a validated address raises an uncaughtValueError("Header values may not contain linefeed or carriage return characters") from Python'semail.policyserialization.PasswordResetForm.send_mailswallows it via a broadexcept Exception; other callers surface it as a 500.django/core/mail/backends/smtp.pyprep_address()silently strips the separators, so the envelope recipient differs from the validated address (user@example\u2028.com→user@example.com).
POC script and its output attached.
Suggested fix
In DomainNameValidator.__call__(), reject characters whose unicodedata.category(ch)[0] is C or Z, or narrow the \u00a1-\uffff range to actual letter/digit categories. This covers EmailValidator, URLValidator, and simple_url_2_re consumers.
Regression cases: user@example\u2028.com, exa\u1680mple.com, http://example\u2029.com/.
Acknowledgement
This was a report received by the security team. The reporter did not respond when asked to open a ticket, so I'm opening it. I edited the report a little.
Attachments (2)
Change History (3)
by , 16 minutes ago
by , 16 minutes ago
| Attachment: | output.txt added |
|---|
comment:1 by , 15 minutes ago
| Keywords: | not-security added |
|---|---|
| Triage Stage: | Unreviewed → Accepted |