Should an IPv4 address input to idna.Registration.ToASCII() return an error or not?

134 views
Skip to first unread message

redder

unread,
Nov 12, 2022, 11:22:21 AM11/12/22
to golang-nuts
https://go.dev/play/p/HdLLJz0uz2q

idna.Registration.ToASCII("100.100.100.100") doesn't return an error. Surely an IPv4 address can never be registered as a domain name and so this should return an error? I just need confirmation: is this function working as expected or is this a bug?

Kurtis Rader

unread,
Nov 12, 2022, 9:00:16 PM11/12/22
to redder, golang-nuts
I think you've misunderstood the purpose of that package and the relevant standards. An IPv4 address is syntactically a valid domain name and thus no error occurs. The ToASCII conversion is a nop in this case since there are no non-ASCII characters. An IPv6 address is not a syntactically valid domain name so you'll get an error. There is nothing about the conversion process that requires validating whether the TLD (the right-most "100" in your example) is in fact a valid TLD.

On Sat, Nov 12, 2022 at 8:22 AM redder <just...@gmail.com> wrote:
https://go.dev/play/p/HdLLJz0uz2q

idna.Registration.ToASCII("100.100.100.100") doesn't return an error. Surely an IPv4 address can never be registered as a domain name and so this should return an error? I just need confirmation: is this function working as expected or is this a bug?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/792a7e4a-3335-40c2-8fe9-fca394d2f988n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

redder

unread,
Nov 14, 2022, 12:20:17 AM11/14/22
to golang-nuts
I suspected this to be the case but wasn't completely sure. Thank you for confirming.

Perhaps I don't understand how this function is typically used in practice, but to me it seems using Registration.ToASCII() alone is never sufficient for registerable domain name validation. In addition to it, one should always check if the input was not an IPv4 address to be thorough. Or is it expected that typical users of this function will further validate the domain name against a whitelist of TLDs, hence making the IPv4 check unnecessary?

Kurtis Rader

unread,
Nov 14, 2022, 6:13:33 PM11/14/22
to redder, golang-nuts
The idna.Registration.ToASCII function only validates that a domain name can be registered in the sense that it is syntactically valid; not that it makes sense semantically including that the TLD is valid. You can pass it the string "a" and it will return that string without error. Its purpose is to rewrite a domain name containing non-ASCII characters into one which only contains ASCII chars in accordance with the IDNA standard. Which means a domain name like "100.100.100.100" is no different than "a.b.c.d" as far as idna.Registration.ToASCII() is concerned.

Reply all
Reply to author
Forward
0 new messages