Skip to content

Takeover check flags CNAME and NS targets that exist without addresses as dangling #362

Closed

Description

@TMHSDigital

Summary

A CNAME or NS target that is registered but has no A/AAAA records (NODATA) is resolved to the same outcome as NXDOMAIN, so it is reported as a dangling takeover candidate although the target domain exists and cannot be claimed. False takeover alarms cost triage time and can fail CI gates that fail on takeover candidates.

Where

  • internal/dns/takeover.go:179-191
  • internal/dns/takeover.go:232
  • internal/dns/takeover.go:258
  • internal/dns/resolver.go:55-58
  • internal/dns/resolver.go:516-522
  • internal/dns/takeover.go:222-237
  • internal/dns/resolver.go:513-525

Details

A CNAME or NS target that exists without addresses (NODATA) is flagged "dangling". The target is resolved with l.forTarget().Resolve(ctx, target) (A and AAAA). Resolve maps "no records of the requested types" to OutcomeNXDomain (516-522), and the Outcome doc says so: "OutcomeNXDomain ... or it exists but has no records of the requested types (NODATA). Go's resolver already reports NODATA as not-found for A/AAAA". marker then treats OutcomeNXDomain as dangling (case outcome == OutcomeNXDomain: return "dangling"), and Hint returns DanglingNS for an NS host with OutcomeNXDomain. The TakeoverHint doc promises "dangling" only "when the CNAME target does not resolve (NXDOMAIN)". This is the previous audit's unverified lead at takeover.go:183-186, confirmed.

Takeover check calls a CNAME target with no address records "dangling". The target is resolved with l.forTarget().Resolve (A and AAAA). Resolve folds "succeeded with no records" into OutcomeNXDomain (resolver.go:517-521), and Go's LookupIP already reports NODATA as not-found (comment at resolver.go:55-57). marker then returns dangling / dangling:<provider> for OutcomeNXDomain. A target that exists but has no A/AAAA (an empty non-terminal, a name holding only MX/TXT, a delegated apex answered without glue by the recursor) is therefore reported as dangling, the same as a target that does not exist. The NS check (line 232) has the same fold for name servers. This was an unverified lead of the previous audit (takeover.go:183-186), confirmed here.

Impact

A CNAME to a registered name that holds no A/AAAA (an apex with only MX/TXT, a name whose own CNAME chain ends in NODATA) or a delegation to a name server host that exists but has no address record is reported as a subdomain-takeover candidate, counted in Stats.Takeover and surfaced in reports/SARIF, although the target domain is registered and cannot be claimed. False takeover alarms in a security tool cost triage time and can fail a CI gate that fails on takeover candidates.

False "dangling" takeover hints, which feed Stats.Takeover, the result's takeover_candidate and the SARIF output. A dangling CNAME is claimable only when the target name is unregistered/unclaimed; a NODATA target already exists, so the hint sends the user after a non-issue. Low because the hint is documented as "verify by hand".

Steps to reproduce

dnstest server: alias.example.test CNAME target.example.test; target.example.test answers NOERROR with no A/AAAA (dnstest.Reply{} = NODATA, as in scenarios_test.go:22). Scan with -type A,CNAME against it: the result carries takeover_candidate: "dangling".

Lab zone: a CNAME b, b MX 10 mx1, scan with -type CNAME: a gets takeover_candidate: dangling, though b exists.

Suggested fix

Tell NXDOMAIN from NODATA for takeover targets: resolve the target with a raw query (as lookupCNAME already does in cname.go) and read the RCODE, calling it dangling only on RCODE 3 (NXDOMAIN); treat NOERROR/no-answer as "exists". Add a NODATA case to the takeover tests.

Keep NXDOMAIN and NODATA apart for takeover: have the target lookup classify by RCODE (a lookupType-level flag or a dedicated NXDOMAIN probe, e.g. the existing lookupCNAME path which sees RCodeNameError) and call only a true NXDOMAIN dangling.

Acceptance criteria

  • A CNAME target answering NOERROR with no A/AAAA is not reported as dangling
  • An NS host that exists without an address is not reported as dangling-ns
  • NXDOMAIN targets are still reported as dangling
  • Takeover tests gain a NODATA case

Getting started

  • Relevant files: internal/dns/takeover.go, internal/dns/resolver.go
  • How to run tests: go test ./... (tests must stay hermetic: use -simulate, a lab zone or internal/dnstest, never a live domain)
  • Related docs: docs/DEVELOPER_GUIDE.md, docs/ARCHITECTURE.md

Filed by repo-audit/full-audit at 0f3b0b6. Severity: medium. Effort: M. audit-key: bug|internal/dns/takeover.go|TakeoverCache.outcome

Activity

  1. added
    bug
    help wanted
    area: dns
    severity: medium
    on Nov 16, 2026
  2. TMHSDigital commented on Nov 16, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 6a7447d.

    When a CNAME target's or NS host's A/AAAA lookup comes back empty, the takeover check now sends one A query and reads the RCODE. NOERROR (NODATA) means the target exists and is not marked. Only NXDOMAIN gives dangling / dangling-ns. A probe that times out or fails marks nothing.

    Verified with a new TestTakeoverHintNODATA (dnstest server). It covers a NODATA CNAME target, a NODATA name server, NXDOMAIN targets that are still dangling, and a SERVFAIL probe. The test fails before the fix and passes after. TestTakeoverCache now expects the extra A query for a missing target. gofmt, go vet, golangci-lint v2.15.0 and go test ./... are all green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: dnsbughelp wantedseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions