Skip to content

fix(cli): correctly identify localhost loopback URLs - #67420

Merged
neriousy merged 1 commit into
anomalyco:devfrom
AdemGhalleb:fix/localhost-trailing-dot-loopback
Dec 1, 2026
Merged

neriousy merged 1 commit into
anomalyco:devfrom
AdemGhalleb:fix/localhost-trailing-dot-loopback

Conversation

@AdemGhalleb

@AdemGhalleb AdemGhalleb commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #67419

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

isLoopback() did not recognize hostnames ending with a trailing DNS dot, such as localhost..

This PR fixes the classification by removing one trailing dot before checking localhost names. It also uses Node's isIP() to ensure that addresses beginning with 127. are actually valid IPv4 addresses, preventing hostnames such as 127.example.com from being incorrectly classified as loopback.

Added regression tests covering trailing-dot localhost, IPv4, IPv6, and ordinary hostnames.

How did you verify your code works?

  • Node-based checks passed for the hostname cases.
  • Prettier check passed.
  • git diff --check passed.
  • The Bun test suite could not complete because the dependency installation was incomplete (@babel/types was missing).

Screenshots / recordings

Not applicable.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Nov 30, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. I called machineReach/formatMachineAdd directly on the base and with this PR. On the base, --url http://localhost.:4096 was reported as "Works from computers that can reach one of these addresses", and 127.example.com was reported as "Only works on this computer". With the PR both are classified correctly, and 127.0.0.1 is still loopback. test/machine.test.ts passes (22 tests) and tsc -b is clean.

Public API: unchanged (isLoopback is internal to the CLI).

One small note: every caller passes URL.hostname, which keeps the brackets on IPv6 ([::1]). So the bare ::1 check never receives real input and could be dropped. It does no harm either way.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@ambujone ambujone left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran bun test test/machine.test.ts in packages/cli on the PR head: 22 pass. With src/ reverted to the parent commit and the new tests kept, 4 fail (localhost., api.localhost., 127.example.com, ::1), so the tests do exercise the change. bun typecheck in packages/cli is clean. I also fed new URL(...).hostname for several inputs through isLoopback: http://localhost.:4096, http://LOCALHOST.:1, http://127.1:4096 (URL normalizes to 127.0.0.1) and http://127.0.0.1.:1 classify as loopback, and 127.example.com and localhost.. do not. One small thing: URL.hostname always brackets IPv6, so the new bare "::1" branch in service-urls.ts is only reachable by calling isLoopback directly; harmless, but you could drop it and the ::1 test case if you want the helper to match its callers (machine/common.ts:41,61 and pair.ts:34). The check at pair.ts:59 uses its own exact-match list and still shows no SSH-forward hint for localhost., which is cosmetic and arguably out of scope.

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.

CLI machine pairing incorrectly classifies trailing-dot localhost as remote

3 participants