Skip to content

Lesson 2 of 14 · 15m

SPF Authorizes a Path

SPF is a DNS-published list of IPs allowed to use your envelope domain — it validates the connecting server's network path, never the human sender.

What Actually Happens

When a remote MTA issues MAIL FROM:<news@sudosecurity.org>, the receiving server extracts the domain — sudosecurity.org — and looks up its TXT record. If it finds v=spf1 mx ~all, it walks the mechanism list left to right: mx expands to the A/AAAA records behind the domain's MX hosts, the receiver compares the connecting IP against that set, hits the terminal ~all, and stamps softfail into Authentication-Results: if nothing matched.

Read that again. SPF compared an IP address to a list. It checked whether this network path may claim the envelope domain sudosecurity.org. It said nothing about who wrote the message, nothing about the From: header, and nothing about whether the content is honest.

Mechanisms and the Two Limits That Bite

The useful mechanisms are ip4:/ip6: (explicit ranges), a and mx (the domain's own records), include: (another domain's SPF, evaluated recursively), exists: (any record resolves = pass), and the redirect= modifier (use that domain's policy instead of this one). Each gets a qualifier: + pass, - fail, ~ softfail, ? neutral. No qualifier means +.

RFC 7208 enforces two limits receivers actually enforce: at most 10 mechanisms and modifiers that cause DNS lookups (a, mx, include, exists, ptr, redirect), counting nested include expansions; and at most 2 void lookups — lookups that return empty. Exceed either and the receiver returns permerror, which DMARC treats as a failure. The classic way to hit it: include: a provider whose own record includes three more, stacked on yours. Audit the expanded chain, not just your one line.

And never ptr — it's deprecated in RFC 7208 precisely because it's slow and unreliable. Some old docs still recommend it.

The Wrong Mental Model

The assumption is that SPF proves the sender. It proves the connecting IP was authorized to use the envelope domain. Two consequences that surprise people the first time:

  • Forwarding breaks it. When a server forwards mail, it keeps the original MAIL FROM but connects from its own IP — which is not in your SPF list. fail. The standard fix is SRS (Sender Rewriting Scheme): the forwarder rewrites the envelope to something like SRS0=hash=ttl=original-domain=localpart@forwarder.example, so SPF now checks the forwarder's own domain. If you run a forwarder, enable SRS or you will break other people's authentication for them.
  • +all is SPF-shaped nothing. v=spf1 +all "authorizes" every IP on the internet. Auditors still find it in the wild — usually left behind by someone who wanted the record to exist without thinking about what it said. Equivalent to publishing no SPF, except it looks deliberate.

Evidence From Production

Run dig TXT sudosecurity.org today and you get v=spf1 mx ~all: the only authorized senders are the MX hosts themselves, everything else softfails, and nothing is hard-rejected yet. The ~all is deliberate — while DMARC reports are still being collected, softfail keeps legitimate-but-unlisted senders (a forgotten cron job, a new transactional provider) deliverable but flagged. The moment that record assumed a provider — say a Brevo include for newsletter sending — was removed, that provider's mail instantly started failing SPF. Stale include: entries and stale integrations are the same problem seen from opposite ends.

Correct Practice

Enumerate every host and service that sends with your envelope domain before you write the record — web server, MTA, CRM, billing. Keep the expanded lookup count under 10; flatten or drop include:s for providers you no longer use. Publish ~all while you monitor DMARC reports, tighten to -all only after the reports show zero legitimate failures. And re-audit quarterly: SPF records rot faster than almost any other DNS you own.

Keep reading

Related articles from the SudoSecurity blog.