DNS security
SPF Hijacking: How Dangling CNAMEs and Typos Let Spoofing Pass DMARC
Some spoofed mail passes DMARC because attackers took over a name your DNS still trusts: a CNAME to an expired domain, a mistyped include, or a CIDR typo. How the takeover works, how to spot it in DNS and in DMARC aggregate reports, and how to close it.
By MailConfig.pro TeamPublished 8 min read

On this page
Most spoofed mail fails DMARC, and a p=reject policy stops it. A smaller and more dangerous group passes. The attacker never touched your DNS. They registered a domain that one of your records still points to: a CNAME to a vendor domain that expired, an SPF include: with a typo in it, or a DKIM selector delegated to a service you stopped using. From then on, receivers see the attacker's servers as authorized by you. To find these, list every name in your DNS that points outside your organization, check that each target still exists and still belongs to who you think it does, and look in your DMARC aggregate reports for sources that pass but that you don't recognize.
Why this mail passes DMARC
DMARC passes when SPF or DKIM passes and the authenticated domain aligns with the visible From domain (RFC 9989, section 4.4). Normal spoofing fails here because the attacker can't publish records in your zone. A dangling record gets around that: your zone hands the answer to a zone the attacker controls.
Relaxed alignment is the default, and it makes the problem worse. Under relaxed SPF alignment the envelope-from only needs the same organizational domain as the From address. Mail with the envelope-from bounce@promo.example.com and the From address ceo@example.com aligns. So one hijacked subdomain can be enough to send DMARC-passing mail as your main domain.
Once a message passes DMARC, your policy does nothing to it. p=reject doesn't help, and neither does sp=reject. That is why this needs its own checks.
How it happens
1. A CNAME to a domain that expired
A team sets up promo.example.com as a CNAME to a campaign platform, for example customer123.mailvendor.example. Years later the platform shuts down, or moves to a new domain and lets the old one expire. Nobody removes the CNAME.
A CNAME redirects every lookup for that name, and the name can't hold any other record (RFC 2181, section 10.1). When a receiver looks up the SPF record of promo.example.com, it follows the CNAME and reads whatever TXT record the target publishes. Someone registers mailvendor.example and publishes this at the target name:
customer123.mailvendor.examplev=spf1 ip4:203.0.113.0/24 include:_spf.bulk-sender.example -allEvery server in that list can now pass SPF as promo.example.com, and through relaxed alignment as example.com. The same CNAME also sends the subdomain's website and MX lookups to the attacker.
2. A delegated DKIM selector
Many email platforms ask you to publish DKIM as a CNAME, such as s1._domainkey.example.com → s1.dkim.mailvendor.example, so they can rotate keys for you. Receivers fetch the public key at selector._domainkey.<domain> (RFC 6376, section 3.6.2.1). If the vendor's domain lapses and someone else registers it, they publish their own key at the target. Their mail then carries a valid d=example.com signature, which passes DKIM and aligns even under strict alignment. This is the strongest form of the attack, and it survives forwarding.
3. A typo in an include:
include:_spf.mailvendro.example instead of include:_spf.mailvendor.example. While the mistyped domain is unregistered, the include finds no SPF record, and RFC 7208 section 5.2 turns that into a PermError for the whole record. Your mail may still get through on DKIM, so the error can sit unnoticed for months. Once someone registers the typo domain and publishes an SPF record there, the error disappears and the registrant's servers are authorized to send as you.
4. A CIDR typo
An ip4: mechanism with a prefix length authorizes the whole network that contains the address (RFC 7208, section 5.6). A missing digit changes the size of that network:
| Written | Intended | Addresses authorized |
|---|---|---|
ip4:198.51.100.10/32 |
one server | 1 |
ip4:198.51.100.10/24 |
the server's network | 256 |
ip4:198.51.100.10/16 |
typo | 65,536 |
ip4:198.51.100.10/3 |
typo for /32 |
536,870,912 (all of 192.0.0.0 to 223.255.255.255) |
A /3 authorizes about one eighth of the IPv4 internet, including every cloud provider in that range. Nobody has to register anything: anyone who rents a server in the range can pass SPF as you. Treat any prefix shorter than /24 in IPv4, or /48 in IPv6, as something to justify.
5. Other names your SPF trusts
The same applies to a:, mx:, exists: and redirect= targets, and to every record nested inside each include. Your SPF record is only as safe as every domain it reaches, and you may not control most of them.
Find it in your DNS
Start with an inventory. Export the zone from your DNS provider; guessing names won't find the forgotten ones.
- List every record that points to another domain: CNAMEs (especially under
_domainkey), and the SPFinclude:,a:,mx:,exists:andredirect=targets. - Resolve each target. A CNAME whose target returns NXDOMAIN is dangling. The DNS lookup tool shows the full CNAME chain and the final answer.
- Check who owns the target's domain. For each external domain, run a WHOIS / RDAP lookup. An unregistered domain, a domain in
redemptionPeriodorpendingDelete, or a registration date after you created the record are red flags. A vendor domain registered last month to a stranger is not your vendor any more. - Run your SPF record through a checker. Look for PermErrors, void lookups (RFC 7208 caps them at two, section 4.6.4),
+allor?all, and unusually short CIDR prefixes.
A quick shell pass over a list of names finds the obvious cases:
# names.txt: one hostname per line, exported from your zone
while read -r name; do
target=$(dig +short CNAME "$name")
[ -z "$target" ] && continue
status=$(dig "$target" A +noall +comments | grep -o 'status: [A-Z]*')
echo "$name -> $target ($status)"
done < names.txt | grep -v NOERROR
NOERROR with no data can still be dangling, for example a CNAME to a cloud resource that was deleted. That is a different takeover class, but it is worth reviewing.
Find it in your DMARC aggregate reports
The usual way to read DMARC reports is to fix what fails. For this problem, look at what passes.
- Passing sources you can't place. Group rows by
source_ipand the authenticated domains, and look for groups that pass DMARC from networks you don't use. The method is the same as for identifying unknown senders; the difference is that these rows showpass. - SPF domains you never send from. In
auth_results, thespf/domainis the envelope-from domain (RFC 9990, section 3.1.1). A subdomain there that your team doesn't use for bounces, such aspromo.example.com, means someone is sending through it. - Unfamiliar DKIM selectors. A passing
d=example.comsignature with a selector you don't recognize points to a selector record you should look up. - A sudden change in a quiet source. A subdomain that sent nothing for a year and now sends thousands of passing messages a day needs a look today.
The free DMARC report analyzer reads a single aggregate report file and lists its sources and results, which is enough to check a handful of days by hand.
Fix and prevent it
- Delete the record, not just its target. Remove a dangling CNAME from your zone. Re-registering the old vendor domain yourself is a stopgap, not a fix.
- Correct typos and tighten ranges. Fix mistyped includes and replace short CIDR prefixes with the exact addresses or networks your providers publish.
- Lock down names that should never send. Once a name has no CNAME, publish
v=spf1 -allon it. Under DMARC,sp=reject(andnp=rejectfor names that don't exist) covers mail that fails. It cannot stop mail that passes through a hijacked record. - Consider strict SPF alignment.
aspf=sstops a hijacked subdomain from passing SPF alignment for mail from your main domain. Check first: many sending services use a custom return-path such asbounce.example.com, and that mail would then depend on DKIM alone. Look at your reports before changing it. - Decommission vendors completely. When you cancel an email service, remove its SPF include, DKIM selector CNAMEs and any custom return-path or tracking CNAMEs in the same change.
- Watch for changes. A takeover changes what your names resolve to without any edit in your own zone, so a single audit isn't enough. Repeat the inventory on a schedule.
Once the dangling records are gone, the rest of the job is ordinary DMARC enforcement: only then does p=reject mean what you think it means.
Monitoring at scale
Doing this by hand works for one domain with a short zone. MailConfig.pro's DMARC monitoring collects your aggregate reports and shows each observed sending source with its SPF and DKIM alignment, so a new source that passes stands out instead of hiding in the XML. It relies on receivers sending reports, and it shows nothing for periods when none arrived.
Frequently asked questions
Does p=reject protect me from SPF hijacking?
No. A hijacked name makes the attacker's mail pass SPF, and when that SPF domain aligns with the From domain the message passes DMARC too. Enforcement only acts on mail that fails DMARC. You have to remove the record the attacker controls.
Can I just add v=spf1 -all to the subdomain with the dangling CNAME?
No. A name that has a CNAME cannot hold any other record, so DNS providers reject the TXT record. Delete the CNAME first, then publish v=spf1 -all on the name if it should never send mail.
Is a CNAME that points to a domain that does not exist harmless?
It is harmless only until someone registers that domain. Treat every CNAME whose target returns NXDOMAIN as dangling and remove or fix it, even though nothing resolves through it today.
References
- RFC 7208: Sender Policy Framework (SPF), sections 4.6.4 (DNS lookup and void lookup limits), 5.2 (include) and 5.6 (ip4 and ip6 with CIDR length)
- RFC 9989: DMARC (May 2026), section 4.4 (identifier alignment) and the aspf and adkim tags
- RFC 9990: DMARC Aggregate Reporting (May 2026), section 3.1.1 (auth_results and policy_evaluated)
- RFC 2181: Clarifications to the DNS Specification, section 10.1 (a CNAME cannot coexist with other data)
- RFC 6376: DomainKeys Identified Mail (DKIM) Signatures, section 3.6.2.1 (key lookup at selector._domainkey)
spfdangling dnscnamesubdomain takeoveraggregate reportsalignment
Related articles
DMARC
What Is DMARC? How Email Authentication Fits Together
DMARC is a DNS record that ties SPF and DKIM to the domain in the visible From address, states what receivers should do with mail that fails, and requests reports. This guide covers alignment, the record syntax, policies, reporting and what happens when a domain has no record.
· 10 min read
DMARC
How to Identify Unknown Senders in DMARC Aggregate Reports
A step-by-step method for the unfamiliar IP addresses in your DMARC aggregate reports: which XML fields matter, how to map an IP to a service with PTR, RDAP and ASN, how to separate legitimate senders from spoofing, and how to fix SPF and DKIM alignment.
· 7 min read
SPF
SPF PermError: "Too Many DNS Lookups" and Other Causes
SPF returns permerror when a receiver cannot interpret your record. The usual cause is more than 10 DNS-querying terms, but extra void lookups, two SPF records, a syntax error or an include with no SPF record do the same. This guide shows how lookups are counted and gives corrected records.
· 8 min read
DMARC
DMARC p=none vs quarantine vs reject: Rolling Out Enforcement
p=none asks for no change in handling and gives you reports, p=quarantine asks receivers to treat failing mail as suspicious, and p=reject asks them to refuse it. This guide covers when each fits, a staged rollout, what happened to pct, and the risks from forwarding and mailing lists.
· 9 min read



