Skip to content

fix(dns): finish the CNAME chain instead of handing clients a dead end - #99

Merged
ralyodio merged 1 commit into
masterfrom
fix/cname-chase
Aug 3, 2026
Merged

fix(dns): finish the CNAME chain instead of handing clients a dead end#99
ralyodio merged 1 commit into
masterfrom
fix/cname-chase

Conversation

@ralyodio

@ralyodio ralyodio commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

https://dns.moshcode.sh/dns-query went live today and could not resolve a single Moshpit name, while resolving the rest of the internet fine.

What it answered

seo.rank AAAA → rcode=0, 1 answer
   type=CNAME  ttl=60  target=dev.profullstack.com

A CNAME, and nothing else. No A, no AAAA — for either query type.

Why that fails

It is a correct authoritative answer. An authoritative server may hand back a CNAME and stop, because the recursive resolver that asked will finish the chain.

This resolver is not in that position. It sets ra: true and is used directly by stub clients — browsers, curl, and every machine pointed at the DoH endpoint. A stub does not chase CNAMEs. It reads the answer section looking for an address, finds none, and reports the name unresolvable:

curl --doh-url https://dns.moshcode.sh/dns-query http://seo.rank/
curl: (6) Could not resolve host: seo.rank

The asymmetry is what made it confusing: google.com worked, because forwarded queries go upstream and upstream chases the chain — gateway.ts:52 already says as much. Only locally-answered Moshpit names took the broken path, so the endpoint failed at precisely the job it exists for.

The fix

moshpitResponse resolves the CNAME target and appends the leaf address records. Three deliberate choices:

  • Best-effort. An upstream failure still returns the CNAME. Failing closed would turn one hiccup into "this name does not exist" — strictly worse than the bug being fixed.
  • Leaves only. Relaying the upstream's own CNAMEs would rebuild the same dead end one link further along.
  • TTL clamped to the registry's. An owner can repoint a name at any moment, and an address cached past that is the one failure nobody can debug from outside.

The CNAME still goes out, so dig still shows where a name points. That visibility was the original intent and it is worth keeping — it just cannot be the whole answer.

Tests

3 new, in tests/dns-server.test.mjs: the hostname target resolving to an address, the upstream-failure path keeping the CNAME, and a literal-address target not triggering a spurious lookup.

Verified the first one fails on master (17 pass, 1 fail) and passes here — it reproduces the production failure rather than describing it.

145 pass, 0 fail across the full suite.

Deploying

The running resolver is a copy at ~/moshpit-dns executed by run.sh, not a checkout, so merging does not ship this — the copy needs updating and the bun process restarting.

A Moshpit name pointed at a hostname answered with a CNAME and nothing
else:

    seo.rank AAAA -> rcode=0, 1 answer
      type=CNAME ttl=60 target=dev.profullstack.com

That is a correct authoritative answer — and this resolver is not in the
position that makes it correct. It sets RA=1 and is used directly by stub
clients: browsers, curl, and every machine pointed at the DoH endpoint. A
stub does not chase CNAMEs. It reads the answer section for an address,
finds none, and reports failure:

    curl --doh-url https://dns.moshcode.sh/dns-query http://seo.rank/
    curl: (6) Could not resolve host: seo.rank

So the endpoint resolved google.com (forwarded upstream, which chases)
while failing every name it exists to serve.

moshpitResponse now resolves the CNAME target and appends the leaf
address records. Best-effort: an upstream failure still returns the
CNAME, because failing closed would turn one hiccup into "this name does
not exist". Answer TTLs are clamped to the registry's, since the owner
can repoint a name at any moment.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

vu1nz Security Review

0 finding(s) in PR #?

No security issues found.

@ralyodio
ralyodio merged commit 3677b99 into master Aug 3, 2026
2 checks passed
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