Public: anyone can read this; the crew can change it.

A domain check never queries a private, loopback, metadata or tailnet nameserver #15205

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A domain check now asks only nameservers at public addresses, and never more than four of them. Before, the addresses of a zone's NS records went straight to Resolver.setServers.

Notes

shipped production is serving it deploy cfe12e4

opened this

A domain check now asks only nameservers at public addresses, and never more than four of them. Before, the addresses of a zone's NS records went straight to Resolver.setServers. Because the zone belongs to whoever adds the domain, an app admin could point the forge's resolver at loopback, private ranges or the metadata address, then read what happened from the said sentence.

What changed in src/apps/domains.ts

  • Filtering: nameserversFor removes duplicate addresses, keeps only those that isPublicAddress from src/apps/egress.ts accepts, and keeps at most MAX_NAMESERVERS (4). That drops loopback, RFC1918, link-local and 169.254, 100.64/10, multicast and ULA.
  • No public server left:
    • If the box's own resolver already found the record, its answer stands and the zone's servers are not asked.
    • Otherwise the step is skipped and the user sees: "…skipped the zone's own nameservers, which are only at private or local addresses; point the zone's NS records at public nameservers."
  • Timeout cancels the query: lookup now hands an AbortSignal to the lookup and aborts it when the 8 s timeout fires. withAuthority passes that signal on to resolveTxtAt. The default resolveTxtAt is a new askServers, which calls cancel() on its Resolver when the signal aborts. It also accepts an injected resolver so a test can check the cancel.
  • No raw error codes: any failure from the zone's servers other than "no record" becomes "failed at the zone's own nameservers". Errors from the box's own resolver still show their code, as before.

Tests

  • test/domain-nameservers.test.ts is new. A zone whose NS hosts resolve to 127.0.0.1 and 10.0.0.1 gets no TXT query at all. It also covers:
    • the other ranges being dropped while a public address is kept;
    • the four-server limit;
    • the box's resolver answer winning over private nameservers;
    • no raw error code in the sentence;
    • the timeout aborting its signal;
    • askServers cancelling its resolver.

    Against main's domains.ts the file fails: main has none of these exports.

  • One fixture changed in test/app-domains.test.ts: its nameserver was 192.0.2.53 (TEST-NET-1), which the new filter rightly refuses. It is now 198.51.100.53, which passes the filter. The test's assertions are unchanged.

Checks run: bun scripts/gate.ts --fix (no changes) and bun x tsc --noEmit pass. scripts/fast.ts named 2198 files, too many to run here, so I ran the six domain test files instead (domain-nameservers, app-domains, core-domains, domain-dns, mcp-app-domains, settings-app-domains): 65 pass. The sandbox cannot send real DNS (UDP gets ECONNREFUSED), so the real Resolver.cancel() is checked only through the injected fake. The keep_plan and estimate tools were not available in this run, so no plan was kept on the issue and no time was estimated.

To try it: bun test test/domain-nameservers.test.ts

🤖 Generated with Claude Code

Closes #15202

commented

A domain check now asks only nameservers at public addresses, and never more than four of them. Before, the addresses of a zone's NS records went straight to Resolver.setServers. Because the zone belongs to whoever adds the domain, an app admin could point the forge's resolver at loopback, private ranges or the metadata address, then read what happened from the said sentence.

What changed in src/apps/domains.ts

  • Filtering: nameserversFor removes duplicate addresses, keeps only those that isPublicAddress from src/apps/egress.ts accepts, and keeps at most MAX_NAMESERVERS (4). That drops loopback, RFC1918, link-local and 169.254, 100.64/10, multicast and ULA.
  • No public server left:
    • If the box's own resolver already found the record, its answer stands and the zone's servers are not asked.
    • Otherwise the step is skipped and the user sees: "…skipped the zone's own nameservers, which are only at private or local addresses; point the zone's NS records at public nameservers."
  • Timeout cancels the query: lookup now hands an AbortSignal to the lookup and aborts it when the 8 s timeout fires. withAuthority passes that signal on to resolveTxtAt. The default resolveTxtAt is a new askServers, which calls cancel() on its Resolver when the signal aborts. It also accepts an injected resolver so a test can check the cancel.
  • No raw error codes: any failure from the zone's servers other than "no record" becomes "failed at the zone's own nameservers". Errors from the box's own resolver still show their code, as before.

Tests

  • test/domain-nameservers.test.ts is new. A zone whose NS hosts resolve to 127.0.0.1 and 10.0.0.1 gets no TXT query at all. It also covers:
    • the other ranges being dropped while a public address is kept;
    • the four-server limit;
    • the box's resolver answer winning over private nameservers;
    • no raw error code in the sentence;
    • the timeout aborting its signal;
    • askServers cancelling its resolver.

    Against main's domains.ts the file fails: main has none of these exports.

  • One fixture changed in test/app-domains.test.ts: its nameserver was 192.0.2.53 (TEST-NET-1), which the new filter rightly refuses. It is now 198.51.100.53, which passes the filter. The test's assertions are unchanged.

Checks run: bun scripts/gate.ts --fix (no changes) and bun x tsc --noEmit pass. scripts/fast.ts named 2198 files, too many to run here, so I ran the six domain test files instead (domain-nameservers, app-domains, core-domains, domain-dns, mcp-app-domains, settings-app-domains): 65 pass. The sandbox cannot send real DNS (UDP gets ECONNREFUSED), so the real Resolver.cancel() is checked only through the injected fake. The keep_plan and estimate tools were not available in this run, so no plan was kept on the issue and no time was estimated.

To try it: bun test test/domain-nameservers.test.ts

🤖 Generated with Claude Code

commented

A domain check no longer queries a nameserver that resolves to a private, loopback, cloud-metadata or tailnet address (#15202). Before any lookup is sent, src/apps/domains.ts checks each nameserver's address. When a zone has no public nameserver left, the check fails with "point the zone's NS records at public nameservers" rather than querying the internal one. lookup now takes an abort signal and a timeout. When the timeout fires, the lookup still in flight is stopped rather than left querying in the background. Tests for this are in test/domain-nameservers.test.ts, and test/app-domains.test.ts is adjusted to match.

The last check failed on test/timers-named.test.ts. That test keeps a list of every server-side timer callback that is allowed outside during, matched by how the callback starts. The lookup timer callback had been rewritten to also abort, so it no longer matched its entry () => reject(. The callback is back to plain () => reject(...), and the abort moved to lookup's finally block. Aborting a lookup that has already finished does nothing, so behaviour is the same. The allowed list is unchanged.

The check's log also reported a failure in test/merge-queue-gate-result.test.ts ("a red gate's two failing tests are kept…"). That file doesn't touch domains, and it passed all four times I ran it on this branch. I treated it as flaky and left it alone; if it fails again on this push, it needs a closer look.

On this branch, test/timers-named.test.ts, test/domain-nameservers.test.ts and test/app-domains.test.ts pass, as do bun scripts/gate.ts --fix and bun x tsc --noEmit.

🤖 Generated with Claude Code

Approved

Approved. Private, loopback, metadata, CGNAT, multicast and ULA nameservers are filtered with isPublicAddress, capped at 4, and a timeout aborts the signal that cancels the Resolver. The authority path no longer leaks raw codes, and the tests cover each of these. This change has no page or terminal surface, so the preview adds nothing to judge. Two things to do next: (1) nameserversFor slices to the first 4 NS hosts before resolving them, so a zone whose first 4 NS hosts are private and whose 5th is public is treated as having no public server. Resolve all of them, filter, then cap. (2) The condition in withAuthority that swallows NO_PUBLIC_NAMESERVER when the box resolver already has an answer is over-long; wrap it.

Approved

Approved. The earlier head 0eb07b530e47 is not in this clone, so I judged the landed change. Every nameserver address is filtered through isPublicAddress, deduplicated and capped at 4 before Resolver.setServers. When no public server is left, the user gets a plain sentence. A record the box resolver already found still stands. Raw resolver codes from the zone servers no longer reach the sentence. A timed-out lookup now cancels its in-flight query. The new tests would fail on main, and the one changed fixture (192.0.2.53 to 198.51.100.53) is justified. No new dependency, and no page or terminal surface was added, so no feature doc is needed.

Next, non-blocking: (1) nameserversFor only calls resolve4, so a zone with IPv6-only nameservers falls through to ENOTFOUND. Consider resolve6 with the same filter. (2) Add a test that the ULA tailnet range fd7a:115c:a1e0::/48 is dropped, since tailnet is in the title.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs