Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
In Development
--------------

* Internationalized domains with a "fake A-label", a non-canonical Punycode label such as `xn---bbk` that decodes to the same Unicode label as `xn--bbk`, are now rejected. With idna versions before 3.19, `me@xn---bbk.com` was accepted with the same normalized address as `me@xn--bbk.com` but with `ascii_email` holding the different domain `xn---bbk.com`.

2.4.0 (November 14, 2026)
-------------------------

Expand Down
14 changes: 11 additions & 3 deletions email_validator/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,20 @@ def validate_email_domain_name(domain: str, test_environment: bool = False, glob
except idna.IDNAError as e:
raise EmailSyntaxError(f"The part after the @-sign is not valid IDNA ({e}).") from e

# Check that it can be encoded back to IDNA ASCII. We have no test
# case for this.
# Check that it can be encoded back to IDNA ASCII, and that it encodes
# back to the same IDNA ASCII domain we started with. A "fake A-label"
# (RFC 5890 2.3.2.1) like xn---bbk is a non-canonical Punycode spelling
# of xn--bbk that decodes to the same Unicode label, so without this
# check two different domains could give the same normalized domain and
# ascii_domain would not be the IDNA ASCII form of domain (RFC 5891 5.4).
# idna 3.19 and later reject these in idna.decode but earlier versions
# do not. We have no test case for the exception.
try:
idna.encode(domain_i18n)
canonical_ascii_domain = idna.encode(domain_i18n).decode("ascii")
except idna.IDNAError as e:
raise EmailSyntaxError(f"The part after the @-sign became invalid after normalizing to international characters ({e}).") from e
if canonical_ascii_domain != ascii_domain:
raise EmailSyntaxError(f"The part after the @-sign is not valid IDNA (Its canonical IDNA ASCII form is {canonical_ascii_domain}).")

# Return the IDNA ASCII-encoded form of the domain, which is how it
# would be transmitted on the wire (except when used with SMTPUTF8
Expand Down
11 changes: 11 additions & 0 deletions tests/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,17 @@ def test_email_long_idna_domain_is_not_quadratic() -> None:
assert time.perf_counter() - start < 2


def test_email_fake_a_label() -> None:
# xn---bbk is a non-canonical Punycode spelling of xn--bbk (U+307E
# HIRAGANA LETTER MA). Before idna 3.19, idna.decode accepted it, so
# me@xn---bbk.com was valid with the same normalized address as
# me@xn--bbk.com but with ascii_email me@xn---bbk.com, a different domain.
assert validate_email("me@xn--bbk.com", check_deliverability=False).ascii_email == "me@xn--bbk.com"
for email in ("me@xn---bbk.com", "me@xn---4dbrk0ce.com"):
with pytest.raises(EmailSyntaxError, match="The part after the @-sign is not valid IDNA"):
validate_email(email, check_deliverability=False)


@pytest.mark.parametrize(
'email_input,error_msg',
[
Expand Down
Loading