Opened 5 weeks ago
Last modified 13 hours ago
#36017 assigned Bug
Urlize email address allows punctuation in domains
Reported by: | Mike Edmunds | Owned by: | Gregory Mariani |
---|---|---|---|
Component: | Utilities | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The urlize template filter incorrectly recognizes domains in email addresses, linkifying punctuation that shouldn't be included in the address:
# Django 5.1.4, Python 3.12.4 from django.template.defaultfilters import urlize urlize("email me@example.com,then I'll respond") 'email <a href="mailto:me@example.com,then">me@example.com,then</a> I'll respond' urlize("test@example?;+!.com") '<a href="mailto:test@example?;+!.com">test@example?;+!.com</a>'
The first example should probably stop before the comma. The second example probably shouldn't linkify at all.
See also #36012.
Change History (10)
comment:1 by , 5 weeks ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 4 weeks ago
comment:3 by , 4 weeks ago
Owner: | set to |
---|---|
Status: | new → assigned |
I have done a fix, need to run the CI to validate, first time on this repo for me:
django.utils.html.py
... @staticmethod def is_email_simple(value): """Return True if value looks like an email address.""" # An @ must be in the middle of the value. if "@" not in value or value.startswith("@") or value.endswith("@"): return False try: p1, p2 = value.split("@") except ValueError: # value contains more than one @. return False # Max length for domain name labels is 63 characters per RFC 1034. # Helps to avoid ReDoS vectors in the domain part. if len(p2) > 63: return False # Dot must be in p2 (e.g. example.com) if "." not in p2 or p2.startswith("."): return False try: validate_email(value) except ValidationError: return False return True
comment:4 by , 4 weeks ago
Has patch: | set |
---|
comment:5 by , 4 weeks ago
Needs tests: | set |
---|
comment:7 by , 20 hours ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 19 hours ago
Triage Stage: | Ready for checkin → Accepted |
---|
comment:9 by , 18 hours ago
Patch needs improvement: | set |
---|
comment:10 by , 13 hours ago
Patch needs improvement: | unset |
---|
@Sarah Boyce who change the triage if someone has already done a review on the PR ?
Note:
See TracTickets
for help on using tickets.
Possible fix: Urlizer could check that validate_email() would allow the email address before generating a mailto. That would result in it ignoring both of the examples above. (#36014 would need to be fixed first to avoid rejecting some international domains.)