DNSVerdict

Dangling CNAME and subdomain takeover: find and fix

Published · Updated

A dangling CNAME is an alias in your DNS zone whose target no longer exists, for example blog.example.com pointing at a hosting address you deleted. If the hosting platform lets anyone register that target name, another customer can claim it and serve content on your subdomain. This is called subdomain takeover. Fix it by deleting the CNAME, and prevent it by removing the DNS record before you deprovision the resource. Trace a suspicious name with the CNAME chain tool.

A typical dangling record:

blog.example.com.  3600  IN  CNAME  old-blog-42.azurewebsites.net.

If the App Service named old-blog-42 was deleted, the alias still advertises blog.example.com as live. Microsoft’s guidance describes exactly this scenario: the record “should be removed from your DNS zone”, and if it is not, the dangling subdomain “can be taken over” by another subscription creating a resource with the same name.

How a CNAME works, and why it goes stale

RFC 1034 §3.6.2 defines the CNAME as an alias: the name is an alias for another, canonical name, and resolvers restart the lookup at the target. Your zone only stores the pointer. It has no idea whether the target still belongs to you, or exists at all. When you delete the resource at the provider, nothing updates your zone, because they are two separate systems run by two different parties.

Why it is a security problem

Once an attacker controls the target, they control what visitors to your subdomain see. Microsoft’s documentation lists the consequences:

Not every dangling CNAME is exploitable. It depends on whether the provider lets a different customer claim the same name without proving ownership of your domain. Providers that require a domain-verification record are harder to abuse. GitHub’s documentation, for example, says a Pages site that is disabled but still has a custom domain configured is “at risk of a domain takeover”, and verifying the domain “prevents other GitHub users from using your domain with their repositories”. Treat any dangling record as a defect either way.

How to find dangling records

  1. Export the zone. Most DNS hosts can list all records. Filter for CNAME records and note the targets.
  2. Resolve each target. Use the CNAME chain tool or the DNS lookup for type A. A target that returns NXDOMAIN (the name does not exist) is an obvious candidate.
  3. Check targets that still resolve. A target such as a *.github.io or *.azurewebsites.net name can resolve to the provider’s generic “not found” page. The page text differs by provider and changes over time, so open the URL and compare against the provider’s documentation. Wording is not a reliable test on its own.
  4. Use the provider’s tooling. Microsoft publishes a “Get-DanglingDnsRecords” PowerShell script for CNAMEs pointing at Azure resources, linked from its guide.
  5. Look at every record type that carries a hostname: CNAME, MX, NS, SRV. The NS lookup is useful for delegated subdomains, since a delegation to a name server you no longer control is its own takeover path.

Also review old DNS history: records created for a campaign or a demo are the usual ones to be forgotten.

How to fix it

  1. Delete the CNAME at your DNS host. Cached copies live until the TTL expires, so see TTL before migration for why the change is not instant.
  2. If the subdomain should still work, create the resource again under your own account with the name the CNAME expects, then keep it. Microsoft lists this as an alternative to deletion.
  3. Check application code, emails and documents that still reference the subdomain.
  4. If the name may have been claimed, investigate according to your incident process: look at what the subdomain served, and whether cookies or credentials could have been sent to it.
  5. Find out why the record survived, so the next decommission removes it.

How to prevent it

FAQ

Is a CNAME to a name that returns NXDOMAIN always exploitable? No. The attacker has to be able to register or claim that target name, and the provider decides whether that needs proof of domain ownership. A dangling record is still a defect: it signals neglect, can start working again under a different owner, and adds noise to audits.

Can I stop takeovers by only using A records? An A record to a released IP address has a similar problem, because the address may be assigned to someone else. The risk is different in kind (an attacker has to be allocated that exact address) but the cure is the same: remove the record when you release the resource.

How often should I audit? Whenever a project is decommissioned, plus a scheduled review at least quarterly if you create cloud resources often. The check takes minutes: export the zone, list every CNAME target, and run each through the CNAME chain tool to see which ones return NXDOMAIN or a provider’s unclaimed-resource page.

Sources

Tools used

CNAME LookupDNS LookupNS Lookup