Skip to content

Reject non-canonical Punycode A-labels in validate_email_domain_name - #196

Open
Keerthana-64 wants to merge 1 commit into
JoshData:mainfrom
Keerthana-64:idna-fake-alabel
Open

Keerthana-64 wants to merge 1 commit into
JoshData:mainfrom
Keerthana-64:idna-fake-alabel

Conversation

@Keerthana-64

Copy link
Copy Markdown
Contributor

validate_email_domain_name runs an ascii domain with xn-- labels through idna.decode and then idna.encode, but only checks that the encode doesn't raise and never compares the result with ascii_domain. before idna 3.19, which idna>=2.0.0 still allows, idna.ulabel didn't require an a-label to be the canonical punycode of its u-label (rfc 5891 5.4), so a "fake a-label" (rfc 5890 2.3.2.1) like xn---bbk, whose leading hyphen is an empty delimiter that python's punycode codec skips, decodes to the same label (U+307E) as xn--bbk. with idna 3.18, 3.10 or 2.10, validate_email("me@xn---bbk.com") is valid with the same normalized address as me@xn--bbk.com but with ascii_email me@xn---bbk.com, a different dns name, and check_deliverability looks up that name rather than the one in normalized. the readme describes ascii_email as the idna form of normalized and recommends storing normalized, so two addresses on different dns names end up as one database key. comparing the re-encoded domain with ascii_domain rejects these on every idna version, with a message that gives the canonical form. over 58,867 generated domains (unicode, a-label, uppercase and fake a-label labels) nothing changed with idna 3.20, and with 3.18 and 3.10 exactly the 476 addresses whose ascii_email wasn't the idna form of normalized became invalid, after which every result matches idna 3.20. raising the minimum idna to 3.19 would also work, but that release is from august 2026 and this check keeps older installs covered. test_email_fake_a_label fails on main with idna 3.18, 3.10 and 2.10 and passes here; with 3.19+ it passes either way because idna.decode already rejects these. flake8, mypy and the suite pass on 3.11 and 3.13.

validate_email_domain_name re-encodes the domain it got from idna.decode
but only checks that idna.encode doesn't raise. before idna 3.19, which
idna>=2.0.0 still allows, ulabel accepted a-labels that aren't the
canonical punycode of their u-label (rfc 5891 5.4), so me@xn---bbk.com
validated with the same normalized address as me@xn--bbk.com but with
ascii_email holding the different domain xn---bbk.com. reject the
address when the re-encoded domain differs from ascii_domain.
@JoshData

Copy link
Copy Markdown
Owner

This is starting to seem a little pedantic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants