Subdomain takeover: a DNS record that outlived its server

A subdomain takeover happens when someone other than you ends up serving content on one of your subdomains. The usual cause is a DNS record that still points at a hosting service after the site behind it was deleted. Because the broken part is a line in a DNS zone, a request filter in front of your website cannot repair it, and this page says plainly where a WAF helps and where the work belongs to whoever manages DNS.

Section Web attacks Updated Fix lives in DNS

Quick facts

What it is
An attacker gains control of a subdomain, typically one with a CNAME record but no host providing content (MDN)
Two conditions
A DNS record points to a missing or inactive resource, and the provider does not verify who owns the name (OWASP WSTG-CONF-10)
Record types
A, CNAME, MX, NS and TXT can all be affected (WSTG)
OWASP category
A02:2025 Security Misconfiguration is the nearest fit; OWASP lists the test under configuration and deployment management
First response
Remove the DNS entry for the subdomain (MDN)
Main fix
Keep an inventory of DNS records and delete the record before, or together with, the resource it points to

Definitions follow MDN, Subdomain takeovers and the OWASP Web Security Testing Guide. The CNAME rules come from RFC 1034, section 3.6.2. No CWE entry is cited here: the two that sometimes get suggested, CWE-1327 (binding to 0.0.0.0) and CWE-404 (improper resource release), describe other problems.

How a record ends up dangling

A CNAME record says that one name is an alias for another. The aliased name is the canonical one, and a resolver that finds the CNAME restarts its lookup there (RFC 1034). That is convenient: shop.example.com can point at a hosting service's name, and the service moves its servers without you touching your zone.

The trouble starts when the service stops answering for your name while your zone still names it. MDN describes two ways in.

During deprovisioning

You delete the site or the virtual host at the provider, but leave the DNS entry. The name now points at a service that has nothing assigned to it. An attacker opens their own account, claims the same name, and the provider starts serving their content for your subdomain.

During provisioning

The order is reversed: DNS is set up first and the virtual host later. In the gap, someone else can claim the host name. MDN notes this is possible unless the provider carefully verifies that whoever sets up a virtual host owns the subdomain name.

Both cases need the second condition from WSTG: the provider does not check ownership properly. Where a provider does verify, a dangling record is far less useful to an attacker. You cannot rely on that, because whether a provider verifies is a property of someone else's service.

FOUR STEPS, ONE FORGOTTEN LINE 1 DNS RECORD POINTS AT SERVICE 2 SITE DELETED, RECORD KEPT 3 ATTACKER CLAIMS THE NAME 4 VISITORS GET THEIR CONTENT // the request never touches your own servers
// the order of events in a dangling-record takeover

What an attacker gets

Visitors see your domain name in the address bar, so they have no reason to doubt the page. MDN lists what follows: the attacker can potentially read cookies set from the main domain, perform cross-site scripting, or circumvent content security policies, and so capture logins or send malicious content to your users.

Cookies shared with subdomains

A cookie set with a Domain attribute is available on that domain and its subdomains; one set without it stays on the host that set it (MDN, Using HTTP cookies). A session cookie scoped to the parent domain is therefore sent to the taken-over subdomain too. That is the route from a forgotten record to session hijacking. The __Host- prefix closes it: such cookies must be set without Domain, so they are only sent to the host that set them.

Trust you extended to subdomains

WSTG adds that cookie scoping, CORS trust, OAuth redirect validation and CSP allowlists can all extend trust to a claimed subdomain and expose the main application. If your CORS policy accepts any subdomain of your domain, a taken-over subdomain is a trusted origin. The same reasoning applies to a redirect check that accepts anything ending in your domain, which is how an open redirect gets its credibility.

Beyond CNAME records

CNAME is the textbook case, but WSTG says any record type can be affected, including A, MX, NS and TXT. An NS record that delegates a subdomain to a name server nobody controls any more is the worst variant: OWASP says a takeover there could give full control over the whole DNS zone.

Wildcards deserve a separate look. WSTG advises checking for wildcard CNAME records, because names covered by a wildcard often do not show up in passive subdomain lists, so nobody notices they exist.

The same guide covers a close relative, broken link hijacking: a retired external script, stylesheet, social profile or storage bucket that someone else can claim. Its remedy is to remove or update references to retired resources and to use Subresource Integrity for third-party scripts and stylesheets.

Where a WAF helps and where it does not

A WAF inspects HTTP requests that reach it. In a takeover, the browser resolves your subdomain, is sent to the other provider's servers, and receives the attacker's page from there. The request does not pass through a filter placed in front of your own site, and the response is not yours to filter. Nothing in the request looks like an attack, because nothing is being attacked: the site is serving what its new owner put on it.

That is the honest limit. Rules on your main domain do not repair a record in your zone, and a request filter does not discover which of your records point at services you have stopped using. What can still be said for a filter:

  • Names that do reach your edge. If a stale record sends traffic to your own proxy for a host name with no site behind it, the proxy can refuse unexpected Host values when the list of valid names is known. The mechanics are on the page about host header injection, and a reverse proxy is where that check sits.
  • What happens afterwards. A stolen cookie is replayed against your real site; a filter sees that request, but it is a valid-looking request from a valid session, which is why session theft is weak ground for pattern matching.
  • Evidence. The activity log records requests the filter flagged. It is not an inventory of your DNS.

The three modes apply to those edge-side checks only. In monitor mode a match is recorded and the request is still served, so start there and read the activity log before turning block on. In off nothing is inspected, and in block matching requests are refused. None of the three changes what your DNS zone says. Misconfiguration of this kind is the subject of security misconfiguration, where the same limit is explained for settings in general.

How to prevent a takeover

  1. Order the steps. MDN: start provisioning by claiming the virtual host and create the DNS records last; start deprovisioning by removing the DNS records first.
  2. Keep an inventory. List every domain and the hosting provider it points at, and update the list as things change, so nothing is left dangling (MDN).
  3. Check continuously. WSTG recommends continuous monitoring and periodic checks, and removing vulnerable records from the zone. A scheduled job that resolves every CNAME target and flags answers that fail is enough to start.
  4. Do everything close together. MDN advises defining standard processes for provisioning and deprovisioning and doing all steps as close together as possible.
  5. Ask vendors how they verify claims. MDN suggests asking how a provider confirms that someone claiming a virtual host is entitled to the name, and making the answer part of vendor selection.
  6. Limit what a subdomain can inherit. Prefer __Host- cookies, avoid wildcard subdomain entries in CSP allowlists and CORS rules, and check the headers your site sends with the security headers tool.

If it has already happened

MDN gives the first step: if possible, cut power by removing the DNS entry for the subdomain. If several layers sit between the name and the content, such as a CDN and virtual hosting, examine each one to find where the attacker made the claim.

Beyond that, treat it as a leak of anything scoped to the parent domain. Invalidate sessions that used cookies with a Domain attribute, review what the subdomain was allowed to do under your CORS and CSP settings, and check logs for requests to the subdomain's host name. Those steps are our suggestion, not a quotation from the sources above.

Questions

What is a subdomain takeover?

A subdomain takeover happens when an attacker gains control of a subdomain, typically because its DNS record still points at a hosting service that no longer serves content for the name. The attacker claims the name on that service and publishes their own content under your domain.

What is a dangling DNS record?

A dangling DNS record is an entry that points to an external resource that no longer exists or has been deprovisioned, such as a CNAME to a hosting service the owner has stopped using.

Can a WAF stop a subdomain takeover?

Almost never. The attacker's content is served by another provider, so the request does not pass through a filter placed in front of your own site. The fix is to remove or update the DNS record and keep an inventory of what each record points to.

How do you prevent a subdomain takeover?

Create DNS records last when provisioning and remove them first when deprovisioning, keep an inventory of domains and the services they point at, and check periodically that every record still resolves to a resource you control.

What should you do if a subdomain was taken over?

First remove the DNS entry for the subdomain to cut off the attacker, then look at every layer in front of the resource to see where the claim was made, and treat cookies scoped to the parent domain as exposed.