Is this host the loopback machine, whatever spelling it arrived in?
THE ANSWER COMES FROM PARSING AN ADDRESS, NEVER FROM HOW THE TEXT BEGINS. A prefix test like
/^127\./ matches 127.evil.com, 127.0.0.1.nip.io and 127.com — all registrable by anyone
— and misses real loopback spellings such as 0177.0.0.1 or [::ffff:127.0.0.1]. It is wrong
in both directions, which is what a string standing in for an address decision usually is.
The verdict is core's isLoopbackLiteral. This adds only the legacy IPv4 canonicalization a
nats:// host needs, because no URL parser normalizes a non-special scheme's host. Brackets are
tolerated so a caller may pass a URL hostname straight in.
Is this host the loopback machine, whatever spelling it arrived in?
THE ANSWER COMES FROM PARSING AN ADDRESS, NEVER FROM HOW THE TEXT BEGINS. A prefix test like
/^127\./matches127.evil.com,127.0.0.1.nip.ioand127.com— all registrable by anyone — and misses real loopback spellings such as0177.0.0.1or[::ffff:127.0.0.1]. It is wrong in both directions, which is what a string standing in for an address decision usually is.The verdict is core's
isLoopbackLiteral. This adds only the legacy IPv4 canonicalization anats://host needs, because no URL parser normalizes a non-special scheme's host. Brackets are tolerated so a caller may pass a URL hostname straight in.