Skip to content

Pin the connection to the address that was checked - #118

Open
Austin666k wants to merge 2 commits into
hanover-computing:masterfrom
Austin666k:fix/pin-checked-address
Open

Austin666k wants to merge 2 commits into
hanover-computing:masterfrom
Austin666k:fix/pin-checked-address

Conversation

@Austin666k

Copy link
Copy Markdown

protect() resolves the hostname once and checks that one address, but got resolves the hostname again when it connects. If the answer changes between the two lookups, or a multi-record answer has a public record first, the connection can reach an address that was never checked, such as loopback.

This change pins the connection's lookup to the validated address and turns off the DNS cache for the connection. The caller's original dnsCache/dnsLookup is kept on the pinned lookup, so redirect hops are still checked against the caller's resolver.

Changes

  • index.ts: pin the connection lookup after the check; keep the original DNS settings across hops.
  • index.test.ts: regression test that the connection uses the checked address.
  • Formatting: a separate commit applies the repository's .prettierrc.yml so that lint:prettier passes.

Testing

  • npx vitest run: 27 passed.
  • npx tsc -p tsconfig.build.json --noEmit: clean.
  • npx eslint index.ts index.test.ts: clean.
  • Socket-level check (simulated DNS answers, loopback-only listener): the 3.0.0 build reaches the loopback listener when the answer changes or when the first record is public. The patched build does not.

I emailed a description of this issue to the npm-listed maintainer address before opening this PR.

🤖 Generated with Claude Code

Austin666k and others added 2 commits October 23, 2026 17:17
protect() resolves the hostname once and checks that single address, but
got then resolves the hostname again when it connects. A DNS answer that
changes between the two lookups, or a multi-record answer whose first
record is public, lets the connection reach an address that was never
checked (for example loopback).

After the check, pin the connection's lookup to the validated address,
and turn off the DNS cache so it cannot answer with another address. The
caller's original dnsCache/dnsLookup is kept on the pinned lookup so that
redirect hops still check against the right resolver.

Adds a regression test that the connection uses the checked address.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Apply the repository's .prettierrc.yml to the changed files so that
lint:prettier passes.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
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