When a cloud resource is deleted but the DNS record that pointed to it is not, anyone who can claim the same resource name inherits your subdomain, your users' trust and often your cookies. This is subdomain takeover, and it follows directly from how cloud services are used: teams create and delete web apps, storage buckets, CDN endpoints and public IPs constantly, while DNS is managed somewhere else by someone else. Microsoft rates it a common, high-severity threat for organisations that regularly create and delete resources. This guide explains how dangling DNS arises, where it shows up across providers, what an attacker can do with a captured subdomain, and how to detect, prevent and clean it up. It is written for cloud, DNS and vulnerability management teams, and goes deeper than the Attack Surface Management Guide on this one issue.
Key takeaways
- The root cause is lifecycle drift. A DNS record outlives the resource it points to, and the provider allows someone else to claim that resource name.
- Delete DNS first, resource second. Reversing the decommissioning order closes the takeover window; add it to every deprovisioning runbook and pipeline.
- Use provider ownership verification. Azure App Service
asuidTXT records, GitHub Pages domain verification and CloudFront's certificate requirement stop other tenants claiming your names. - A captured subdomain is a trusted origin. It can read cookies scoped to the parent domain, obtain valid TLS certificates and receive OAuth tokens or webhooks still pointed at it.
- Inventory beats scanning. Continuous comparison of DNS zones against the cloud resources you actually own finds dangling records before attackers do.
How the attack works
Microsoft's documentation describes the typical sequence with Azure App Service, and the pattern is the same elsewhere:
- Creation: a team creates
app-contogreat-dev-001.azurewebsites.netand adds a CNAMEgreatapp.contoso.compointing to it. - Deprovisioning: the app is deleted but the CNAME stays. The record now points at a name nobody owns: it is dangling.
- Takeover: someone finds the dangling record, creates a resource with the same provider name in their own subscription, and traffic for
greatapp.contoso.comnow reaches content they control.
The condition OWASP's Web Security Testing Guide (WSTG-CONF-10) describes is the same: a DNS record points to a resource that no longer exists, and the hosting provider does not verify ownership. OWASP lists A, CNAME, MX, NS and TXT records as relevant, with CNAME the most common case and NS takeover less likely but highest impact, because it can hand over control of the whole delegated zone. A related variant is a CNAME pointing to another organisation's domain that has lapsed: whoever re-registers that domain controls the target.
In ATT&CK, taking over a victim's domain or subdomain is described under T1584.001 Compromise Infrastructure: Domains, a resource development technique: the attacker gains trusted infrastructure for later phishing or delivery.
Where it shows up
| Record type | Dangling when | Typical targets | Provider control that helps |
|---|---|---|---|
| CNAME | The target cloud resource is deleted but its provider name can be recreated | App Service (azurewebsites.net), Blob Storage (blob.core.windows.net), Azure CDN (azureedge.net), Front Door (azurefd.net), Traffic Manager (trafficmanager.net), API Management (azure-api.net), Container Instances, S3 buckets, GitHub Pages | Domain verification TXT records; alias records; certificate requirements |
| A / AAAA | A public IP is released and can be reallocated to another customer | Cloud public IPs, load balancer addresses | Alias records tied to the IP resource; reserving IPs for long-lived services |
| CNAME to a third-party domain | The third party's domain expires | Old SaaS, agencies, campaign sites, vendor-hosted portals | Inventory of external targets; monitoring their registration status |
| NS | A delegated subzone points to name servers or a hosted zone that no longer exists or can be claimed | Delegations to cloud DNS zones, old DNS providers | Remove delegations when zones are deleted; audit NS records |
| MX | The mail service for a subdomain is decommissioned | Legacy mail or marketing platforms | Remove MX records; Microsoft notes dangling MX could let attackers receive mail for the subdomain |
| Wildcard records | A wildcard points at a service where any name can be claimed | *.example.com to a hosting platform | Avoid wildcards to shared platforms; GitHub strongly advises against wildcard records |
For Azure classic cloud services, Azure reserves a deleted service's cloudapp.net name so that only subscriptions in the same Microsoft Entra tenant can reuse it for a period; after the reservation expires anyone can claim it, so do not rely on it. GitHub notes that takeovers of Pages custom domains can follow a deleted repository, a downgraded billing plan or disabling Pages while the domain remains configured and unverified.
Impact
- Content and brand: attacker-controlled pages under your domain, used for phishing, malware delivery or defacement that users and filters trust.
- Cookies and sessions: cookies scoped to the parent domain (for example
Domain=contoso.com) are sent to every subdomain, so a captured subdomain can read session cookies. Microsoft also notes that the attacker can obtain a valid TLS certificate for the hijacked name, so the padlock offers users no warning. - Web security bypass: Microsoft lists cross-site scripting, CSRF and CORS bypass where applications trust their own subdomains in allowlists or CORS policies.
- Credentials and tokens sent to the name: OAuth redirect URIs, webhook endpoints, SSO assertion consumer URLs and API callbacks that still point at the subdomain will deliver secrets to whoever controls it. Microsoft warns that secrets such as OAuth credentials sent to a dangling subdomain may be exposed.
- Email: dangling MX records may let an attacker receive mail for the subdomain, useful for password resets or domain validation.
Where identity fits: stale names are part of the trust configuration of applications and machine identities. App registrations, OAuth clients, SAML service providers and webhook subscriptions all embed URLs, and nobody reviews them when a site is retired. Include redirect URIs and callback URLs in NHI and application reviews. See the OAuth 2.0 Security Best Current Practice (RFC 9700) Guide and the SaaS and OAuth App Governance Guide.
Detection
- Zone-to-inventory reconciliation: export every DNS zone you host and, for each record pointing at a cloud or SaaS target, confirm the target exists and belongs to you. Microsoft recommends maintaining a service catalogue of FQDN endpoints and owners and reviewing zones regularly.
- Provider tooling: Microsoft publishes the Get-DanglingDnsRecords PowerShell script, which lists CNAMEs pointing at Azure resources and checks whether they exist; it needs Reader on the subscriptions and read access to Azure Resource Graph, and accepts an input file for zones hosted elsewhere. Microsoft Defender for App Service alerts when an App Service is decommissioned but its custom domain remains in DNS.
- Response fingerprints: OWASP notes typical signs such as a GitHub Pages 404 "There isn't a GitHub Pages site here" or an S3
NoSuchBucketresponse for a CNAME target. Treat automated fingerprint matches as leads and confirm manually; OWASP warns that tools produce false positives. When testing your own estate, never claim a resource to "prove" the issue unless your rules of engagement allow it. - External attack surface monitoring: passive DNS, certificate transparency logs and ASM tools reveal subdomains you did not know existed, including ones created by other teams or agencies.
- Expiry monitoring: track registration expiry for every third-party domain your records point to, and for your own secondary domains.
- Certificate transparency: alert on new certificates issued for your names by issuers you do not use, which can indicate a takeover in progress.
Metrics:
- Number of dangling records found per month, and mean time from detection to removal.
- Percentage of DNS records with a mapped owner and live target.
- Percentage of decommissioning changes that removed DNS before the resource (from change records or pipeline logs).
- Percentage of custom domains on supported platforms with ownership verification in place.
Prevention and hardening
| Control | How it works | Limits |
|---|---|---|
| Delete DNS before deprovisioning | Removes the pointer before the name becomes claimable; Microsoft suggests delete locks on resources with custom DNS entries as a reminder | Depends on people and runbooks; automate it in pipelines |
| Alias records (Azure DNS, Route 53) | The record is tied to the resource lifecycle; in Azure, deleting the resource leaves the alias empty rather than dangling | Azure supports alias targets for Front Door, Traffic Manager, CDN endpoints and public IPs only |
| App Service domain verification | An asuid.{subdomain} TXT record with your verification ID prevents another subscription validating the custom domain | Others can still create an app with the old name, but cannot bind your domain to it |
| GitHub Pages domain verification | A _github-pages-challenge-ORGANIZATION TXT record limits publishing on the domain and its immediate subdomains to your repositories | Does not protect deeper names under a wildcard |
| Certificate-bound custom domains | CloudFront requires a trusted certificate covering an alternate domain name before it can be added | Remove alternate names and DNS when distributions are deleted |
| No wildcards to shared platforms | Removes whole classes of claimable names | Requires explicit records per service |
| Infrastructure as code for DNS | DNS records are created and destroyed in the same change as the resource | Only covers zones managed in code |
| Narrow cookie scope | Set cookies host-only or use the __Host- prefix so subdomains cannot read them | Does not stop phishing or token delivery |
| CAA records | Restrict which certificate authorities may issue for your domains | An attacker controlling the name can still obtain a certificate from a permitted CA that validates by HTTP or DNS |
Process matters as much as tooling. Add "remove DNS entry" to every decommissioning checklist, give each zone an owner, and require that any new CNAME to an external platform is registered in the service catalogue with an owner and review date. See the Authoritative DNS and Registrar Account Security Guide for protecting the zones themselves.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev. 5 | CM-8 System Component Inventory; CM-3 Configuration Change Control; SC-20 Secure Name/Address Resolution Service (Authoritative Source); RA-5 Vulnerability Monitoring and Scanning | DNS and endpoint inventory, decommissioning as controlled change, authoritative DNS integrity, scanning for dangling records |
| NIST CSF 2.0 | ID.AM-02 inventories of services; ID.AM-04 supplier services; ID.RA-01 vulnerabilities identified | Knowing which names exist, which third parties they point to, and recording dangling records as vulnerabilities |
| OWASP WSTG | WSTG-CONF-10 Test for Subdomain Takeover | Test procedure for application assessments |
| MITRE ATT&CK | T1584.001 Compromise Infrastructure: Domains | Adversary use of captured domains and subdomains |
Rolling out the controls
- Discover: export all zones (including those managed by agencies and subsidiaries) and run reconciliation against cloud inventories in report-only mode.
- Triage: for each dangling record, follow Microsoft's sequence: investigate whether it was already abused, find out why it was missed, delete or repoint it, and review code for hard-coded references.
- Fix the pipeline: move DNS for cloud services into the same infrastructure-as-code modules as the resources, and add a pre-destroy check that fails if a record still points at the resource.
- Verify ownership: add verification TXT records for every platform that supports them, then remove wildcard records to shared platforms.
- Monitor continuously: schedule reconciliation daily, alert the zone owner on any new dangling record, and track the metrics above.
Lessons from incidents
Stale domains do not only sit in your DNS zones; they sit in allowlists. In the ForcedLeak research on Salesforce Agentforce, an expired domain remained on a content security policy allowlist. A researcher re-registered it for about $5, and data sent to that trusted domain was no longer blocked. Salesforce secured the domain and began enforcing Trusted URLs for Agentforce and Einstein AI on 8 September 2025. The lesson matches dangling DNS: any name you trust, in DNS, CSP, CORS, OAuth redirect URIs or webhook settings, must be owned and monitored for as long as the trust exists.
Practitioner checklist
- Export every DNS zone and map each record to an owner and a live target you control.
- Run dangling DNS reconciliation at least daily and alert zone owners on findings.
- Make "remove DNS first" a mandatory step in decommissioning runbooks and pipelines.
- Use alias records and DNS in infrastructure as code wherever supported.
- Add ownership verification records for Azure App Service, GitHub Pages and other platforms that support them.
- Remove wildcard records that point at shared hosting platforms.
- Scope cookies to the host and review CORS, CSP and OAuth redirect allowlists for names you no longer own.
- Monitor certificate transparency and third-party domain expiry for names you depend on.
- When a dangling record is found, investigate for prior abuse before deleting it.
Standards and references
- Microsoft Learn: Prevent dangling DNS entries and avoid subdomain takeover
- OWASP: Web Security Testing Guide, WSTG-CONF-10 Test for Subdomain Takeover
- GitHub Docs: Verifying your custom domain for GitHub Pages
- AWS: Use custom URLs by adding alternate domain names (CNAMEs) in CloudFront
- MITRE ATT&CK: T1584.001 Compromise Infrastructure: Domains
- NIST: SP 800-53 Rev. 5
Related NHI Mgmt Group resources: Attack Surface Management Guide · DNS Security Guide · Authoritative DNS and Registrar Account Security Guide · DNS Hijack Playbook