You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
validate.Email accepts a leading/trailing hyphen in the last domain label #3072
validate.Email is currently allowing domain names that start or end with a hyphen to bypass in certain cases such as “user@example.-com”, “user@example.com-”. We believe domain labels must not start or end with a hyphen (RFC 5321 §4.1.2), and Email already rejects this for the other labels, e.g. “user@ex-.com”
After some investigation, the cause is how Email.DOMAIN_REGEX matches the last domain label, which allows a hyphen to appear anywhere. To fix this, we can wrap that alternative in two lookarounds so the label can neither start nor end with a hyphen: (?!-) at the start and (?<!-) at the end. Django's URLValidator uses the same approach for its TLD regex.
marshmallow 4.3.1 (same on dev at 1c63bda), Python 3.12
AI usage disclosure
This bug was detected by our bug detection tool, which is built on PatchGuru. Two authors carefully reviewed all warnings raised by the tool, and we report only warnings which are likely real bugs. The report and reproduction tests were manually drafted by authors based on evidence provided by the tool and independently verified by two authors.
Activity
X6M-Work commentedon Nov 7, 2026