Skip to content

Accept an arpa suffix in any case and without the root dot in fromArpa - #227

Merged
beaugunderson merged 1 commit into
mainfrom
bg-arpa-root-dot
Sep 15, 2026
Merged

beaugunderson merged 1 commit into
mainfrom
bg-arpa-root-dot

Conversation

@beaugunderson

Copy link
Copy Markdown
Owner

Address4.fromArpa() stripped .in-addr.arpa only when a root dot followed it, so 1.0.0.127.in-addr.arpa threw with "IPv4 addresses are at most 15 characters." while 1.0.0.127.in-addr.arpa. parsed. Address6.fromArpa() already accepted both. Neither family accepted an uppercase suffix, though DNS names are case-insensitive.

The fix

Both suffix regexes are now /(\.<suffix>)?\.?$/i. Everything else is unchanged: the reversed labels still go through the constructor, which rejects anything that is not four octets, and fromArpa(x.reverseForm()) round-trips for a host and for a network.

Tests

Address4.fromArpa() had no tests of its own. This adds a block covering the plain reversal, the suffix with and without the root dot, the suffix in mixed case, the reverseForm() round trip for /32, /24 and /8, and rejection of names whose labels are not four octets. Address6.fromArpa() gets the mixed-case case alongside its existing prefix-length tests. The three new acceptance cases fail before the fix.

Reported by @waydeshi via GHSA-329j-wj2f-jq5q, declined as an advisory and fixed as a correctness bug: the throw is a clean rejection of a valid form, and reversing 127.0.0.1. to 1.0.0.127 is the function doing what its name says, since 127.0.0.1.in-addr.arpa is the PTR name of 1.0.0.127.

Address4.fromArpa() stripped `.in-addr.arpa` only when a root dot
followed it, so `1.0.0.127.in-addr.arpa` threw while
`1.0.0.127.in-addr.arpa.` parsed; Address6.fromArpa() already accepted
both. Neither family accepted an uppercase suffix, though DNS names are
case-insensitive.

Both now strip the suffix in any case, with or without the root dot.
Address4.fromArpa() also gets its own tests, including the reverseForm
round trip for a host and a network.
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.

1 participant