Skip to content

fix(network): replace LOCAL_HOSTS set with isLoopback predicate - #85

Merged
N-i-xx merged 2 commits into
Vero-protocol:mainfrom
Victorjonah-prog:fix/issue-75-loopback-host-detection
Aug 27, 2026
Merged

fix(network): replace LOCAL_HOSTS set with isLoopback predicate#85
N-i-xx merged 2 commits into
Vero-protocol:mainfrom
Victorjonah-prog:fix/issue-75-loopback-host-detection

Conversation

@Victorjonah-prog

Copy link
Copy Markdown

Summary

Fixes dead code and inconsistent loopback detection in validateUrl.

Problem

LOCAL_HOSTS contained a bare '::1' entry that could never match — the WHATWG URL parser always returns IPv6 hostnames in bracketed form (new URL('http://[::1]:8000').hostname === '[::1]'), so the bare form is unreachable.

The set also only covered 127.0.0.1 exactly, leaving the rest of the 127.0.0.0/8 loopback range (e.g. 127.0.0.2) unrecognised and treated as remote. allowInsecureLocalhost therefore behaved inconsistently for addresses a developer would reasonably expect to be local.

Changes

  • src/network/index.ts: removed LOCAL_HOSTS set; replaced with an isLoopback(hostname) predicate covering 'localhost', '[::1]' (the bracketed form the URL parser actually produces), and the full 127.0.0.0/8 range via regex.
  • src/__tests__/network.test.ts: added tests for http://127.0.0.2:8000 and http://[::1]:8000 both with and without allowInsecureLocalhost.

Tested

All 193 tests pass (npx jest), including 2 new cases covering the previously untested addresses.

Closes #75

The bare '::1' entry in LOCAL_HOSTS was dead code — the WHATWG URL parser
always returns IPv6 hostnames in bracketed form ([::1]), so it could never
match parsed.hostname.

The exact-match set also only covered 127.0.0.1, leaving the rest of the
127.0.0.0/8 loopback range (e.g. 127.0.0.2) unrecognised and treated as
remote, making allowInsecureLocalhost behave inconsistently.

Replace the set with an isLoopback() predicate that covers:
- 'localhost'
- '[::1]' (the form the URL parser actually returns)
- the full 127.0.0.0/8 range via regex

Add tests for http://127.0.0.2:8000 and http://[::1]:8000 with and
without allowInsecureLocalhost.

Closes Vero-protocol#75
@N-i-xx
N-i-xx merged commit 5e642e7 into Vero-protocol:main Aug 27, 2026
3 checks passed
@N-i-xx

N-i-xx commented Aug 27, 2026

Copy link
Copy Markdown

Merged — thanks for the contribution! If you've got a moment, a rating on GrantFox helps the project.

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.

Remove the unreachable '::1' entry from LOCAL_HOSTS

3 participants