fix(dns): finish the CNAME chain instead of handing clients a dead end - #99
Merged
Conversation
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>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://dns.moshcode.sh/dns-querywent live today and could not resolve a single Moshpit name, while resolving the rest of the internet fine.What it answered
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: trueand 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:The asymmetry is what made it confusing:
google.comworked, because forwarded queries go upstream and upstream chases the chain —gateway.ts:52already 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
moshpitResponseresolves the CNAME target and appends the leaf address records. Three deliberate choices:The CNAME still goes out, so
digstill 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-dnsexecuted byrun.sh, not a checkout, so merging does not ship this — the copy needs updating and the bun process restarting.