Skip to main content
Security guideReviewed

Subdomain takeover: how a forgotten DNS record lets someone else answer under your name

A DNS record tells every browser that a name on your domain is served by a particular place.

When the place is given up and the record stays, whoever claims that place next can serve content under your name. This guide explains how that happens during ordinary work, what the person holding the name can do, and how to find and close dangling records, with a DNS lifecycle evidence worksheet, a verification procedure that creates nothing at any provider, and a local Node.js lab.

DNS lifecycle evidence worksheet and dangling record lab

An illustration on an invented zone. Part 1 is a DNS lifecycle evidence worksheet with one row per hostname, linking each name to its resource, provider account, business owner, verification record and decommissioning approval, with the source behind every column.

How to use it

Part 2 is a verification procedure for a suspected dangling record that only reads and creates nothing at any provider. Parts 3 to 6 are a Node.js lab with no installs that compares a zone file with an inventory as text, shows which launch and retire orders leave a dangling record, and runs a regression test that fails when one is added. Part 7 gives the steps to run the checks on your own zone.

subdomain-takeover.txt

Introduction5 lines

ILLUSTRATION ONLY. Harbourline Supplies, harbourline.example, every provider, account, address, person and date below are invented for this page. harbourline.example and the provider names sit under .example, one of the top level names RFC 2606 reserves, and RFC 2606 recommends .example for documentation and examples. The two addresses come from ranges IANA's special-purpose address registry lists as Documentation. What this asset is, and what it is not. Part 1 is a DNS lifecycle evidence worksheet, one row per hostname, with the reason for each column and its source. Part 2 is a verification procedure for a suspected dangling record that only reads: it ends before anything is created at any provider. Parts 3 to 6 are a lab. A checker reads an invented zone file, an invented inventory of provider resources and the fixture's own provider table, all as text, and reports for every hostname record its target, whether the inventory holds a matching live resource, and a classification. The checker compares text files with each other. It performs no DNS query and contacts no provider, and the provider table is a fixture that stands in for what each invented provider holds. Part 7 lists the steps to run the same checks on your own zone, with your system's resolver tools. Written and run on: Node.js 26.0.0, the only version it was run on. The lab imports only node:fs, node:test and node:assert and installs no packages. Every output below comes from that run; the test timings will differ on your machine.

What a DNS record promises, and what a subdomain takeover is

A name on your domain, such as shop or help in front of your business name, works because a DNS record says where it is served from.

Read in plain terms, the record is a promise to every browser and mail server that asks: this name is served by that place. For an alias, the place is another name. RFC 1034, Domain Names: Concepts and Facilities, says a CNAME record identifies its owner name as an alias and specifies the corresponding canonical name, and that in most cases a resolver simply restarts the query at the new name when it encounters one.

So a record making shop an alias for a name at your store provider sends every visitor to whatever answers for that provider name.

A subdomain takeover is what happens when the place is given up and the promise is left standing. MDN describes it as an attacker gaining control over a subdomain of a target domain, and says this typically happens when the subdomain has a CNAME in DNS but no host is providing content for it, either because a virtual host has not been published yet or because one has been removed.

Microsoft's guidance, written for Azure, calls a DNS record that points to a deprovisioned Azure resource a dangling DNS entry, and says CNAME records are especially vulnerable.

OWASP's Web Security Testing Guide covers it as WSTG-CONF-10, Test for Subdomain Takeover. It says the attack relies on two things: the subdomain's DNS record is configured to point to a non-existing or non-active resource, external service or endpoint, and the provider hosting it does not handle subdomain ownership verification properly.

It also says the weakness is not limited to aliases: it could be exploited for a wide variety of DNS record types, including A, CNAME, MX, NS and TXT.

How someone else ends up answering for your name

MDN explains the mechanism with a hosted blog.

You point blog.example.com at a blogging platform and set up a virtual host there for that name. Later you remove the virtual host but leave the DNS entry that points to the provider. An attacker can then create their own virtual host with that provider, claim your subdomain and host their own content under it.

Microsoft walks through the same sequence on Azure. A resource is created with a provider name such as app-contogreat-dev-001.azurewebsites.net, and a CNAME record sends greatapp.contoso.com to it. The resource is deleted and the CNAME is not. Using commonly available methods and tools, a threat actor discovers the dangling name and provisions an Azure resource with the same provider name, and traffic sent to greatapp.contoso.com is then routed to a resource where they control the content.

The gap can open at the start of a name's life as well as the end. MDN's other case is provisioning. If you set up DNS before the virtual host exists, and the hosting provider is not very careful to verify that whoever sets up the virtual host owns the name, an attacker who is quicker than you could create a virtual host for your name with the same provider and host content on it as soon as your DNS record is in place.

WSTG-CONF-10's summary gives two examples. In one, a business moves its code repository away from GitHub but leaves coderepo.victim.com in DNS, and someone else claims the name through GitHub Pages with their own account. In the other, www is a CNAME to a second domain the business owned; that domain expires, and whoever registers it has full control over www while the record is present.

For delegations, WSTG says an NS takeover, although less likely, has the highest impact, because a successful attack could result in full control over the whole DNS zone and the victim's domain.

What the person holding your name can do with it

Once the name answers from their resource, they choose what your visitors see.

Microsoft says dangling entries make it possible for threat actors to take control of the associated DNS name to host a malicious website or service, and that malicious pages and services on an organisation's subdomain might result in loss of control over the content of the subdomain, cookie harvesting from unsuspecting visitors, phishing campaigns, and further risks in which malicious sites might escalate into attacks such as XSS, CSRF and CORS bypass.

It adds that the phishing risk extends to MX records, which could let threat actors receive email sent to legitimate subdomains. WSTG-CONF-10 lists serving malicious content, phishing, and stealing user session cookies and credentials among the attacks possible.

For a customer who follows a link, the address bar shows your business's own name, so checking the address before signing in does not help them. A padlock does not settle it either. Microsoft calls it a common misconception that SSL certificates protect your site and your users' cookies from a takeover, because a threat actor can use the hijacked subdomain to apply for and receive a valid SSL certificate, which it says grants access to secure cookies and can make the malicious site look more legitimate.

Sign-in cookies that every subdomain receives

The cookie risk depends on how your site sets its cookies. MDN's Set-Cookie reference says setting the Domain attribute makes a cookie available to that domain and all its subdomains, while leaving it out returns the cookie only to the host that sent it.

Microsoft says it is common for web apps to expose session cookies to subdomains and that any subdomain can access them, and that a threat actor can use a takeover to build an authentic-looking page, trick visitors into opening it and harvest their cookies.

MDN's page on subdomain takeover says an attacker holding the subdomain can potentially read cookies set from the main domain.

The risk runs the other way too. The IETF cookie draft, draft-ietf-httpbis-rfc6265bis-22, says in section 8.6 that cookies do not provide integrity guarantees for sibling domains: one subdomain can set a cookie with the parent domain as its Domain, possibly overwriting a cookie another subdomain set, and in the worst case the other subdomain will be unable to tell it from a cookie it set itself.

ASVS 5.0 requirement 3.3.3, at Level 2, asks for the __Host- prefix on cookie names unless a cookie is explicitly designed to be shared with other hosts. The cookie security guide explains what that prefix locks down.

Trust rules written as "any of our subdomains"

Rules that trust every subdomain take on the risk of the weakest one. OWASP's CSRF Prevention Cheat Sheet notes that SameSite is scoped to the registrable domain rather than the origin, so a cookie set on app.example.com is still sent with requests from anything.example.com, which it says amplifies the impact of subdomain takeovers.

Its Fetch Metadata policy treats same-site requests as allowed only if your threat model trusts sibling subdomains. MDN says an attacker who takes over a subdomain can potentially circumvent content security policies, and Microsoft names CORS bypass among the further risks.

The same reasoning applies to any allow-list your own code writes as a pattern for your domain: a CORS origin check, a list of addresses a sign-in may return to, a list of hosts allowed to frame your pages.

A pattern trusts whichever host answers under it today, including one that someone else has claimed. The CORS misconfiguration guide explains why an origin check should compare the whole origin against a list.

Why dangling records come out of ordinary work

None of this needs a mistake anyone would notice at the time.

A dangling record is what is left when two jobs that belong together are done by different people, in different places, at different times. The DNS record lives with whoever manages your domain: an IT contact, an agency, a developer who has since moved on.

The service lives in an account at a provider, run by the team that uses it. When the service ends, the person closing the account may not have the DNS login, and the record goes on answering until someone notices it.

  • A campaign site is retired. Last winter's sale page is deleted from the campaign tool, and winter-sale still points at it.
  • A trial ends. Someone tried a help desk or booking tool on a subdomain, the trial lapsed and the account closed, and the DNS record was never on anyone's list for the trial.
  • A supplier changes. The store or blog moves to a new platform under a new name, and the old CNAME stays in case something still links to it.
  • An agency or developer leaves. A staging host, a cloud server or a delegated subzone sat in their accounts, and those accounts closed with the contract.
  • A domain lapses. A CNAME points at a second domain the business once held; WSTG-CONF-10's example shows that whoever registers the expired domain controls the alias.

Why the gap goes unnoticed

MDN frames prevention as a matter of order of operations in lifecycle management for virtual hosts and DNS. It notes that, depending on the size of the organisation, this may require communication and coordination across multiple departments, which it says can only increase the likelihood of a vulnerable misconfiguration. Microsoft describes subdomain takeovers as a common, high-severity threat for organisations that regularly create and delete many resources.

The ASVS scope points away from DNS. ASVS 5.0 says it generally excludes requirements where configuration is outside the application's responsibility, and gives DNS issues, typically managed by a separate team or function, as its example. So a review measured against ASVS alone may never reach your DNS records, and the inventory below is how they get an owner.

A DNS asset inventory that ties every hostname to an owner and a resource

Prevention starts with a list.

MDN recommends an inventory of all of your organisation's domains and their hosting providers, updated as things change, so that nothing is left dangling. Microsoft, writing for Azure, recommends a service catalogue of your endpoints and the application owners, exported regularly for the resources you can access. If you have access to all subscriptions in your tenant, it says to include all of them in the inventory; if you do not, to document which subscriptions the inventory covers.

WSTG-CONF-10's test objectives are to enumerate all possible domains, previous and current, and to identify forgotten or misconfigured ones.

The worksheet in the asset on this page turns that into one row per hostname, and it does not stop at the record. A record only says where a name points. The row also says what is there, which account holds it and who holds the account, who in the business answers for the name and why it exists, whether the provider binds the name to your account, when it was last checked and, when the name is retired, who approved it and what showed it was gone.

Three statuses cover the resource: it exists and is ours, it exists and is not in any account we hold, or it does not exist.

They answer the two questions Microsoft's regular review asks of each record: does the resource exist, and do you own it.

Start the list from the zone, not from memory. WSTG-CONF-10 notes that a tester who has the DNS zone file available does not need DNS enumeration. Your zone file is the list of names your DNS host publishes for that zone, so export each zone you hold, including old domains that only redirect, and add a row for every record that points somewhere.

Then work outwards from each target to the account that holds it. A name whose account nobody can find goes to the verification procedure.

The CNAME lifecycle: create the resource first, remove the record first

Subdomain takeover prevention starts with the order of the steps.

MDN's defences say to start provisioning by claiming the virtual host and create DNS records last, and to start deprovisioning by removing DNS records first. They also say to define standard processes for both and to do all the steps as closely together as possible. GitHub gives the launch half for its Pages hosting: add your custom domain to your GitHub Pages site before configuring it with your DNS provider, because configuring the DNS provider first could result in someone else being able to host a site on one of your subdomains.

The lab plays out both orders for a new events page. Launching record first leaves one step at which the name points at a provider name that nothing answers to; launching resource first leaves none. Retiring resource first leaves one such step; retiring record first leaves none. In the lab a step takes no time. In a business, the gap lasts until someone does the second step.

  • Get the business owner's approval to retire the name, and write down who gave it (this page's advice).
  • Remove the DNS record first. Microsoft suggests putting a "Remove DNS entry" step on the list of required checks when decommissioning a service.
  • Wait out the record's TTL. RFC 1034 describes the TTL as how long a record can be cached before it should be discarded. Until it has passed, a resolver that cached the old alias may still send visitors to the provider name, so delete the resource after that (this page's advice).
  • Delete the resource at the provider, and close the account if nothing else uses it.
  • Remove any verification record for the name last, and only if nothing else relies on it. GitHub says to keep its verification TXT record in your DNS configuration to make sure your custom domain remains verified; the order is this page's advice.
  • Record the evidence after the change: the command, the date, an NXDOMAIN or NOERROR status, and an answer section that holds no CNAME and no address for the name (this page's advice). Read both, because RFC 1034 says that when recursive service is requested and available, a name error may include CNAME records showing that the original query name was an alias for a name which does not exist.

Making the order stick

For Azure, Microsoft adds habits that keep the order from depending on memory: educate application developers to reroute addresses whenever they delete resources, and add delete locks to resources that have a custom DNS entry, as an indicator that the mapping must be removed before the resource is deprovisioned.

It says measures like this work only when combined with internal education. For a smaller business, the equivalent is a line in whatever checklist closes a supplier account or ends a campaign: who removes the DNS record, and when (this page's advice).

What a provider's domain verification does and does not prevent

Some providers bind a custom name to one account through a verification record you publish in your own DNS.

What that prevents is whatever each provider's documentation says it prevents, so read it for every provider you use. Two examples, from each provider's own documentation as read on 14 November 2026:

  • Azure App Service. Microsoft's custom domain guide asks for a TXT record named asuid for the root domain, or asuid followed by the subdomain, holding a domain verification ID. It says the record is not absolutely required but highly recommended for security, because it helps avoid subdomain takeovers from other App Service apps, and that custom domains set up without it should be protected by adding it. Microsoft's dangling DNS guidance says that when such a TXT record exists, no other Azure subscription can validate the custom domain or take it over. It also gives the limit: the record does not prevent someone from creating an App Service instance with the same name that is in your CNAME entry, but without the ability to prove ownership of the domain name, it says, they cannot receive traffic or control the content.
  • GitHub Pages. GitHub's documentation says that when you verify a custom domain for your personal account, only repositories that account owns may publish a Pages site to the verified domain or the domain's immediate subdomains, and the same holds for an organisation account. It says verifying stops other GitHub users from taking over your custom domain, and that takeovers can happen when you delete your repository, when your billing plan is downgraded, or after any other change which unlinks the custom domain or disables GitHub Pages while the domain remains configured for GitHub Pages and is not verified. Its limit is wildcard records: it strongly recommends against records such as *.example.com, which it says put you at an immediate risk of domain takeovers even if you verify the domain, because verifying example.com stops someone using a.example.com but not b.a.example.com.

What follows from those two documents

Three things, as this page reads them. Verification is a feature of each provider, with its own rules, so the worksheet records it per provider as something you checked rather than assumed. It covers what the provider's documentation says it covers, inside that provider.

And it does not repair the record. A verified name pointing at a resource you deleted still points at nothing you control, and WSTG-CONF-10's remediation is to remove the vulnerable DNS resource records from the zone.

MDN suggests asking each hosting vendor how they verify that someone claiming a virtual host has a legitimate claim to the domain name, and making that part of how you choose vendors.

A subdomain takeover check that stays on your own property

Checking for dangling records needs nothing more than reading.

The procedure in the asset reads the record, resolves the chain, classifies the target, checks your own accounts at the provider, reads the response the hostname gives, decides, and records the evidence. Every step is a lookup, or a sign-in to an account your organisation already holds.

Run it only on zones your organisation holds or that you are authorised in writing to check. It starts from your own zone file, so it needs no way of discovering anyone else's names, and it describes none.

It also stops before anything is created. WSTG-CONF-10's A and CNAME record walkthrough ends with the tester claiming the domain through GitHub Pages. Do not take that step, even on your own domain. Registering the resource to prove a takeover takes control of something your organisation has not approved, through an account it may not even hold, and it can break the provider's terms.

On someone else's domain it is unauthorised. The evidence the procedure collects is enough to decide: the record, the resolver's answer, the accounts you searched and the response the name gave.

The resolver's answer tells you which branch you are on. When recursive service is requested and available, RFC 1034 says the response is the answer to the query, possibly prefaced by CNAME records for the aliases met on the way, or a name error showing that the name does not exist, which may include CNAME records showing that the original name was an alias for a name that does not exist, or a temporary error.

RFC 9499, DNS Terminology, gives NXDOMAIN as the shorthand for that name error, SERVFAIL for a name server that was unable to process the query due to a problem with the name server, and REFUSED for one that refuses to perform the operation for policy reasons. WSTG-CONF-10 lists NXDOMAIN, SERVFAIL, REFUSED and no servers could be reached as responses that warrant further investigation.

Running the DNS lifecycle lab

The lab is an illustration for an invented business, Harbourline Supplies.

It is four text files and four scripts: a zone file for harbourline.example, an inventory of the provider resources the business knows it holds, the fixture's own provider table standing in for what each invented provider holds today, and a cleaned copy of the zone.

The domain and every provider name sit under .example, one of the top level names RFC 2606 reserves, which it recommends for documentation and examples, and the two addresses come from ranges IANA's special-purpose address registry lists as Documentation.

Be exact about what it does. The checker compares the zone file with the inventory and the provider table, as text. It sends no DNS query and contacts no provider; the lab imports only node:fs, node:test and node:assert and installs no packages.

A result that reads "dangling: target name has no record in the fixture's own provider table" means just that: the invented table does not list the name. On your own zone, the resolver steps in Part 7 of the asset answer the same question for real.

It was written and run on Node.js 26.0.0, and every output in the asset was copied from that run by a script.

  • node check-zone.mjs zone.txt prints one block per hostname record. Of the nine records, four are matched, three are dangling because no live resource in the inventory matches the target (blog, old-api and labs), one is dangling because the provider table has no record of the target name (winter-sale), and one is unowned (help).
  • node lifecycle-orders.mjs plays the two launch orders and the two retire orders for events.harbourline.example. Record first on launch, and resource first on retirement, each leave one step with a dangling record. The other two orders leave none.
  • node zone-check.test.mjs zone-proposed.txt runs the regression test with Node's test runner, the node:test module. With one dangling record added to a proposed copy of the cleaned zone, it fails and names the record; with the line removed, it passes. The Node.js documentation says the process exit code is set to 1 when any test fails. A pipeline step that treats a non-zero exit code as a failure then fails (this page's reading).

If one of your names is already serving someone else's content

Treat it as an incident.

MDN's first step, if possible, is to cut power by removing the DNS entry for the subdomain, and it notes that with several layers, such as a CDN in addition to virtual hosting, you may need to examine each layer to see where the attacker asserted their claim.

Before you delete the record, copy its value from your DNS host. It takes seconds, and it is evidence you may not be able to get back once the record is gone (this page's advice).

Microsoft's guidance, written for Azure, is to investigate whether any compromise occurred and act according to your organisation's incident response procedures, and to find out why the record was not removed when the resource was deprovisioned. It warns that if your application sends secrets such as OAuth credentials, or privacy-sensitive information, to a dangling subdomain, that data might be exposed to third parties.

If you need to see what the name is serving, look from a private browser window that is signed in to nothing on your domain, and enter nothing into the page (this page's advice). Clever Ops does not provide incident response. Containment and cleanup come first, from an incident response specialist, and a check of the domain can follow once that work is finished.

Neighbouring guides, and where a Clever Ops check fits

A dangling record is one kind of configuration left behind.

The OWASP Top 10:2025 defines security misconfiguration as a system, application or cloud service set up incorrectly from a security perspective, and the security misconfiguration guide covers that wider category. What your responses reveal is the subject of the sensitive data exposure guide. Keys that leak into code, repository history, browser bundles or logs belong to the secrets exposure guide.

The Clever Ops website security check looks at this from outside, without signing in, under WSTG-CONF-10. It lists hostnames from public DNS and certificate records and checks where each one points, and a good result is that every hostname has an owner who can say what it is for and no record points at a third-party service you have stopped using.

A subdomain that someone else could take over is reported rather than claimed. The methodology page explains how scope and authorisation are settled before any testing: authorisation is a letter signed by a person with authority over each target, and services run by other businesses on your subdomains stay out of scope unless their owner agrees.

If Clever Ops built or hosts your site, the work is a security review rather than an independent test, and the report says who built it and who hosts it.

Frequently asked questions

Someone else gaining control of a name on your domain, such as shop or help. MDN says it typically happens when the subdomain has a CNAME in DNS but no host is providing content for it, and that an attacker can then take the subdomain over by providing their own virtual host and hosting their own content for it. WSTG-CONF-10 says it also depends on the provider not handling subdomain ownership verification properly.

A record that still points at something that no longer exists or is no longer yours: a deleted cloud resource, a closed store, a released address or an expired domain. Microsoft uses the term for a DNS record that points to a deprovisioned Azure resource. WSTG-CONF-10's remediation is to remove the vulnerable records from the zone.

Start from your zone file, not from a search. For each record that points somewhere, resolve it, classify the target, look for the resource in your own provider accounts, and read what the name serves. The procedure in the asset gives each step and the decision it leads to, and it never asks you to create anything at a provider. Check only zones your organisation holds or that you are authorised in writing to check.

No. Microsoft calls it a common misconception that SSL certificates protect your site and your users' cookies from a takeover, because a threat actor can use the hijacked subdomain to apply for and receive a valid certificate, which it says grants access to secure cookies.

It limits who can attach your name inside that provider, as far as the provider's documentation says. Microsoft says that with an App Service verification record in place, no other Azure subscription can validate the custom domain. GitHub says a verified domain covers the domain and its immediate subdomains, and warns that wildcard records still leave deeper names open. Verification does not remove a record that points at a resource you deleted, so remove that record too.

No. Registering it takes control of something your organisation has not approved, possibly through an account it does not hold, and it can break the provider's terms. On someone else's domain it is unauthorised. The record, the resolver's answer, the accounts you searched and the response the name gave are enough evidence to remove or repoint the record.

It can when those cookies are shared with subdomains. MDN says setting the Domain attribute makes a cookie available to that domain and all its subdomains, and MDN's subdomain takeover page says an attacker holding the subdomain can potentially read cookies set from the main domain. A cookie set without a Domain attribute is returned only to the host that sent it.

Scope the right test for your application

Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.