Skip to content

DNS Lookup: nameserver picker (DoH presets, authoritative, custom via /api/dig) - #2

Closed
chrismuench wants to merge 2 commits into
mainfrom
dns-nameserver-picker
Closed

DNS Lookup: nameserver picker (DoH presets, authoritative, custom via /api/dig)#2
chrismuench wants to merge 2 commits into
mainfrom
dns-nameserver-picker

Conversation

@chrismuench

Copy link
Copy Markdown
Collaborator

What

The DNS Lookup subtab gets a Server dropdown so you can choose which nameserver to query:

  • Cloudflare / Google / DNS.SB — DoH from the browser, exactly as before (these are the only public resolvers with CORS-enabled JSON APIs).
  • Authoritative (zone NS) — finds the zone's nameserver (walks up from the query name via NS answers / SOA authority) and queries it directly — useful to see what the registry/registrar actually serves before propagation.
  • Custom nameserver… — any hostname or IP, i.e. dig @ns1.example.com.

How

Browsers can't speak DNS on port 53, so authoritative/custom queries go through a new /api/dig Pages Function that talks real DNS over TCP via cloudflare:sockets (same mechanism as the whois port-43 fallback in #1):

  • lib/dnswire.mjs — minimal, dependency-free DNS wire codec (single-question encode; response decode with name-compression support and rdata formatting for A, AAAA, NS, CNAME, SOA, PTR, MX, TXT, SRV, CAA).
  • Returns DoH-shaped JSON ({Status, Answer: [{name, type, TTL, data}]}) so the existing record-card rendering works unchanged; a note under the results shows which server answered.
  • Guards: strict name/type/nameserver validation before anything touches a socket, private/reserved nameservers rejected via isBlockedHost, 64 KB response cap, 8 s timeout, query-ID match check, 60 s edge cache in _middleware.js. No user input is logged.

Testing

  • node tests/smoke.mjs — 268 checks pass (new: wire-codec encode/decode incl. compression pointers, NXDOMAIN, truncation and pointer-loop safety).
  • node tests/e2e.mjs vs wrangler pages dev — all 46 checks pass (new: dig via 8.8.8.8, missing/bad params, private-NS rejection).
  • Manually exercised /api/dig: A/MX/TXT/SOA via 8.8.8.8 & 1.1.1.1, authoritative ns3.cloudflare.com by hostname, empty answers, and validation errors.

🤖 Generated with Claude Code

… /api/dig)

The Lookup subtab now has a Server dropdown:
- Cloudflare / Google / DNS.SB — DoH straight from the browser, as before
  (the only public resolvers with a CORS-enabled JSON API).
- Authoritative — walks up from the query name via NS/SOA to find the
  zone's nameserver, then queries it directly.
- Custom… — any nameserver hostname or IP, like `dig @ns1.example.com`.

Browsers can't speak DNS on port 53, so the last two go through a new
/api/dig Pages Function that does DNS over TCP via cloudflare:sockets,
using a minimal wire-format codec in lib/dnswire.mjs (encode one
question; decode answers incl. name compression, A/AAAA/NS/CNAME/SOA/
PTR/MX/TXT/SRV/CAA rdata). Strict input validation, private/reserved
nameservers blocked, 64KB cap, 8s timeout, 60s edge cache. Responses
match the DoH JSON shape so the frontend rendering is unchanged; a note
shows which server answered.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 9, 2026

Copy link
Copy Markdown

Deploying sysadminstuff with  Cloudflare Pages  Cloudflare Pages

Latest commit: a3dc5a8
Status: ✅  Deploy successful!
Preview URL: https://cebe5efa.sysadminstuff.pages.dev
Branch Preview URL: https://dns-nameserver-picker.sysadminstuff.pages.dev

View logs

…ract

A custom entry is always queried over classic DNS on TCP/53 (the dig
@server contract) — which every major DoH provider also serves. If
someone pastes a DoH URL, extract its hostname via hostFromInput; if
the host truly only speaks DoH, the error now says so.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chrismuench
chrismuench marked this pull request as ready for review July 9, 2026 02:55
@chrismuench chrismuench closed this Jul 9, 2026
@chrismuench
chrismuench deleted the dns-nameserver-picker branch July 9, 2026 03:02
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