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.
In this guide
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 itHide the instructions
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
Part 1: The DNS lifecycle evidence worksheet93 lines
Part 2: A safe verification procedure for a suspected dangling record42 lines
Part 3: The lab files527 lines
Part 4: Check the invented zone107 lines
Part 5: The two orders for launching and retiring a name38 lines
Part 6: The regression test50 lines
Part 7: Run the checks on your own zone23 lines
Whole template924 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.
================================================================
PART 1: THE DNS LIFECYCLE EVIDENCE WORKSHEET
Keep one row per hostname, for every zone you hold, including old domains that only redirect. Fill it in from your zone file and your provider accounts, not from memory. Each column below says what to write and why the column is there, with its source in parentheses, or "this page's advice" where no source makes the choice for you.
Source names used in Parts 1 and 2:
RFC 1034 IETF RFC 1034, Domain Names: Concepts and Facilities, November 1987
RFC 9499 IETF RFC 9499, DNS Terminology, March 2024 (BCP 219)
WSTG-CONF-10 OWASP Web Security Testing Guide v4.2, Test for Subdomain Takeover
MDN MDN Web Docs, Subdomain takeover
Microsoft Microsoft Learn, Prevent dangling DNS entries and avoid subdomain takeover, written for Azure
App Service Microsoft Learn, Set up an existing custom domain name for your app (Azure App Service)
GitHub Pages GitHub Docs, Verifying your custom domain for GitHub Pages
THE COLUMNS
1. Hostname
The full name, such as help.harbourline.example. Include names that used to be in use and still have a record. WSTG-CONF-10's test objectives are to enumerate all possible domains, previous and current, and to identify forgotten or misconfigured domains.
2. Record type, target and TTL, copied from the zone
For example CNAME harbourline.desk.helpdeskhost.example, A 192.0.2.10 or NS ns1.oldagency-dns.example, with the TTL. A CNAME record identifies its owner name as an alias for the canonical name in its data (RFC 1034, 3.6.2). WSTG-CONF-10 says the weakness could be exploited for a wide variety of record types, including A, CNAME, MX, NS and TXT. The TTL is how long a record can be cached before it should be discarded (RFC 1034, 3.6), which sets the wait in column 9.
3. Points at: resource, provider, account and account holder
The named resource behind the target, the provider, the account it sits in and the person who holds that account. Microsoft recommends a service catalogue of the endpoints you use and their application owners. It says that if you have access to all subscriptions in your Azure tenant, you include all of them in the inventory, and if you do not, you document which subscriptions the inventory covers.
4. Business owner, and why the hostname exists
The person who can say what the name is for and approve retiring it, and one line on why it exists. Microsoft's catalogue names application owners. The reason line is this page's advice: a name nobody can explain is a name nobody feels able to remove.
5. Resource status
One of three: exists and is ours; exists and is not in any account we hold; does not exist. Microsoft's regular review asks two things of each record: that the resource it targets exists, and that you own it. "Exists and is not in any account we hold" is the status to escalate (Part 2, step 5).
6. Provider verification
Whether the provider binds the name to one account through a verification record you publish, the record's name, and whether it is in your zone; or "provider has none", or "not checked". App Service and GitHub Pages each describe their own, with limits, in their own documentation. Read each provider's documentation rather than assuming (this page's advice; MDN suggests asking each hosting vendor how they verify that someone claiming a virtual host has a legitimate claim to the domain name).
7. Last checked
The date, who checked, and how: zone file, resolver, provider console. WSTG-CONF-10 recommends continuous monitoring and periodic checks as best practice, and Microsoft recommends reviewing DNS records regularly.
Filled in when a name is retired:
8. Approval
Who approved retiring the name, and when (this page's advice).
9. Order of steps, with a date for each
The record removed first. Then, once the TTL from column 2 has passed, the resource deleted at the provider. Then any verification record for the name removed, if nothing else relies on it. MDN: start deprovisioning by removing DNS records first. Microsoft: put "Remove DNS entry" on the list of required checks when decommissioning a service. The TTL wait and the verification record coming last are this page's advice; GitHub Pages says to keep its verification TXT record in your DNS configuration to make sure the domain remains verified.
10. Evidence the name no longer resolves
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, not the status alone. RFC 1034 (4.3.1) says that when recursive service is requested and available, a name error may include CNAME records that indicate the original query name was an alias for a name which does not exist. On this page's reading, an NXDOMAIN answer can therefore still carry the dangling CNAME. RFC 9499 gives NXDOMAIN as the name error for a name that does not exist, and NODATA for a NOERROR answer with no records of the type asked for.
A BLANK ROW TO COPY
Hostname:
Record type, target and TTL:
Points at (resource, provider, account, account holder):
Business owner, and why the hostname exists:
Resource status (exists and is ours / exists and is not in any account we hold / does not exist):
Provider verification (record name and whether present, or provider has none, or not checked):
Last checked (date, by whom, how):
Decommission approval (who, date):
Decommission order (record removed on, resource deleted on, verification record removed on):
Evidence the name no longer resolves (command, date, answer):
THREE ROWS FROM THE LAB'S INVENTED ZONE
Hostname: help.harbourline.example
Record type, target and TTL: CNAME harbourline.desk.helpdeskhost.example, 3600
Points at: helpdesk, at helpdeskhost, account hl-support, held by the customer service lead
Business owner, and why the hostname exists: none recorded, so the checker reports it as unowned; the help centre is in use, so name an owner before the next check
Resource status: exists and is ours
Provider verification: TXT _helpdeskhost-verify.help.harbourline.example, present
Last checked: the date of your own check
Decommission: not being retired
Hostname: blog.harbourline.example
Record type, target and TTL: CNAME harbourline-blog.pages.bloghost.example, 3600
Points at: blog-site, at bloghost, account hl-marketing, held by the marketing coordinator, marked deleted on 2026-03-31
Business owner, and why the hostname exists: the marketing coordinator; the company blog, since moved to the main site
Resource status: exists and is not in any account we hold. The provider table still lists the name, and the inventory has no live resource for it
Provider verification: bloghost uses none
Last checked: the date of your own check
Decommission approval: the marketing coordinator, with the date
Decommission order: the resource was deleted first and the record left behind, so Part 2, step 5 applies: copy the record, remove it, then investigate
Evidence the name no longer resolves: after the TTL has passed, an NXDOMAIN or NOERROR status and an answer section with no CNAME and no address for the name, with the command and the date (column 10; this page's advice)
Hostname: winter-sale.harbourline.example
Record type, target and TTL: CNAME winter-sale-2025.sites.campaignhost.example, 3600
Points at: winter-page, at campaignhost, account hl-marketing, marked deleted on 2026-01-15
Business owner, and why the hostname exists: the marketing coordinator; the 2025 winter sale page
Resource status: does not exist. The provider table has no record of the name
Provider verification: campaignhost uses none
Last checked: the date of your own check
Decommission approval: the marketing coordinator, with the date
Decommission order: record removed now; the resource is already gone
Evidence the name no longer resolves: after the TTL has passed, an NXDOMAIN or NOERROR status and an answer section with no CNAME and no address for the name, with the command and the date (column 10; this page's advice)
================================================================
PART 2: A SAFE VERIFICATION PROCEDURE FOR A SUSPECTED DANGLING RECORD
Use it only on zones your organisation holds, or that you are authorised in writing to check. Every step reads something: your zone, a resolver's answer, your own provider accounts, or the response your own hostname gives. No step creates, registers or claims anything at any provider, and the procedure ends before anything is created anywhere.
Step 1. Read the record
Do: open the zone at your DNS host, or your exported zone file, and copy the record exactly: owner name, type, target and TTL. Copy any verification TXT record for the same name too.
Decide: if the name is not in a zone your organisation holds, stop; it is not yours to check. Otherwise go to step 2.
Step 2. Resolve the chain
Do: ask a resolver for the name (Part 7 has the commands) and write down every CNAME in the answer and the final status.
Why: when recursive service is requested and available, RFC 1034 (4.3.1) says the response is one of three things: the answer to the query, possibly prefaced by one or more CNAME records for the aliases met on the way; a name error indicating that the name does not exist, which may include CNAME records showing that the original name was an alias for a name which does not exist; or a temporary error. RFC 9499 gives NXDOMAIN as the shorthand for that name error.
Decide:
NOERROR, with an address at the end of the chain: go to step 3.
NXDOMAIN, with one or more CNAME records in the answer: the chain ends at a name that does not exist. Go to step 3.
SERVFAIL, REFUSED, or no servers could be reached: WSTG-CONF-10 lists these, with NXDOMAIN, as responses that warrant further investigation. For an NS record, go to step 3 with the delegation's name servers as the target.
Step 3. Classify the target
Do: put the end of the chain in one of three classes.
a. An address. You will look for it in your own provider accounts in step 4. WSTG-CONF-10's example uses a whois lookup on the address to identify the provider that holds it.
b. A provider hostname: a name under a provider's domain, such as a store, blog or help desk host. Write down the provider.
c. A name that does not resolve: the NXDOMAIN case from step 2. For an NS record whose name servers do not answer, check with a domain registrar search whether the name servers' domain is active, which is the check WSTG-CONF-10 describes; it says that if the domain is available for purchase, the subdomain is vulnerable. Noting who now holds the domain is this page's advice. Do not register it.
Decide: go to step 4 with the provider and the target written down.
Step 4. Check your own provider accounts for the resource
Do: sign in to each account your organisation holds at that provider and look for the resource that answers to this hostname. Ask anyone who might hold an account you do not know about: the agency, a former developer, the team that ran the campaign. Microsoft's review asks two things of each target: that the resource exists, and that you own it.
Decide:
Found in one of your accounts: the status is "exists and is ours". Go to step 6.
Not found in any account you hold: go to step 5.
Step 5. Read the response the hostname gives
Do: request the hostname once, from a private browser window that is signed in to nothing on your domain. Write down the status code and what the page shows. Do not sign in, submit a form or follow its links. (This page's advice, because MDN says whoever holds the name can potentially read cookies set from the main domain.)
Decide:
The name does not resolve, or the provider shows its own error page and holds nothing for the name in your accounts: the status is "does not exist" (this page's advice). Go to step 6.
Content you do not recognise: the status is "exists and is not in any account we hold". Treat it as a possible takeover. Copy the record's value, then remove the record, which is MDN's first step if possible, and follow your incident response procedures, as Microsoft advises. Clever Ops does not provide incident response, so bring in an incident response specialist. Then go to step 7.
Step 6. Decide: remove, repoint or keep
Remove, when the name has no current use: get the business owner's approval and follow the order in Part 1, column 9. WSTG-CONF-10's remediation is to remove the vulnerable DNS resource records from the zone.
Repoint, when the name is still needed: point it at a resource your organisation holds, and have that resource ready before you change the record. Microsoft's advice is to delete the record if it is no longer in use, or point it at the correct resource owned by your organisation, and MDN's is to create DNS records last.
Keep, when the resource exists and is yours: record a business owner, and whether the provider's verification record is in place.
Step 7. Record the evidence
Fill in the worksheet row: the record as it was, the resolver's answer and status, the accounts searched and who searched them, the response the hostname gave, the decision, who approved it, the date of each change, and, once the TTL has passed after the change, an NXDOMAIN or NOERROR status and an answer section that holds no CNAME and no address for the name (Part 1, column 10).
The procedure ends here. Nothing in it creates, registers or claims a resource at any provider. WSTG-CONF-10's own A and CNAME record walkthrough goes one step further and claims the name through GitHub Pages. Do not take that step. 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.
================================================================
PART 3: THE LAB FILES
================================================================
Make an empty folder, save the eight files below into it with the names shown, and open a terminal in that folder.
================================================================
FILE 1 OF 8: zone.txt
================================================================
; zone.txt: the zone of an invented business, Harbourline Supplies, as its
; DNS host would export it. Illustration only. Every name, address, provider
; and account in this lab is invented. harbourline.example and the provider
; names sit under .example, a top level name RFC 2606 reserves for examples.
; The addresses come from the documentation ranges in IANA's special-purpose
; address registry.
$ORIGIN harbourline.example.
@ 3600 IN A 192.0.2.10
@ 3600 IN MX 10 harbourline.mail.mailhost.example.
www 3600 IN CNAME harbourline.example.
shop 3600 IN CNAME harbourline.stores.storehost.example.
_storehost-verify.shop 3600 IN TXT "storehost-verify=hl-store-4471"
blog 3600 IN CNAME harbourline-blog.pages.bloghost.example.
winter-sale 3600 IN CNAME winter-sale-2025.sites.campaignhost.example.
old-api 3600 IN A 198.51.100.24
labs 3600 IN NS ns1.oldagency-dns.example.
help 3600 IN CNAME harbourline.desk.helpdeskhost.example.
_helpdeskhost-verify.help 3600 IN TXT "helpdeskhost-verify=hl-support-1182"
================================================================
FILE 2 OF 8: zone-cleaned.txt
================================================================
; zone-cleaned.txt: the same invented zone after the verification procedure.
; The records for blog, winter-sale, old-api and labs were removed. help was
; kept, and its business owner still has to be written into the inventory.
$ORIGIN harbourline.example.
@ 3600 IN A 192.0.2.10
@ 3600 IN MX 10 harbourline.mail.mailhost.example.
www 3600 IN CNAME harbourline.example.
shop 3600 IN CNAME harbourline.stores.storehost.example.
_storehost-verify.shop 3600 IN TXT "storehost-verify=hl-store-4471"
help 3600 IN CNAME harbourline.desk.helpdeskhost.example.
_helpdeskhost-verify.help 3600 IN TXT "helpdeskhost-verify=hl-support-1182"
================================================================
FILE 3 OF 8: inventory.txt
================================================================
# inventory.txt: the provider resources the invented business knows it holds,
# one per line. Illustration only.
# Fields, separated by a vertical bar:
# resource | provider | account | account holder | endpoint (address or provider name) | status | hostnames it serves | business owner | why it exists
web-01 | webhost | hl-main | Operations manager | 192.0.2.10 | live | harbourline.example www.harbourline.example | Operations manager | main website
mail | mailhost | hl-main | Operations manager | harbourline.mail.mailhost.example | live | harbourline.example | Operations manager | company email
store | storehost | hl-store | Online sales lead | harbourline.stores.storehost.example | live | shop.harbourline.example | Online sales lead | online store
blog-site | bloghost | hl-marketing | Marketing coordinator | harbourline-blog.pages.bloghost.example | deleted 2026-03-31 | blog.harbourline.example | Marketing coordinator | company blog, moved to the main site
winter-page | campaignhost | hl-marketing | Marketing coordinator | winter-sale-2025.sites.campaignhost.example | deleted 2026-01-15 | winter-sale.harbourline.example | Marketing coordinator | 2025 winter sale page
api-server | cloudhost | hl-dev | Former developer | 198.51.100.24 | deleted 2026-02-14 | old-api.harbourline.example | Operations manager | first booking API, replaced
helpdesk | helpdeskhost | hl-support | Customer service lead | harbourline.desk.helpdeskhost.example | live | help.harbourline.example | | customer help centre
================================================================
FILE 4 OF 8: providers.txt
================================================================
# providers.txt: the fixture's own provider table. It stands in for what each
# invented provider holds today, so the lab can run with no network at all.
# The checker reads this file; it never asks a provider anything.
# Fields, separated by a vertical bar:
# name suffix | provider | verification record label, or none | provider names that exist today
mail.mailhost.example | mailhost | none | harbourline.mail.mailhost.example
stores.storehost.example | storehost | _storehost-verify | harbourline.stores.storehost.example
pages.bloghost.example | bloghost | none | harbourline-blog.pages.bloghost.example
sites.campaignhost.example | campaignhost | none | spring-launch.sites.campaignhost.example
desk.helpdeskhost.example | helpdeskhost | _helpdeskhost-verify | harbourline.desk.helpdeskhost.example
================================================================
FILE 5 OF 8: dns-lifecycle.mjs
================================================================
// dns-lifecycle.mjs: reads a zone file, an inventory of provider resources and
// the fixture's provider table, all as text, and classifies every record that
// points at another host or an address. It compares text files with each other.
// It performs no DNS query and contacts no provider. Illustration only.
import { readFileSync } from 'node:fs'
export const MATCHED = 'matched'
export const NOT_IN_INVENTORY = 'dangling: target resource not in inventory'
export const NO_PROVIDER_RECORD = "dangling: target name has no record in the fixture's own provider table"
export const UNOWNED = 'unowned: no business owner recorded'
// Record types whose data names another host or an address.
const POINTING_TYPES = ['A', 'AAAA', 'CNAME', 'MX', 'NS']
const CLASSES = ['IN', 'CH', 'HS', 'CS']
const NEWLINE = String.fromCharCode(10)
const TAB = String.fromCharCode(9)
export function readText(path) {
return readFileSync(path, 'utf8')
}
// ---------- the zone file (a subset of the RFC 1035 section 5.1 format) ----------
export function parseZone(text) {
const state = { origin: '', lastOwner: '', records: [] }
for (const entry of listZoneEntries(text)) {
readZoneEntry(entry, state)
}
return state.records
}
// One entry per record. A comment starts at a semicolon outside quotes, and
// parentheses continue an entry across lines (RFC 1035 section 5.1).
function listZoneEntries(text) {
const entries = []
let pending = null
for (const rawLine of text.split(NEWLINE)) {
const line = removeComment(rawLine).replaceAll(TAB, ' ')
if (pending) {
pending.text = pending.text + ' ' + line
if (line.includes(')')) {
entries.push(closeEntry(pending))
pending = null
}
continue
}
if (line.trim() === '') continue
const entry = { text: line, ownerOmitted: line.startsWith(' ') }
if (line.includes('(') && !line.includes(')')) pending = entry
else entries.push(closeEntry(entry))
}
return entries
}
function removeComment(line) {
let insideQuotes = false
for (let index = 0; index < line.length; index += 1) {
if (line[index] === '"') insideQuotes = !insideQuotes
if (line[index] === ';' && !insideQuotes) return line.slice(0, index)
}
return line
}
function closeEntry(entry) {
return { text: entry.text.replaceAll('(', ' ').replaceAll(')', ' '), ownerOmitted: entry.ownerOmitted }
}
function splitWords(text) {
return text.split(' ').filter(function (word) { return word !== '' })
}
function readZoneEntry(entry, state) {
const words = splitWords(entry.text)
if (words[0] === '$ORIGIN') {
state.origin = toFullName(words[1], '')
return
}
// Other directives change nothing this checker reads.
if (words[0].startsWith('$')) return
let owner = state.lastOwner
let rest = words
if (!entry.ownerOmitted) {
owner = toFullName(words[0], state.origin)
rest = words.slice(1)
}
state.lastOwner = owner
const fields = skipTtlAndClass(rest)
const type = fields[0].toUpperCase()
const data = fields.slice(1)
state.records.push({ owner: owner, type: type, data: data, target: readTarget(type, data, state.origin) })
}
// RFC 1035 section 5.1: a name ending in a dot is complete; any other name
// is relative to the origin, and @ stands for the origin itself.
export function toFullName(name, origin) {
const lower = name.toLowerCase()
if (lower === '@') return origin
if (lower.endsWith('.')) return lower.slice(0, -1)
if (origin === '') return lower
return lower + '.' + origin
}
// The TTL and class are optional and may come in either order.
function skipTtlAndClass(words) {
let index = 0
while (index < words.length - 1 && (isNumber(words[index]) || CLASSES.includes(words[index].toUpperCase()))) {
index += 1
}
return words.slice(index)
}
function isNumber(word) {
return word !== '' && Number.isInteger(Number(word))
}
function readTarget(type, data, origin) {
if (type === 'A' || type === 'AAAA') return data[0].toLowerCase()
if (type === 'CNAME' || type === 'NS') return toFullName(data[0], origin)
if (type === 'MX') return toFullName(data[1], origin)
return ''
}
// ---------- the inventory and the provider table ----------
function listDataLines(text) {
return text.split(NEWLINE).map(function (line) { return line.trim() }).filter(function (line) {
return line !== '' && !line.startsWith('#')
})
}
function splitFields(line) {
return line.split('|').map(function (field) { return field.trim() })
}
export function parseInventory(text) {
return listDataLines(text).map(function (line) {
const fields = splitFields(line)
return {
resource: fields[0], provider: fields[1], account: fields[2], accountHolder: fields[3],
endpoint: fields[4].toLowerCase(), status: fields[5], serves: splitWords(fields[6]),
businessOwner: fields[7], purpose: fields[8],
}
})
}
export function parseProviders(text) {
return listDataLines(text).map(function (line) {
const fields = splitFields(line)
return { suffix: fields[0], name: fields[1], verificationLabel: fields[2], names: splitWords(fields[3] || '') }
})
}
// ---------- the comparison ----------
export function checkZone(records, resources, providers) {
const pointing = records.filter(function (record) { return POINTING_TYPES.includes(record.type) })
return pointing.map(function (record) { return checkRecord(record, records, resources, providers) })
}
function checkRecord(record, records, resources, providers) {
const chain = followChain(record, records)
const endpoint = chain[chain.length - 1]
const resource = findLiveResource(resources, endpoint)
const provider = findProvider(providers, endpoint)
return {
hostname: record.owner,
type: record.type,
record: record.owner + ' ' + record.type + ' ' + record.data.join(' '),
chain: [record.owner].concat(chain),
resource: resource,
pastResources: findPastResources(resources, record.owner),
provider: provider,
providerListsName: provider ? provider.names.includes(endpoint) : false,
verification: describeVerification(provider, record.owner, records),
businessOwner: findBusinessOwner(resources, record.owner),
classification: classify(resource, provider, endpoint),
}
}
// RFC 1034 section 3.6.2: CNAME chains should be followed, and loops
// signalled as an error. Only names inside this zone file can be followed
// here. A name at a provider ends the chain, because the checker asks no one.
function followChain(record, records) {
const chain = [record.target]
while (chain.length < 10) {
const next = findNextInZone(chain[chain.length - 1], records)
if (!next) break
if (chain.includes(next)) throw new Error('CNAME loop at ' + next)
chain.push(next)
}
return chain
}
function findNextInZone(name, records) {
const alias = records.find(function (record) { return record.owner === name && record.type === 'CNAME' })
if (alias) return alias.target
const address = records.find(function (record) {
return record.owner === name && (record.type === 'A' || record.type === 'AAAA')
})
return address ? address.target : undefined
}
function isLive(resource) {
return resource.status === 'live'
}
function findLiveResource(resources, endpoint) {
return resources.find(function (resource) { return isLive(resource) && resource.endpoint === endpoint })
}
function findPastResources(resources, hostname) {
return resources.filter(function (resource) { return !isLive(resource) && resource.serves.includes(hostname) })
}
function findProvider(providers, endpoint) {
return providers.find(function (provider) { return endpoint.endsWith('.' + provider.suffix) })
}
function findBusinessOwner(resources, hostname) {
const serving = resources.filter(function (resource) { return resource.serves.includes(hostname) })
const owners = serving.map(function (resource) { return resource.businessOwner }).filter(Boolean)
return owners.length ? owners[0] : ''
}
function describeVerification(provider, hostname, records) {
if (!provider) return 'no provider row for this target'
if (provider.verificationLabel === 'none') return provider.name + ' uses no verification record'
const recordName = provider.verificationLabel + '.' + hostname
const found = records.some(function (record) { return record.owner === recordName && record.type === 'TXT' })
return 'TXT ' + recordName + (found ? ' present' : ' missing')
}
function classify(resource, provider, endpoint) {
if (!resource) {
if (provider && !provider.names.includes(endpoint)) return NO_PROVIDER_RECORD
return NOT_IN_INVENTORY
}
if (!resource.businessOwner) return UNOWNED
return MATCHED
}
export function isDangling(result) {
return result.classification === NOT_IN_INVENTORY || result.classification === NO_PROVIDER_RECORD
}
export function describeNextStep(result) {
if (result.classification === MATCHED) return 'keep, and write the date of this check in the worksheet'
if (result.classification === UNOWNED) return 'keep, and name a business owner before the next check'
if (result.classification === NO_PROVIDER_RECORD) return 'nothing at the provider answers to this name: remove the record, or repoint it at a resource you hold'
if (result.providerListsName) return 'the provider holds this name in an account the inventory does not list: find that account, or treat it as a possible takeover'
return 'search every account you hold for this resource; if none holds it, remove or repoint the record'
}
================================================================
FILE 6 OF 8: check-zone.mjs
================================================================
// check-zone.mjs: prints one block per hostname record in a zone file, with
// its target, the chain inside the zone, what the inventory and the provider
// table say, and a classification. Usage: node check-zone.mjs zone.txt
// It reads three text files. It sends no DNS query and contacts no provider.
import { checkZone, describeNextStep, parseInventory, parseProviders, parseZone, readText } from './dns-lifecycle.mjs'
const zonePath = process.argv[2] || 'zone.txt'
const records = parseZone(readText(zonePath))
const resources = parseInventory(readText('inventory.txt'))
const providers = parseProviders(readText('providers.txt'))
const results = checkZone(records, resources, providers)
console.log('ZONE FILE: ' + zonePath + ' (' + results.length + ' hostname records)')
for (const result of results) printResult(result)
printSummary(results)
function printResult(result) {
console.log('')
console.log(result.hostname + ' ' + result.type)
console.log(' Record: ' + result.record)
console.log(' Chain: ' + result.chain.join(' -> '))
console.log(' Inventory: ' + describeInventory(result))
console.log(' Provider table: ' + describeProviderTable(result))
console.log(' Verification: ' + result.verification)
console.log(' Business owner: ' + (result.businessOwner || 'none recorded'))
console.log(' Classification: ' + result.classification)
console.log(' Next step: ' + describeNextStep(result))
}
function describeInventory(result) {
if (result.resource) {
const resource = result.resource
return 'live resource ' + resource.resource + ' at ' + resource.provider + ', account ' + resource.account + ' (held by ' + resource.accountHolder + ')'
}
if (result.pastResources.length) {
const past = result.pastResources[0]
return 'no live resource; ' + past.resource + ' at ' + past.provider + ' is marked ' + past.status
}
return 'no live resource at this target, and no past resource for this hostname'
}
function describeProviderTable(result) {
if (!result.provider) return 'no provider row covers the target'
const listed = result.providerListsName ? 'lists' : 'does not list'
return result.provider.name + ' ' + listed + ' the target name'
}
function printSummary(results) {
console.log('')
console.log('SUMMARY')
const counts = new Map()
for (const result of results) {
counts.set(result.classification, (counts.get(result.classification) || 0) + 1)
}
for (const entry of counts) console.log(' ' + entry[1] + ' ' + entry[0])
}
================================================================
FILE 7 OF 8: lifecycle-orders.mjs
================================================================
// lifecycle-orders.mjs: plays out the two orders for launching a new events
// page and the two orders for retiring it, on copies of the cleaned fixture
// held in memory. After each step it classifies events.harbourline.example
// again. It changes no file, sends no DNS query and contacts no provider.
import { checkZone, isDangling, parseInventory, parseProviders, parseZone, readText } from './dns-lifecycle.mjs'
const HOSTNAME = 'events.harbourline.example'
const PROVIDER_NAME = 'harbourline-events.sites.campaignhost.example'
const BASE = {
records: parseZone(readText('zone-cleaned.txt')),
resources: parseInventory(readText('inventory.txt')),
providers: parseProviders(readText('providers.txt')),
}
// Each step changes one thing: the DNS record, or the resource at the provider.
function addRecord(state) {
state.records.push({ owner: HOSTNAME, type: 'CNAME', data: [PROVIDER_NAME + '.'], target: PROVIDER_NAME })
}
function removeRecord(state) {
state.records = state.records.filter(function (record) { return record.owner !== HOSTNAME })
}
function createResource(state) {
campaignhost(state).names.push(PROVIDER_NAME)
state.resources.push({
resource: 'events-page', provider: 'campaignhost', account: 'hl-marketing', accountHolder: 'Marketing coordinator',
endpoint: PROVIDER_NAME, status: 'live', serves: [HOSTNAME], businessOwner: 'Marketing coordinator', purpose: 'events page',
})
}
function deleteResource(state) {
const provider = campaignhost(state)
provider.names = provider.names.filter(function (name) { return name !== PROVIDER_NAME })
for (const resource of state.resources) {
if (resource.resource === 'events-page') resource.status = 'deleted'
}
}
function campaignhost(state) {
return state.providers.find(function (provider) { return provider.name === 'campaignhost' })
}
const ORDERS = [
{ title: 'LAUNCH, RECORD FIRST', start: [], steps: [['add the CNAME record', addRecord], ['create the page at campaignhost', createResource]] },
{ title: 'LAUNCH, RESOURCE FIRST', start: [], steps: [['create the page at campaignhost', createResource], ['add the CNAME record', addRecord]] },
{ title: 'RETIRE, RESOURCE FIRST', start: [createResource, addRecord], steps: [['delete the page at campaignhost', deleteResource], ['remove the CNAME record', removeRecord]] },
{ title: 'RETIRE, RECORD FIRST', start: [createResource, addRecord], steps: [['remove the CNAME record', removeRecord], ['delete the page at campaignhost', deleteResource]] },
]
for (const order of ORDERS) playOrder(order)
function playOrder(order) {
const state = structuredClone(BASE)
for (const change of order.start) change(state)
console.log(order.title)
console.log(' Before: ' + describeHostname(state))
let danglingSteps = 0
order.steps.forEach(function (step, index) {
step[1](state)
const result = findResult(state)
if (result && isDangling(result)) danglingSteps += 1
console.log(' Step ' + (index + 1) + ': ' + step[0])
console.log(' ' + describeHostname(state))
})
console.log(' Steps that left a dangling record: ' + danglingSteps)
console.log('')
}
function findResult(state) {
const results = checkZone(state.records, state.resources, state.providers)
return results.find(function (result) { return result.hostname === HOSTNAME })
}
function describeHostname(state) {
const result = findResult(state)
if (!result) return HOSTNAME + ' has no record in the zone'
return HOSTNAME + ' -> ' + result.chain[1] + ': ' + result.classification
}
================================================================
FILE 8 OF 8: zone-check.test.mjs
================================================================
// zone-check.test.mjs: a regression test for a zone file. The first test checks
// the checker against the worked example in zone.txt. The second fails when
// any record in the zone under test is dangling, and names each one.
// Usage: node zone-check.test.mjs (tests zone-cleaned.txt)
// node zone-check.test.mjs zone-proposed.txt (tests a proposed change)
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { checkZone, isDangling, parseInventory, parseProviders, parseZone, readText } from './dns-lifecycle.mjs'
const zonePath = process.argv[2] || 'zone-cleaned.txt'
const resources = parseInventory(readText('inventory.txt'))
const providers = parseProviders(readText('providers.txt'))
function checkFile(path) {
return checkZone(parseZone(readText(path)), resources, providers)
}
const EXPECTED_FOR_ZONE_TXT = [
'harbourline.example A: matched',
'harbourline.example MX: matched',
'www.harbourline.example CNAME: matched',
'shop.harbourline.example CNAME: matched',
'blog.harbourline.example CNAME: dangling: target resource not in inventory',
"winter-sale.harbourline.example CNAME: dangling: target name has no record in the fixture's own provider table",
'old-api.harbourline.example A: dangling: target resource not in inventory',
'labs.harbourline.example NS: dangling: target resource not in inventory',
'help.harbourline.example CNAME: unowned: no business owner recorded',
]
function describe(result) {
return result.hostname + ' ' + result.type + ': ' + result.classification
}
test('checker: classifies the nine records in zone.txt as the worked example expects', function () {
assert.deepEqual(checkFile('zone.txt').map(describe), EXPECTED_FOR_ZONE_TXT)
})
test(zonePath + ': no record points at a resource missing from the inventory or the provider table', function () {
const dangling = checkFile(zonePath).filter(isDangling).map(describe)
assert.deepEqual(dangling, [])
})
================================================================
PART 4: CHECK THE INVENTED ZONE
================================================================
Command: node check-zone.mjs zone.txt
ZONE FILE: zone.txt (9 hostname records)
harbourline.example A
Record: harbourline.example A 192.0.2.10
Chain: harbourline.example -> 192.0.2.10
Inventory: live resource web-01 at webhost, account hl-main (held by Operations manager)
Provider table: no provider row covers the target
Verification: no provider row for this target
Business owner: Operations manager
Classification: matched
Next step: keep, and write the date of this check in the worksheet
harbourline.example MX
Record: harbourline.example MX 10 harbourline.mail.mailhost.example.
Chain: harbourline.example -> harbourline.mail.mailhost.example
Inventory: live resource mail at mailhost, account hl-main (held by Operations manager)
Provider table: mailhost lists the target name
Verification: mailhost uses no verification record
Business owner: Operations manager
Classification: matched
Next step: keep, and write the date of this check in the worksheet
www.harbourline.example CNAME
Record: www.harbourline.example CNAME harbourline.example.
Chain: www.harbourline.example -> harbourline.example -> 192.0.2.10
Inventory: live resource web-01 at webhost, account hl-main (held by Operations manager)
Provider table: no provider row covers the target
Verification: no provider row for this target
Business owner: Operations manager
Classification: matched
Next step: keep, and write the date of this check in the worksheet
shop.harbourline.example CNAME
Record: shop.harbourline.example CNAME harbourline.stores.storehost.example.
Chain: shop.harbourline.example -> harbourline.stores.storehost.example
Inventory: live resource store at storehost, account hl-store (held by Online sales lead)
Provider table: storehost lists the target name
Verification: TXT _storehost-verify.shop.harbourline.example present
Business owner: Online sales lead
Classification: matched
Next step: keep, and write the date of this check in the worksheet
blog.harbourline.example CNAME
Record: blog.harbourline.example CNAME harbourline-blog.pages.bloghost.example.
Chain: blog.harbourline.example -> harbourline-blog.pages.bloghost.example
Inventory: no live resource; blog-site at bloghost is marked deleted 2026-03-31
Provider table: bloghost lists the target name
Verification: bloghost uses no verification record
Business owner: Marketing coordinator
Classification: dangling: target resource not in inventory
Next step: the provider holds this name in an account the inventory does not list: find that account, or treat it as a possible takeover
winter-sale.harbourline.example CNAME
Record: winter-sale.harbourline.example CNAME winter-sale-2025.sites.campaignhost.example.
Chain: winter-sale.harbourline.example -> winter-sale-2025.sites.campaignhost.example
Inventory: no live resource; winter-page at campaignhost is marked deleted 2026-01-15
Provider table: campaignhost does not list the target name
Verification: campaignhost uses no verification record
Business owner: Marketing coordinator
Classification: dangling: target name has no record in the fixture's own provider table
Next step: nothing at the provider answers to this name: remove the record, or repoint it at a resource you hold
old-api.harbourline.example A
Record: old-api.harbourline.example A 198.51.100.24
Chain: old-api.harbourline.example -> 198.51.100.24
Inventory: no live resource; api-server at cloudhost is marked deleted 2026-02-14
Provider table: no provider row covers the target
Verification: no provider row for this target
Business owner: Operations manager
Classification: dangling: target resource not in inventory
Next step: search every account you hold for this resource; if none holds it, remove or repoint the record
labs.harbourline.example NS
Record: labs.harbourline.example NS ns1.oldagency-dns.example.
Chain: labs.harbourline.example -> ns1.oldagency-dns.example
Inventory: no live resource at this target, and no past resource for this hostname
Provider table: no provider row covers the target
Verification: no provider row for this target
Business owner: none recorded
Classification: dangling: target resource not in inventory
Next step: search every account you hold for this resource; if none holds it, remove or repoint the record
help.harbourline.example CNAME
Record: help.harbourline.example CNAME harbourline.desk.helpdeskhost.example.
Chain: help.harbourline.example -> harbourline.desk.helpdeskhost.example
Inventory: live resource helpdesk at helpdeskhost, account hl-support (held by Customer service lead)
Provider table: helpdeskhost lists the target name
Verification: TXT _helpdeskhost-verify.help.harbourline.example present
Business owner: none recorded
Classification: unowned: no business owner recorded
Next step: keep, and name a business owner before the next check
SUMMARY
4 matched
3 dangling: target resource not in inventory
1 dangling: target name has no record in the fixture's own provider table
1 unowned: no business owner recorded
Reading the report:
harbourline.example, www and shop Matched. Each target is a live resource in the inventory with a business owner. www is an alias inside the zone, and the checker follows it to the address at the apex, as a resolver does in most cases, according to RFC 1034.
blog The inventory marks the blog deleted on 2026-03-31, yet the provider table still lists its provider name. In a real zone this is the status to escalate: the name exists at the provider, and not in any account the inventory lists. Part 2, step 5 applies.
winter-sale The campaign page was deleted and the provider table has no record of the name. This is the state MDN describes: a CNAME with no host providing content for it. Remove the record.
old-api An address record for a server the inventory marks deleted. Search every account you hold for the address; if none holds it, remove the record.
labs A delegation to name servers at a former agency's domain, with no inventory row at all. WSTG-CONF-10 rates an NS takeover, although less likely, as having the highest impact. Remove the delegation, or move the subzone to a DNS host your organisation holds.
help The help desk is live and its verification record is in place, but nobody in the business is recorded as its owner. It stays, and it needs an owner.
================================================================
PART 5: THE TWO ORDERS FOR LAUNCHING AND RETIRING A NAME
================================================================
lifecycle-orders.mjs starts from zone-cleaned.txt and plays out two ways to launch events.harbourline.example on the invented campaign host, and two ways to retire it, classifying the name again after every step. It works on copies in memory and changes no file.
Command: node lifecycle-orders.mjs
LAUNCH, RECORD FIRST
Before: events.harbourline.example has no record in the zone
Step 1: add the CNAME record
events.harbourline.example -> harbourline-events.sites.campaignhost.example: dangling: target name has no record in the fixture's own provider table
Step 2: create the page at campaignhost
events.harbourline.example -> harbourline-events.sites.campaignhost.example: matched
Steps that left a dangling record: 1
LAUNCH, RESOURCE FIRST
Before: events.harbourline.example has no record in the zone
Step 1: create the page at campaignhost
events.harbourline.example has no record in the zone
Step 2: add the CNAME record
events.harbourline.example -> harbourline-events.sites.campaignhost.example: matched
Steps that left a dangling record: 0
RETIRE, RESOURCE FIRST
Before: events.harbourline.example -> harbourline-events.sites.campaignhost.example: matched
Step 1: delete the page at campaignhost
events.harbourline.example -> harbourline-events.sites.campaignhost.example: dangling: target name has no record in the fixture's own provider table
Step 2: remove the CNAME record
events.harbourline.example has no record in the zone
Steps that left a dangling record: 1
RETIRE, RECORD FIRST
Before: events.harbourline.example -> harbourline-events.sites.campaignhost.example: matched
Step 1: remove the CNAME record
events.harbourline.example has no record in the zone
Step 2: delete the page at campaignhost
events.harbourline.example has no record in the zone
Steps that left a dangling record: 0
Reading the evidence: launching record first and retiring resource first each leave one step at which the name points at a provider name that nothing answers to. Those are the provisioning and deprovisioning gaps MDN describes. The other two orders leave no such step. In the lab a step is instant. In a business, the gap between two steps lasts until someone does the second one.
================================================================
PART 6: THE REGRESSION TEST
================================================================
The first test checks the checker against the nine expected results for zone.txt, so it passes in every run. The second fails when any record in the zone under test is dangling, and names each one. Run with no argument, it tests zone-cleaned.txt. Here it tests a proposed change: a copy of zone-cleaned.txt with one new record for a promotion page that does not exist at the provider, then the same copy with that line removed.
Commands:
cp zone-cleaned.txt zone-proposed.txt
echo "promo 3600 IN CNAME harbourline-promo.sites.campaignhost.example." >> zone-proposed.txt
node zone-check.test.mjs zone-proposed.txt
✔ checker: classifies the nine records in zone.txt as the worked example expects (1.733875ms)
✖ zone-proposed.txt: no record points at a resource missing from the inventory or the provider table (1.36125ms)
ℹ tests 2
ℹ suites 0
ℹ pass 1
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 6.830875
✖ failing tests:
test at zone-check.test.mjs:38:1
✖ zone-proposed.txt: no record points at a resource missing from the inventory or the provider table (1.36125ms)
AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected
+ [
+ "promo.harbourline.example CNAME: dangling: target name has no record in the fixture's own provider table"
+ ]
- []
(stack trace and error object lines removed here)
The process exits with code 1, so a pipeline step running the test fails.
Commands, after removing the line by copying the cleaned zone again:
cp zone-cleaned.txt zone-proposed.txt
node zone-check.test.mjs zone-proposed.txt
✔ checker: classifies the nine records in zone.txt as the worked example expects (1.707917ms)
✔ zone-proposed.txt: no record points at a resource missing from the inventory or the provider table (0.668958ms)
ℹ tests 2
ℹ suites 0
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 6.700667
The process exits with code 0.
================================================================
PART 7: RUN THE CHECKS ON YOUR OWN ZONE
These are steps for you to carry out on zones your organisation holds. No output is shown for them, because the answers are yours. Replace harbourline.example and the names under it with your own.
1. Export each zone from your DNS host into a text file, or copy its records into the zone file format of RFC 1035 section 5.1. The lab reads one record per line, $ORIGIN, comments after a semicolon, @ for the origin and parentheses that continue a record across lines. Save it as zone.txt in the lab folder.
2. Replace inventory.txt with your own resources, one per line in the same fields: the resource, the provider, the account, the account holder, the endpoint the provider gave you (a provider hostname or an address), its status, the hostnames it serves, the business owner and why it exists.
3. Delete every data row in providers.txt. The fixture's provider table stands in for the lab's invented providers, and you cannot know which names other accounts hold at a real provider. With the table empty, every target missing from your inventory is reported as "dangling: target resource not in inventory", and the resolver steps below show which of those names still resolve.
4. Run node check-zone.mjs zone.txt and copy each result into the worksheet in Part 1.
5. For each record the checker flags, and each CNAME and NS record, ask a resolver.
On macOS or Linux, with dig:
dig blog.harbourline.example
Read the status (NOERROR, NXDOMAIN, SERVFAIL or REFUSED; RFC 9499 explains each) and the answer section, which lists each CNAME on the way. With no type given, dig asks for an A record (BIND 9 documentation for dig).
dig +short CNAME blog.harbourline.example
+short gives a terse answer (BIND 9 documentation for dig), and RFC 1034 (5.2.2) says that when the query type is CNAME, the user is interested in the CNAME record itself, and not the records at the name it points to. For a name that is an alias, expect the alias target and nothing else (this page's description of the terse answer to a CNAME query).
dig NS labs.harbourline.example
For a delegated name. WSTG-CONF-10 lists SERVFAIL and REFUSED as the responses to an NS check that warrant further investigation.
On Windows, GitHub's documentation notes that dig is not included, and names two alternatives: the Resolve-DnsName PowerShell command, or installing BIND. With Resolve-DnsName:
Resolve-DnsName -Name blog.harbourline.example -DnsOnly
Resolve-DnsName -Name blog.harbourline.example -Type CNAME -DnsOnly
Resolve-DnsName -Name labs.harbourline.example -Type NS -DnsOnly
Microsoft's reference for the cmdlet says -DnsOnly resolves the query using only the DNS protocol, and that with no -Type it asks for both A and AAAA records.
After you remove a record, read both the status and the answer: treat the name as gone only when the status is NXDOMAIN or NOERROR and no CNAME and no address comes back for it (Part 1, column 10; this page's advice).
6. Work through the procedure in Part 2 for each flagged name, and record the evidence in the worksheet.
7. Keep zone-check.test.mjs with your DNS change records and run it on each proposed zone before it is published: node zone-check.test.mjs zone-proposed.txt. Delete its first test, or replace that test's expected list with your own reviewed results, because it checks the lab's zone.txt. 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).
8. Run all of this only on zones your organisation holds, or that you are authorised in writing to check.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.