RFC 7208 SPF Lookup & Triple-Counter Workbench
include, a, mx, ptr, exists, redirect=v=spf1 ip4:192.0.2.0/24 include:_spf.workspace-mail.example include:mail.helpdesk.example include:spf.crm-cloud.example mx exists:%{ir}._spf.mta.acme-saas.example ~allinclude: lookup counts require live DoH or running the air-gapped CLI script below inside your VPC.RFC 7208 Diagnostics & Remediation
Mechanism 'exists:%{ir}._spf.mta.acme-saas.example' on billing.acme-saas.example uses runtime RFC 7208 §7 macro(s) (%{ir}). Counted +1 toward the 10-lookup budget without querying literal '%{...}' over DNS.
Evaluating billing.acme-saas.example required 13 DNS-querying mechanisms/modifiers (include, a, mx, ptr, exists, redirect), violating the strict RFC 7208 §4.6.4 ceiling of 10. Receivers abort with PermError and fail SPF alignment.
Remediation: Move marketing/transactional vendors onto dedicated subdomains (e.g. mail.example.com, billing.example.com), replace 'a'/'mx' with static 'ip4:'/'ip6:' CIDRs where owned, and prune unused ESP includes.
At least one mechanism resolved to NXDOMAIN or zero resource records. Exceeding 2 void lookups triggers RFC 7208 §4.6.4 PermError.
Recursive Lookup Tree
billing.acme-saas.exampleROOT TXT (0/10)Evaluated Mechanisms & Modifiers Breakdown
| Slot | Source Domain | Term | Target / Network | Status & Notes |
|---|---|---|---|---|
| 0 DNS | billing.acme-saas.example | ip4:192.0.2.0/24 | billing.acme-saas.example | OK 0 DNS lookups |
| #1/10 | billing.acme-saas.example | include:_spf.workspace-mail.example | _spf.workspace-mail.example | PASS-MATCH |
| #2/10 | _spf.workspace-mail.example | include:_netblocks1.workspace-mail.example | _netblocks1.workspace-mail.example | PASS-MATCH |
| 0 DNS | _netblocks1.workspace-mail.example | ip4:198.51.100.0/24 | _netblocks1.workspace-mail.example | PASS-MATCH Matched simulated IP 198.51.100.44 (pass) |
| 0 DNS | _netblocks1.workspace-mail.example | ~all | _netblocks1.workspace-mail.example | OK SoftFail catch-all (~all) |
| #3/10 | _spf.workspace-mail.example | include:_netblocks2.workspace-mail.example | _netblocks2.workspace-mail.example | OK |
| 0 DNS | _netblocks2.workspace-mail.example | ip6:2001:db8:10::/48 | _netblocks2.workspace-mail.example | OK 0 DNS lookups |
| 0 DNS | _netblocks2.workspace-mail.example | ~all | _netblocks2.workspace-mail.example | OK SoftFail catch-all (~all) |
| 0 DNS | _spf.workspace-mail.example | ~all | _spf.workspace-mail.example | OK SoftFail catch-all (~all) |
| #4/10 | billing.acme-saas.example | include:mail.helpdesk.example | mail.helpdesk.example | OK |
| #5/10 | mail.helpdesk.example | a:out1.helpdesk.example | out1.helpdesk.example | OK Resolved 1 address(es) |
| #6/10 | mail.helpdesk.example | a:out2.helpdesk.example | out2.helpdesk.example | OK Resolved 1 address(es) |
| #7/10 | mail.helpdesk.example | a:out3.helpdesk.example | out3.helpdesk.example | OK Resolved 1 address(es) |
| 0 DNS | mail.helpdesk.example | ~all | mail.helpdesk.example | OK SoftFail catch-all (~all) |
| #8/10 | billing.acme-saas.example | include:spf.crm-cloud.example | spf.crm-cloud.example | OK |
| #9/10 | spf.crm-cloud.example | a:relay1.crm-cloud.example | relay1.crm-cloud.example | OK Resolved 1 address(es) |
| #10/10 | spf.crm-cloud.example | a:relay2.crm-cloud.example | relay2.crm-cloud.example | OK Resolved 1 address(es) |
| #11/10 | spf.crm-cloud.example | a:decommissioned-host.crm-cloud.example | decommissioned-host.crm-cloud.example | VOID Void lookup (NXDOMAIN / 0 address records) |
| 0 DNS | spf.crm-cloud.example | ~all | spf.crm-cloud.example | OK SoftFail catch-all (~all) |
| #12/10 | billing.acme-saas.example | mx | billing.acme-saas.example | OK 2/10 per-MX host lookups |
| #13/10 | billing.acme-saas.example | exists:%{ir}._spf.mta.acme-saas.example | %{ir}._spf.mta.acme-saas.example | MACRO-UNEXPANDED Short-circuited earlier (pass) — skipped expanding exists:%{ir}._spf.mta.acme-saas.example |
| 0 DNS | billing.acme-saas.example | ~all | billing.acme-saas.example | OK SoftFail catch-all (~all) |
Air-Gapped Recursive CLI Diagnostics (dig & PowerShell)
# Air-gapped recursive SPF lookup counter (Bash + dig, option-injection & glob hardened)
( set -f; total=0;
spf_walk() { local d="$1" seen="$2" pad="$3" c=0;
[[ "$d" =~ ^[A-Za-z0-9._-]+$ && "$d" != -* && "$d" == *.* ]] || { printf "%s[rejected unsafe target: %s]\n" "$pad" "$d"; return; };
[[ " $seen " == *" $d "* ]] && { printf "%sLOOP:%s\n" "$pad" "$d"; return; };
local txt; txt=$(dig +short TXT -- "$d" | sed 's/" "//g; s/"//g' | grep -i '^v=spf1\([[:space:]]\|$\)' || true);
printf "%s%-34s -> %s\n" "$pad" "$d" "${txt:-<NO_SPF>}";
for tok in $txt; do local clean="${tok#[+~?-]}";
case "$clean" in
include:*) c=$((c+1)); total=$((total+1)); spf_walk "${clean#include:}" "$seen $d" " $pad" ;;
redirect=*) c=$((c+1)); total=$((total+1)); spf_walk "${clean#redirect=}" "$seen $d" " $pad" ;;
a|a:*|a/*|mx|mx:*|mx/*|ptr|ptr:*|exists:*) c=$((c+1)); total=$((total+1)) ;;
esac;
done; printf "%s [local DNS terms on %s: %d]\n" "$pad" "$d" "$c"; };
spf_walk 'billing.acme-saas.example' "" "";
printf "Total RFC 7208 DNS-querying mechanisms: %d/10 (%s)\n" "$total" "$([ "$total" -le 10 ] && echo OK || echo PERMERROR)"; )# Air-gapped recursive SPF lookup inspector (PowerShell Resolve-DnsName, injection hardened)
$script:SpfTotal = 0
function Show-SpfTree([string]$Domain, [string[]]$Seen = @(), [string]$Pad = '') {
if ($Domain -notmatch '^[A-Za-z0-9._-]+$' -or $Domain.StartsWith('-') -or -not $Domain.Contains('.')) { Write-Warning ($Pad + "Rejected unsafe target: $Domain"); return }
if ($Seen -contains $Domain) { Write-Warning ($Pad + "Loop detected: $Domain"); return }
$txts = @(Resolve-DnsName -Name $Domain -Type TXT -ErrorAction SilentlyContinue | Where-Object { $_.Type -eq 'TXT' } | ForEach-Object { ($_.Strings -join '') } | Where-Object { $_ -match '^v=spf1(\s|$)' })
Write-Host ("{0}{1} -> {2}" -f $Pad, $Domain, ($(if ($txts.Count) { $txts -join ' | ' } else { '<NO_SPF>' })))
foreach ($t in ($txts -split '\s+')) {
$clean = $t -replace '^[+~?-]',''
if ($clean -match '^include:(.+)$') { $script:SpfTotal++; Show-SpfTree $Matches[1] ($Seen + $Domain) ($Pad + ' ') }
elseif ($clean -match '^redirect=(.+)$') { $script:SpfTotal++; Show-SpfTree $Matches[1] ($Seen + $Domain) ($Pad + ' ') }
elseif ($clean -match '^(a([:/].+)?|mx([:/].+)?|ptr(:.*)?|exists:.+)$') { $script:SpfTotal++ }
}
}; Show-SpfTree 'billing.acme-saas.example'; Write-Host ("Total RFC 7208 DNS-querying mechanisms: {0}/10" -f $script:SpfTotal)RFC 7208 Protocol Verification Rules
| Specification Rule | Ceiling / Behavior | Receiver Verdict on Violation |
|---|---|---|
| RFC 7208 §4.6.4 Global DNS Terms | Max 10 total across include, a, mx, ptr, exists, and redirect= (root TXT, ip4, ip6, all, exp= are exempt). | PermError |
| RFC 7208 §4.6.4 Per-MX / Per-PTR | Max 10 address (A/AAAA) lookups per individual mx or ptr mechanism (ptr truncates after 10 validated names). | PermError (MX) |
| RFC 7208 §4.6.4 Void Lookups | Max 2 DNS queries returning NXDOMAIN (RCODE 3) or NOERROR (RCODE 0) with 0 answers (Null MX 0 . excluded). | PermError |
| RFC 7208 §4.5 Single Record Rule | A domain MUST NOT publish more than one TXT RR beginning with v=spf1. | PermError |
| RFC 7208 §3.3 Multi-String TXT | Adjacent quoted strings inside a single TXT RR (>255 bytes) are concatenated directly without inserting spaces; CNAME (type=5) hops are filtered first. | Concatenated |
SPF Engineering Failure Modes & Remediation Guides
Email Authentication & Delivery Infrastructure
Dedicated transactional delivery streams with custom Return-Path subdomain SPF alignment and 2048-bit DKIM signing.
High-volume API mail relay with automated DKIM key rotation, subdomain isolation, and structured bounce telemetry.
Automated XML aggregate report ingestion and dynamic SPF flattening to stay under the 10-lookup ceiling without stale netblocks.