Skip to content

fix(spf): expand %{d} macro to the domain currently being evaluated - #126

Merged
andris9 merged 1 commit into
masterfrom
fix/spf-macro-domain
Aug 19, 2026
Merged

fix(spf): expand %{d} macro to the domain currently being evaluated#126
andris9 merged 1 commit into
masterfrom
fix/spf-macro-domain

Conversation

@andris9

@andris9 andris9 commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

RFC 7208 defines d as the current <domain> of check_host(), which changes on every include:/redirect= recursion, while o stays on the sender domain (sections 5.2, 6.1, 7.2, 7.3). mailauth expanded %{d} as an alias of %{o}, so macros inside nested SPF records were built from the wrong domain, producing bogus DNS lookups and spurious permerrors, as reported in #125.

Changes:

  • lib/spf/macro.js: d now expands from a new optional values.domain (falling back to the sender domain, which is the correct top-level value), o and p keep using the sender domain
  • lib/spf/spf-verify.js: each spfVerify() recursion level passes its own domain to every macro expansion site; the bare ptr mechanism now uses the current domain directly
  • Regression tests: nested-include %{d} expansion mirroring the reported chain (asserting the wrong hostname is never queried), %{d} after redirect=, %{o} staying on the sender in nested includes, and macro unit tests. All three %{d} tests fail on master and pass with this fix; the full suite (756 tests, including the RFC 7208 test suite) passes.

Previously %{d} always expanded to the sender domain, behaving exactly
like %{o}. Inside included or redirected SPF records the macro must
expand to the domain whose record is currently being evaluated by
check_host() (RFC 7208 sections 5.2, 6.1 and 7.2), so nested records
using %{d}, and the bare ptr mechanism, built DNS lookups against the
wrong domain and caused spurious permerrors.

Refs #125

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GLXjjgoCN1dJsRqc9R98gu
@andris9
andris9 merged commit 53c4522 into master Aug 19, 2026
11 checks passed
@andris9
andris9 deleted the fix/spf-macro-domain branch August 19, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant