Repository navigation
Reject non-canonical Punycode A-labels in validate_email_domain_name - #196
Open
Keerthana-64 wants to merge 1 commit into
Open
Keerthana-64 wants to merge 1 commit into
Keerthana-64 wants to merge 1 commit into
Conversation
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.
Owner
|
This is starting to seem a little pedantic. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.