Skip to content

Full Toolkit for Next-Level Domain Analysis

Stop cross-server NS cycles and unrelated-zone denials 🔁🧭 (#125)

Felix Wotschofsky8018ed8b2883
diff --git a/lib/resolvers/authoritative-walk.test.ts b/lib/resolvers/authoritative-walk.test.ts
index 6970a33..1d5712d 100644
--- a/lib/resolvers/authoritative-walk.test.ts
+++ b/lib/resolvers/authoritative-walk.test.ts
@@ -184,6 +184,63 @@ describe('AuthoritativeResolver walk bounds', () => {
});
});
+ it('stops a circular glueless dependency reached through several roots', async () => {
+ const roots = ['192.0.2.1', '192.0.2.2', '192.0.2.3', '192.0.2.4'];
+ const udpTransport = vi.fn<AuthoritativeUdpTransport>(
+ async ({ domain, recordType, nameserver }) => {
+ await new Promise((resolve) => setTimeout(resolve, 5));
+ if (roots.includes(nameserver)) {
+ if (domain.endsWith('.c.test'))
+ return referral(
+ domain,
+ recordType,
+ 'c.test',
+ ['ns.c.test'],
+ ['8.8.4.1'],
+ );
+ // a.test and b.test name each other's servers, without glue.
+ if (domain.endsWith('.b.test'))
+ return referral(domain, recordType, 'b.test', [
+ 'ns1.a.test',
+ 'ns2.a.test',
+ ]);
+ return referral(domain, recordType, 'a.test', [
+ 'ns1.b.test',
+ 'ns2.b.test',
+ 'h.x3.x2.x1.c.test',
+ ]);
+ }
+ // The healthy NS sits four referrals below c.test.
+ const hop = Number(nameserver.split('.')[3]);
+ if (nameserver.startsWith('8.8.4.') && hop < 4) {
+ const zone = domain
+ .split('.')
+ .slice(-(2 + hop))
+ .join('.');
+ return referral(
+ domain,
+ recordType,
+ zone,
+ [`ns.${zone}`],
+ [`8.8.4.${hop + 1}`],
+ );
+ }
+ return reply(domain, recordType, [
+ address(domain, nameserver === '8.8.4.4' ? '9.9.9.9' : undefined),
+ ]);
+ },
+ );
+ const resolver = new AuthoritativeResolver({
+ udpTransport,
+ rootServers: async () => roots,
+ });
+ await expect(
+ resolver.resolveRecordType('www.a.test', 'A'),
+ ).resolves.toMatchObject({
+ records: [expect.objectContaining({ data: '203.0.113.10' })],
+ });
+ });
+
it('treats authoritative negative answers with SOA and NS as terminal', async () => {
const udpTransport = vi.fn<AuthoritativeUdpTransport>(
async ({ domain, recordType, nameserver }) => {
@@ -234,6 +291,53 @@ describe('AuthoritativeResolver walk bounds', () => {
).resolves.toMatchObject({ records: [{ data: '203.0.113.10' }] });
});
+ it('follows a referral beside a denial from an unrelated zone', async () => {
+ const udpTransport = vi.fn<AuthoritativeUdpTransport>(
+ async ({ domain, recordType, nameserver }) => {
+ if (nameserver === '192.0.2.1')
+ return referral(
+ domain,
+ recordType,
+ 'example.com',
+ ['p1.example.net'],
+ ['8.8.8.8'],
+ );
+ // The SOA's zone does not hold the queried name; the NS do.
+ if (nameserver === '8.8.8.8') {
+ const denial = nodata(
+ domain,
+ recordType,
+ 'other.example.com',
+ 'p1.example.net',
+ );
+ return {
+ ...denial,
+ authorities: [
+ denial.authorities![0],
+ {
+ name: 'sub.example.com',
+ type: 'NS',
+ ttl: 300,
+ data: 'c.example.net',
+ },
+ ],
+ additionals: [address('c.example.net', '1.1.1.1')],
+ } as DecodedPacket;
+ }
+ return reply(domain, recordType, [address(domain)]);
+ },
+ );
+ const resolver = new AuthoritativeResolver({
+ udpTransport,
+ rootServers: async () => ['192.0.2.1'],
+ });
+ await expect(
+ resolver.resolveRecordType('www.sub.example.com', 'A'),
+ ).resolves.toMatchObject({
+ records: [expect.objectContaining({ data: '203.0.113.10' })],
+ });
+ });
+
it('asks a sibling parent for DS when another refers it to the child apex', async () => {
const udpTransport = vi.fn<AuthoritativeUdpTransport>(
async ({ domain, recordType, nameserver }) => {
diff --git a/lib/resolvers/authoritative.ts b/lib/resolvers/authoritative.ts
index 384e3f3..f7c4319 100644
--- a/lib/resolvers/authoritative.ts
+++ b/lib/resolvers/authoritative.ts
@@ -610,11 +610,8 @@ export class AuthoritativeResolver extends DnsResolver {
// Branch-local ancestry stops a circular glueless dependency, whose
// replies are cached after a round trip or two and then recurse in
// microtasks, before it spends the step budget a slower sibling needs.
- // ponytail: keyed per server, so a cycle reachable through several
- // servers (four roots, or a cached delegation's addresses) still forks
- // through their orders and can starve a sibling only a few round trips
- // slower; tracking the glueless NS names each branch is resolving would
- // close that.
+ // This catches a request repeating itself; followReferralViaNsLookup
+ // catches an NS name cycling back through other servers.
if (ancestors.has(key)) {
failedNameservers.push(`${candidate}: DNS referral loop detected`);
continue;
@@ -852,9 +849,10 @@ export class AuthoritativeResolver extends DnsResolver {
}
// Authoritative NXDOMAIN/NODATA is final when its SOA shows it came from
- // the zone at this cut or below; an NXDOMAIN without SOA is final too.
- // Other denials skip this: a NODATA without SOA, a lame server's denial
- // from a zone outside the cut, and a DS denial from the child zone itself
+ // a zone at this cut or below that holds the queried name; an NXDOMAIN
+ // without SOA is final too. Other denials skip this: a NODATA without
+ // SOA, a lame server's denial from a zone outside the cut or one not
+ // holding the queried name, and a DS denial from the child zone itself
// (SOA owned by the queried name; DS lives in the parent), even from a
// parent server that also hosts the child. Below, NS they carry are
// followed, or rejected as a loop so that a sibling is tried; without NS
@@ -867,6 +865,7 @@ export class AuthoritativeResolver extends DnsResolver {
(soaZone === undefined
? packet.rcode === 'NXDOMAIN'
: (!cut || isInBailiwick(soaZone, cut)) &&
+ (!soaZone || isInBailiwick(wantName, soaZone)) &&
!(recordType === 'DS' && soaZone === wantName))
) {
return { answers: [], trace, rcode: packet.rcode, zone };
@@ -997,14 +996,20 @@ export class AuthoritativeResolver extends DnsResolver {
// as the winner are already collected as fallbacks.
const resolvedSets: string[][] = [];
const lookups = nsRedirects.slice(0, 4).map(async (ns) => {
+ // An NS name already being resolved further up this branch is a
+ // circular dependency whichever servers it goes through, so it is
+ // stopped once rather than once per server ordering.
+ const nsKey = `NS ${canonicalDnsName(ns.data)}`;
try {
+ if (ancestors.has(nsKey))
+ throw new Error(`circular NS dependency (${ns.data})`);
const resolved = await this.fetchRecordsRaw({
domain: ns.data,
recordType: 'A',
depth: depth + 1,
deadlineAt,
budget,
- ancestors,
+ ancestors: new Set([...ancestors, nsKey]),
});
subTrace.push(...resolved.trace);
// resolved.answers are all A records (filtered by type), so