test(idn-email): add address-literal coverage - #1035
Conversation
jviotti
left a comment
There was a problem hiding this comment.
Being the only one passing this made me a bit more nervous but it does seem like it's correct. Would love a second eye on this though! cc @jdesrosiers
You're spot on. I was not doing address literal validation in V4 at all. V5 had an adjacent bug that was allowing invalid ASCII because it was just rejecting the disallowed IDN-rune list. So V5 was doing exactly what you're doing (and what this tests), but had a different issue! |
a67904d to
bb0f904
Compare
I'm not sure I agree with that logic. The comment is adding additional constraints to the abnf. It says that the value represents and integer. Integers aren't represented with preceding zeros. Just like the comment restricts the value to represent numbers more that 255, I think it also restricts leading zeros. |
Following the methodology I used for ipv4 and uuid, I read RFC 5321 section 4.1.3 and found that
idn-email.jsonhas no address-literal tests at all, whileemail.jsonhas three. RFC 6531 does not change the address-literal branch, so everythingemailtests there applies toidn-emailtoo.The interesting one is the leading zero.
Snum = 1*3DIGITwith the comment "representing a decimal integer value in the range 0 through 255", so the rule constrains the value and not the digit count -01is a legalSnum. That differs from the dec-octet rule behindformat: ipv4, which forbids leading zeros, so an implementation that reuses its ipv4 checker for the bracket form gets this wrong.Changes
δοκιμή@[192.0.2.1]- a non-ASCII local part with an IPv4-address-literal - valid.δοκιμή@[IPv6:2001:db8::1]- a non-ASCII local part with an IPv6-address-literal - valid.user@[192.0.2.300]- an octet over 255 inside the brackets - invalid.user@[01.0.0.1]- leading zeros in an octet - valid.Ecosystem Impact
is_snuminsrc/core/email/helpers.hchecks the parsed value against 255 rather than the digit count, and the comment there calls out the difference from the RFC 3986 dec-octet behindis_ipv4.user@[01.0.0.1], and also[192.168.1.1]and the IPv6 form) - it does not implement the address-literal branch.user@[01.0.0.1]and the IPv6 form).user@[01.0.0.1]).user@[01.0.0.1]even withallow_domain_literal=True) - it hands the bracket contents to Python'sipaddress.IPv4Address, which raisesAddressValueError: Leading zeros are not permitted.user@[01.0.0.1]even withallow_ip_domain: true) - same shape, a strict IPv4 pattern applied to the literal.RFC References
Snumand the IPv6 form): https://www.rfc-editor.org/rfc/rfc5321#section-4.1.3Reproduction commands and the idn-email cross-implementation matrix are in my evidence repo: https://github.com/vtushar06/JSON-Schema-format-test-Evidence/blob/main/idn-email.md
Related: #965