Back to blog
Threat Intel
Phishing Forensics

The SPF PermError Playbook: Surviving the 10-Lookup Limit

Marketing added a new vendor, your SaaS provider updated their include, and suddenly your outbound mail is failing DMARC.

MailSleuth Research
Email Security Team
September 13, 20267 min read
Abstract illustration of glowing data cables breaking through a glass barrier representing a DNS limit.

Marketing just signed a contract for a new customer success platform and unilaterally decided to add another include statement to your root domain's TXT record.

They think they are doing the right thing by ensuring their emails authenticate. But they do not realize they just pushed your Sender Policy Framework record to eleven DNS lookups. Because RFC 7208 strictly mandates a ten-lookup limit to prevent denial-of-service attacks against receivers, your previously functioning email infrastructure is now throwing fatal errors across the board.

That silent creep of third-party dependencies is the primary reason organizations experience catastrophic authentication failures without ever touching their own mail servers. The fix requires moving from reactive firefighting to a proactive architectural stance.

The Silent Creep of Third-Party Dependencies

You authorize a vendor to send mail on your behalf. You add their include string to your DNS. It looks like a single lookup in your control panel. But you are delegating trust to an external entity, and that entity often delegates trust further down the chain.

If that vendor migrates from physical infrastructure to a cloud provider, they might add an include for Amazon SES or SendGrid. If they acquire another company, they might append that company's entire SPF tree to their own. Your lookup count increments dynamically, entirely outside your change control processes and without any notification to your security team.

When an external MTA queries your domain, it unrolls this nested tree. The protocol requires the receiving mail server to fetch every referenced domain to build a complete list of authorized IP addresses. The moment the parser hits the eleventh mechanism requiring a DNS query, it abruptly halts execution. The verdict is not a SoftFail or a TempError. It is a PermError.

A PermError is a hard fail. If your DMARC policy is set to reject, and the message lacks a valid DKIM signature to achieve alignment on the other axis, the receiving mail server drops the message. The bounce logs light up, but by the time the helpdesk escalates the routing failure to the security operations center, the business has already suffered reputational damage and lost revenue.

Unrolling the Tree Manually

Tracing the Execution Path

Before you can fix a bloated record, you have to measure it exactly how a receiving MTA measures it. That means recursive querying. You cannot just read the text record on your apex domain and count the include statements you see on the surface.

The standard Unix toolset is where incident triage begins. Running a simple dig command for TXT records reveals the top-level mechanisms, but you must manually chase every single include down its respective rabbit hole. Every time you see an include, a, mx, ptr, or exists mechanism, you add one to your mental tally and execute another recursive DNS query against that specific target domain.

The Hidden Cost of IP4 and IP6 Mechanisms

It is critical to understand what does not consume your lookup budget. Mechanisms like ip4 and ip6 are evaluated directly from the retrieved record. They do not trigger additional DNS queries. Many administrators mistakenly count these when auditing, artificially inflating their perceived risk.

The true danger lies in nested includes that hide behind vendor domains, which can dynamically shift over a weekend. A single vendor include might look harmless until you trace it and discover it hides four additional lookups behind the scenes.

Transitioning to Automated Audits

Manual recursive querying is fine for an isolated incident response scenario, but it completely fails as a preventative control. You cannot manually run diagnostic queries against your apex domain every Friday afternoon. The moment you stop checking is the exact moment a third-party vendor decides to reorganize their sending infrastructure.

This is where you must transition from ad-hoc commands to programmatic spf lookup limit monitoring. By querying an external API or running a scheduled cron job that recursively evaluates the DNS tree, you shift from reactive firefighting to proactive governance.

A mature stateful monitoring script does more than just count. It parses the TXT record, identifies lookup-consuming mechanisms, recursively fetches the records for those mechanisms, and diffs the current state against the previous baseline. If the lookup count climbs from seven to nine, the script should trigger a high-severity alert in your ticketing system.

Nine is the absolute maximum threshold for comfort. Sitting at nine leaves a buffer of exactly one lookup for emergency changes or unannounced vendor modifications. Once you hit ten, you are operating without a net.

The Vendor Update Chain Reaction

Consider a realistic incident chain. An organization relies on Google Workspace for corporate mail, Salesforce for CRM, and a popular marketing automation tool. Their apex domain sits comfortably at seven lookups. Everything passes SPF alignment.

On a Tuesday night, the marketing vendor updates their infrastructure to support a new dedicated IP pool offering. They add two nested includes to their base SPF record. The next morning, the CRM vendor routes some backend notifications through a new AWS cluster, adding another include. The apex domain is now dynamically sitting at ten lookups.

Authentication-Results: mx.google.com; spf=permerror (google.com: domain of marketing@example.com uses a nested include that exceeds the maximum of 10 DNS lookups) smtp.mailfrom=marketing@example.com; dmarc=fail (p=REJECT sp=REJECT dis=NONE) header.from=example.com — Authentication-Results Header

A completely unrelated department triggers a targeted outbound campaign. The receiving MTA begins evaluating the SPF record from left to right. Because the CRM vendor is evaluated first in the text string, the MTA exhausts its ten-lookup budget before it even reaches the marketing vendor's mechanisms. The campaign emails drop entirely.

The marketing vendor's infrastructure is functioning perfectly, but the CRM vendor's silent update weaponized the lookup limit. Because DKIM was missing entirely from this specific campaign platform, DMARC failed on both axes. This blast radius is exactly why flat apex domains are a massive operational risk.

The Remediation Hierarchy

When the monitoring alerts fire, you need a pre-approved remediation path. Throwing all your IP addresses into a giant, unmaintainable string is a terrible idea. You must choose an architectural fix based on operational overhead, team maturity, and risk tolerance.

Subdomain Delegation

The cleanest and most scalable approach is removing third-party senders from the apex domain entirely. If marketing wants to send emails, they should send them from a dedicated subdomain. This physically isolates the lookup budget. The apex domain retains its pristine, low-lookup record for corporate mail, while the subdomain handles the chaos of vendor includes.

SPF Flattening

Flattening involves resolving all nested includes down to their raw IP addresses and publishing a massive list of ip4 and ip6 mechanisms. Because IP mechanisms do not count against the limit, you bypass the restriction entirely. The glaring operational danger here is that cloud IP spaces change constantly. If you flatten a record and do not aggressively sync it via automation, a vendor will rotate their IPs and your static flattened record will immediately cause hard fails.

SPF Macros

For highly advanced architectures, RFC 7208 defines macros. These allow the receiving MTA to perform dynamic DNS lookups based on variables like the sender's IP address or the local part of the email address. Macros are incredibly powerful for massive multitenant environments, but they require a sophisticated DNS management layer and are notoriously difficult for Tier 1 SOC analysts to debug when things go wrong.

The takeaway

You cannot control when your external vendors update their infrastructure, but you can absolutely control your visibility into those changes. Waiting for your bounce logs to tell you about an authentication collapse is an abdication of architectural responsibility.

Establish a strict quarterly audit cadence with your IT and marketing stakeholders to review exactly who is authorized to send mail. Back that policy up with daily automated checks. Use the continuous DNS alerting features in MailSleuth.AI to watch your tree for unannounced expansions, and fix the architecture before that tenth lookup takes your domain offline.

#email-forensics#spf#rfc-7208#dmarc#permerror#playbook
MailSleuth Research
Email Security Team

We dissect phishing campaigns and email infrastructure so you don't have to.