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:

  1. send_mail() on a validated address raises an uncaught ValueError ("Header values may not contain linefeed or carriage return characters") from Python's email.policy serialization. PasswordResetForm.send_mail swallows it via a broad except Exception; other callers surface it as a 500.
  2. django/core/mail/backends/smtp.py prep_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)

poc.py​ (2.0 KB ) - added by Shai Berger 16 minutes ago.
output.txt​ (931 bytes ) - added by Shai Berger 16 minutes ago.

Download all attachments as: .zip

Change History (3)

by Shai Berger, 16 minutes ago

Attachment: poc.py​ added

by Shai Berger, 16 minutes ago

Attachment: output.txt​ added

comment:1 by Jacob Walls, 15 minutes ago

Keywords: not-security added
Triage Stage: Unreviewed → Accepted
Note: See TracTickets for help on using tickets.
Back to Top