Skip to content

Dangling CNAME record: find it and remove it before a takeover

A dangling CNAME record points your subdomain at a deleted Azure app, S3 bucket or GitHub Pages site that someone else can register. Find every one in your zone, tell real ones from false alarms, and remove them in the right order.

Offensly Team··5 min read

dig old-app.example.com returns a CNAME to example-app-01.azurewebsites.net, and the header says status: NXDOMAIN. The app was deleted months ago. The record was not. That is a dangling CNAME record: your hostname still points at a name on someone else's platform that nobody holds any more, and on several platforms any customer can register that name again and serve pages on old-app.example.com.

The fix is almost always one deleted record. The work is finding all of them without deleting the ones that still serve traffic.

Export the zone, not your memory of it

The subdomains that dangle are the ones nobody remembers creating. Start from the full record list.

In Cloudflare, open the DNS Records page, select Import and Export, then Export (Cloudflare docs). In Route 53 the CLI is quicker than the console:

aws route53 list-resource-record-sets --hosted-zone-id Z0EXAMPLE00000 \
  --query "ResourceRecordSets[?Type=='CNAME'].[Name,ResourceRecords[0].Value]" \
  --output text > cnames.txt

Keep the lines whose target lives outside your own domain: *.azurewebsites.net, *.github.io, *.amazonaws.com, *.cloudapp.azure.com, SaaS help desks and landing page builders. Those are the targets someone else can register. On Azure, Microsoft's Get-DanglingDnsRecords script matches CNAMEs against the resources that still exist in your tenants.

Read the status line, not just the answer

Resolve every target and print the response code:

while read name target; do
  printf '%-24s %-56s %s\n' "$name" "$target" \
    "$(dig +noall +comments "$target" | grep -o 'status: [A-Z]*')"
done < cnames.txt
old-app.example.com.    example-app-01.azurewebsites.net.                        status: NXDOMAIN
docs.example.com.       example-org.github.io.                                   status: NOERROR
assets.example.com.     assets.example.com.s3-website-eu-west-1.amazonaws.com.   status: NOERROR

NXDOMAIN on the target is the clear case: the resource behind it is gone. When you query your own hostname instead, the code belongs to the last name in the CNAME chain (RFC 6604, section 3). So dig old-app.example.com also says NXDOMAIN while the answer section still shows your CNAME. People read that as "the subdomain does not exist" and close the ticket. Your record exists; its target does not.

NOERROR does not clear a record. GitHub Pages and S3 website endpoints resolve whether or not your site is still behind them, so those only show up over HTTP.

"NoSuchBucket" and "There isn't a GitHub Pages site here"

Request each NOERROR hostname that points at a shared platform:

curl -s http://assets.example.com/
curl -s https://docs.example.com/

Only run checks like these against sites you own or are allowed to test.

A deleted S3 website bucket renders this page:

404 Not Found
Code: NoSuchBucket
Message: The specified bucket does not exist
BucketName: assets.example.com

GitHub answers 404 There isn't a GitHub Pages site here. Both are platform pages, not your app. Tell the cases apart before you touch anything:

What you seeWhat it meansDangling
status: NXDOMAIN on the targetThe resource was deletedYes
Code: NoSuchBucketThe bucket is gone; another AWS account can create one with that nameYes
There isn't a GitHub Pages site here.Repository deleted, Pages turned off, or custom domain removedYes, unless the domain is verified in GitHub
Your app's own 404, a 403 or a login pageThe resource exists and answersNo, that is an app problem
SERVFAIL or a timeoutResolution fails, often DNSSECNo, check the DS record at the parent first

Fix a dangling CNAME record: delete it or take the name back

Delete by default. A CNAME to a deleted resource serves nothing anyone needs today, and if nobody can say what old-app was for, nobody will miss it. If you rarely edit the zone, the guide to adding DNS records shows where the record list sits in common panels.

Re-create the resource only when the hostname is still linked from emails, documentation or an app, and then do it in your own account under the exact same name. Provider specifics:

GitHub Pages. Verify the domain. For an organization: open the organization's Settings, then Pages under "Code, planning, and automation", then Add a domain, and publish the TXT record _github-pages-challenge-ORGANIZATION.example.com. After that, only your repositories can publish to the domain and its immediate subdomains (GitHub docs). GitHub also advises against wildcard records such as *.example.com, which stay claimable even on a verified domain.

Azure App Service. Keep the asuid.<subdomain> TXT record with your verification ID; while it exists, no other subscription can bind the hostname (Microsoft Learn). For Front Door, Traffic Manager, CDN endpoints and public IPs, use Azure DNS alias records: when the resource is deleted, the record set becomes empty instead of dangling.

S3. For a CNAME to a website endpoint, the bucket name equals the hostname (AWS docs). That makes it easy to recreate the bucket in your account if you need the name, and just as easy for anyone else.

Edits that make the cleanup worse

Do not delete _github-pages-challenge-* during a cleanup. It looks like an orphan TXT record, and it is the thing that keeps other accounts off your subdomains.

Do not treat every hashed target as urgent. A CNAME to example-app-0a1b2c3d4e5f6a7b.westeurope-01.azurewebsites.net uses Azure's secure unique hostname, which another tenant cannot recreate. Delete it if it is dead, but it can wait behind the NXDOMAIN list.

Do not count on TLS or CAA to protect a dangling name. Whoever controls the target can pass HTTP validation and get a valid certificate for your hostname. If they order it from a CA your CAA records allow, CAA does not stop it.

When you retire a service, delete the DNS record first and the resource second. Microsoft gives the same order for App Service, because the gap between the two is when the name is claimable.

Check the authoritative answer after the change

Public resolvers keep the old CNAME until its TTL runs out. Ask your own name servers directly:

dig +short NS example.com
dig @ns1.example.net old-app.example.com
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 5127
;; flags: qr aa rd; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

Look for aa and ANSWER: 0. Before the change this query had ANSWER: 1 with the CNAME line; now the zone itself no longer has the name. Re-run the loop over cnames.txt after every decommission, not once a year.

A claimed subdomain carries your name

Pages served from old-app.example.com look like yours to customers, partners and anyone who checks the address bar, and browsers send cookies scoped to .example.com to that server. The people hurt are your users; the cost of the fix is one deleted record per hostname and no downtime.

The Offensly advanced DNS check, free with an account on a verified domain, flags suspicious subdomain delegations, the NS version of this problem, together with DNSSEC and CAA.

Check your subdomain delegations with Offensly

Check your own domain in seconds

The free check reads your SPF, DKIM, DMARC and MX records and tells you exactly what to fix. No sign-up.