Skip to content

fix(peer): refuse our own address written with a trailing dot - #1198

Draft
hackobi wants to merge 2 commits into
stabilisationfrom
chef/peer-self-url-trailing-dot
Draft

hackobi wants to merge 2 commits into
stabilisationfrom
chef/peer-self-url-trailing-dot

Conversation

@hackobi

@hackobi hackobi commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

What changed and why

PeerManager.urlPointsAtUs decides whether an advertised peer URL is this node's own address. It compared the two hostnames as exact strings. The URL parser keeps a trailing dot (http://us.example.:53550 has hostname us.example.), and a trailing dot is the absolute form of the same DNS name. So another identity advertising our own address with a trailing dot was not refused by addPeer / canAddPeer, and the same happened the other way round when EXPOSED_URL itself is written with the dot.

This PR strips trailing dots from both hostnames before comparing. It reuses the linear stripTrailingDots that isLoopbackHost already uses in src/config/nodeUrl.ts (now exported and re-exported from src/config). The port check, the loopback branch and the exemption for our own identity are unchanged.

Scope: this is only the self-address piece of an older peer-admission proposal. It does not change how peer identities are stored or compared, and it does not touch the "URL already bound to another identity" check (see follow-ups).

Two commits, test first:

  • 8418608b adds src/libs/peer/selfUrlAlias.test.ts. Through canAddPeer and addPeer it checks that another identity is refused at our address with a trailing dot, and at our plain address when we advertise the dotted form. Four controls: our exact address is refused; another host with a trailing dot, our host on another port, and our own identity at our own address are accepted.
  • a147dad0 makes the comparison ignore trailing dots, and adds the test to scripts/test-consensus.sh so CI runs it. It also adds two eslint-disable-next-line comments to the test file; no assertion differs between the two commits.

The one-line change in scripts/test-consensus.sh may conflict with other open PRs that add a test to the same list.

How it was checked

Run on macOS with Bun 1.4.4 (the version the repo pins), after bun install --frozen-lockfile.

Command At 8418608b (test only) At a147dad0 (head)
bun test ./src/libs/peer/selfUrlAlias.test.ts exit 1 (4 pass, 2 fail: the two trailing-dot cases) exit 0 (6 pass)

At the head, compared with stabilisation at 21095de5 on the same machine:

  • bun run type-check: exit 0.
  • bun run test:release: exit 0. bun test testing/forks/rehearsal/: exit 0.
  • bun run test:consensus: 186 files, 1 failed (scripts/node-doctor.test.ts, 16 failing tests). The base has 185 files and the same file failing with the same 16 tests. The new file runs in it: 6 pass.
  • bash scripts/launcher-wipe-guard.test.sh: exit 4 at the head and at the base.
  • eslint .: output identical to the base; the only entries in the changed files are three existing no-console warnings in src/config/nodeUrl.ts. tsc --noEmit: 413 errors at the head and at the base, none in the changed files.

The base failures were not investigated; they may be specific to this machine.

Builder and verifier

  • Built by an AI coding agent (Claude Opus 5.5) under a lead agent that planned and checked the work.
  • Independently reviewed by a second AI system (Grok) at a147dad03020b302f69b0e33befe5c9763fb93a2: verdict approve, no critical or high findings. The review read the code; it did not run it.
  • No human has reviewed this yet. It is a draft for the node owners.

Follow-ups (from the review, not in this PR)

  • Medium, existing: the URL-binding check has the same gap. findPeersByUrl compares raw origins, so identity B at http://alice.example.:53550 is not seen as colliding with identity A at http://alice.example:53550. The reviewer judges the harm bounded, because a hello to that address is answered by A's key and fails the identity check. Suggested fix: one canonicalOrigin(url) in nodeUrl.ts, used by both findPeersByUrl and urlPointsAtUs, with a test.
  • Low, existing: false "another process is using our identity" signal. manageHelloPeer.ts and identityLiveness.ts compare our origin with a reported origin as raw strings, so a dotted and an undotted spelling of our own address count as a twin.
  • Low: two CI tests mock src/config with a fixed export list that lacks stripTrailingDots (GossipManager.lifecycle.test.ts, helloGenesisGate.test.ts). Both pass at this head in the run above (8 and 7 pass).
  • Low: EXPOSED_URL=http://.:53550 is accepted by validateExposedUrl, and its hostname now strips to an empty string. Only a nonsensical configuration is affected.
  • Low: test gaps. No case with the dot on both sides, and none for the prod loopback branch with a dotted name.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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