Preventing Subdomain Takeover From Dangling DNS
Subdomain takeover is one of the most common security problems found on otherwise well-run domains, and one of the easiest to prevent. It happens when a DNS record keeps pointing at something you no longer control. If someone else can claim that something, they can serve their own content on your subdomain, under your name and, often, with a valid certificate. This guide explains how takeovers happen, why they matter and the habits that stop them. It is written for defenders: the people who own the zone.
How a takeover happens
The classic case involves a CNAME record and a hosted service. Imagine the sequence:
- A team creates a site on a hosting platform. The platform gives it a name such as
campaign-site.platform.example. - Someone adds a CNAME so that
promo.example.compoints at that name, and adds the custom domain in the platform's dashboard. - Months later the campaign ends. The site is deleted on the platform, but nobody removes the CNAME.
- The record now points at a name that no longer belongs to anyone. On some platforms, any customer can create a new site with that same name, or claim the custom domain
promo.example.com. - Whoever does so now controls what
promo.example.comserves.
The record that points at an unclaimed resource is called a dangling record. The risk depends on the platform: some verify domain ownership before letting anyone attach a custom domain, and some do not.
Other kinds of dangling record
- A and AAAA records to released cloud addresses. If a subdomain points at a cloud IP address that you release back to the provider, that address may later be assigned to another customer, who then receives your subdomain's traffic.
- NS delegations to abandoned zones. If you delegate
dev.example.comto a DNS provider and later close that account, someone who can create the same zone at that provider may be able to answer for your subdomain. - MX records to retired mail services, which can let mail addressed to the subdomain be received by someone else in some setups.
Why it matters
A taken-over subdomain is not just an embarrassing page. Because it sits under your domain, it can be used to:
- Host convincing phishing pages that visitors and email filters may trust because of the domain name.
- Read or set cookies that are scoped to the parent domain, depending on how your cookies are configured, which can expose sessions on other subdomains.
- Obtain a certificate for the subdomain from an authority that validates by HTTP, because the attacker now controls what the name serves.
- Damage your reputation with search engines and users if it serves spam or malware.
Prevention habit 1: Remove DNS first, then the resource
The single most effective rule is order of operations. When you retire anything a subdomain points at, delete or change the DNS record before you delete the hosted site, release the IP address or close the account. If the record goes first, there is never a moment when it points at something unclaimed. The checklist for retiring a subdomain safely builds this into a routine, and the retirement notice template helps coordinate it with other teams.
Prevention habit 2: Keep a register
You cannot protect subdomains you do not know you have. A simple register, even a spreadsheet, listing each subdomain, what it points at, who owns it and when it was last reviewed makes forgotten records visible. Review it on a schedule, such as every quarter. See putting a subdomain register into practice.
Prevention habit 3: Audit the zone regularly
Export your zone and check every record that points outside your own infrastructure:
| Record type | What to check | Warning sign |
|---|---|---|
| CNAME | Does the target name still resolve, and is the resource on the platform still yours? | Target returns NXDOMAIN, or the platform shows a "no such site" page |
| A / AAAA | Is the address still assigned to your account? | Address not listed in your cloud console |
| NS | Does the delegated zone still exist in your account at that provider? | Provider's servers return SERVFAIL or REFUSED for the zone |
| MX | Is the mail service still active for that name? | Service cancelled or account closed |
The takeover risk self-check walks through one subdomain at a time, and the scenario on cleaning up forty forgotten subdomains shows an audit end to end.
Prevention habit 4: Prefer platforms that verify ownership
Many hosting and SaaS platforms now require you to prove you control a domain, for example by adding a TXT record, before they will serve a custom domain. When choosing a service, prefer those that do, and complete the verification step rather than skipping it. Avoid wildcard CNAMEs that send every possible subdomain to a third-party service, since that makes every unused name a potential target.
Prevention habit 5: Monitor continuously
For domains with many subdomains, add monitoring that alerts you when a record's target stops resolving, when a certificate is issued for one of your names unexpectedly, or when a record changes outside your normal process. Certificate Transparency logs, which publicly record issued certificates, are a useful source for the second check. Managing DNS as code, with changes reviewed before they are applied, adds a further layer. See certificate and DNS monitoring and DNS as code.
If you find a dangling record
- Remove or correct the DNS record straight away.
- Check whether the subdomain is currently serving content you did not publish.
- If it was taken over, review cookie scope, sessions and any certificates issued for the name, and follow your organisation's incident process.
- Add the cause to your retirement checklist so it does not recur.
The Learn hub lists every page in the security module, and launching a subdomain shows how to start each new name with an owner on record.