Skip to content

Lesson 4 of 9 · 27m

SPF: Mechanisms, Alignment, Lookup Limits, and Forwarding Reality

Write SPF policies that reflect actual senders, understand alignment versus validation, avoid the ten-lookup trap, and anticipate forwarding failure.

SPF is simple enough to fit in one DNS TXT record and complicated enough to cause years of bad assumptions. It answers a narrow question: is this connecting IP authorized to use this envelope sender domain? It does not authenticate the visible From: header by itself, it does not survive naive forwarding, and it does not prove the message is wanted. Treat SPF as one signal in an authentication system, not as a magic anti-phishing spell.

The narrow question SPF answers

A receiver evaluating this transaction checks the domain in the envelope sender:

MAIL FROM:<bounces@mail.sudosecurity.org>

Suppose the connecting IP is 198.51.100.24. The receiver looks up TXT records for mail.sudosecurity.org and evaluates mechanisms in order:

v=spf1 ip4:198.51.100.24 include:_spf.resend.com -all

This says the explicit IPv4 address and the networks authorized by the included provider policy may send for the envelope domain; everything else fails. If no TXT record starts with v=spf1, SPF evaluation does not happen.

Mechanisms are DNS-shaped cost

The expensive mechanisms are not the ones that look expensive:

ip4/ip6 direct authorization; a/mx resolve hosts; include evaluates another policy
redirect replaces the policy; exists is macro-driven; ptr is deprecated and unreliable

SPF has a hard limit of ten DNS-querying mechanisms and modifiers per evaluation. Exceed it and evaluation returns permerror, which is worse than a slightly conservative policy because receivers cannot determine what you intended. Nested includes count. Large cloud provider includes can consume several lookups by themselves.

Inspect before you publish with dig +short TXT mail.sudosecurity.org, then use a validation tool that recursively expands includes. Do not learn about lookup exhaustion from Gmail headers.

SPF alignment is not the same as SPF pass

DMARC cares whether the domain that passed SPF aligns with the visible From: domain. Suppose:

Header From: support@sudosecurity.org
Envelope sender: bounce@mailprovider.example
SPF pass domain: mailprovider.example

SPF passed, but SPF alignment failed because mailprovider.example does not align with sudosecurity.org. With relaxed alignment, subdomains of the same organizational domain can align; with strict alignment, exact domains are required. The lesson is practical: passing authentication in isolation is not enough for DMARC.

Forwarding breaks naive SPF assumptions

When a mailbox forwards mail without rewriting the envelope sender, the final receiving server sees the forwarder's IP but evaluates the original envelope domain. The forwarder is probably not in your SPF record. Result: SPF fail.

Sender Rewriting Scheme exists because of this. It rewrites the envelope sender into a domain controlled by the forwarder:

original:  bounces@mail.sudosecurity.org
rewritten: SRS0=abcd=EF=mail.sudosecurity.org=bounces@forwarder.example

You cannot force the world to implement SRS correctly. This is one reason DKIM matters: a surviving cryptographic signature is often the stable authentication signal across forwarding.

Field notes

  • SPF uses the envelope sender, not the visible From: header. Confusing these causes most SPF misunderstandings.
  • One domain must not publish multiple independent SPF TXT records. Receivers treat that as a broken policy.
  • include is trust. If the included provider broadens its ranges, your policy inherits that exposure.
  • Do not add ptr to modern records; it is slow, fragile, and widely ignored. Test exact SMTP client IPs, not console output for an unrelated service.

Was this lesson helpful?

Sign in to rate