The exists mechanism can make SPF policy depend on a DNS name assembled from the message's SMTP inputs. This enables fine-grained policies, but makes the visible TXT record a poor description of the actual query or its privacy implications.
[ SPF ]
SPF exists and macros: inspect the query that will actually be made
Expand an SPF macro with concrete inputs and inspect the DNS question before trusting the result.
By the EmailAuth research team · 4 min read
[ Key points ]
- Exists tests for an A answer, not an IP address match.
- Expand actual inputs and identify who receives the query.
- Separate no-match, DNS error and answering-service changes.
On this page
Do not approve a macro policy because it looks familiar. Expand it for representative inputs, identify the DNS operator receiving the query and establish what a positive answer means.
Understand the exists test
exists expands its domain specification and performs an A-record query. It does this even for an IPv6 SMTP connection. If any A record is returned, the mechanism matches; the returned address is not compared with the connecting IP. An AAAA-only answer does not satisfy that A lookup. See RFC 7208 section 5.7.
Under the normal + qualifier, a match produces pass. A missing name or empty A answer does not match; temporary DNS errors must be handled according to SPF's error rules, not silently converted into an authorisation decision.
Expand a synthetic query by hand
Assume a valid single record, successful DNS answers and no exceeded limits. Consider v=spf1 exists:%{ir}._permit.%{d} -all at example.com for an IPv4 connection from 192.0.2.9. The i macro represents the input address. The r transformer reverses the parts, and d is the current evaluation domain. The expanded query is 9.2.0.192._permit.example.com.
If that name returns an A record, such as the illustrative value 127.0.0.2, exists matches even though that address differs from 192.0.2.9. If no A record exists and no error prevents evaluation, the mechanism does not match and the policy reaches -all.
The A value here is only a positive-answer marker. The security meaning comes from control of the queried DNS namespace and its rule for returning answers. A wildcard that answers every possible query can unintentionally authorise every input that reaches it.
Distinguish macro identities
The d macro is the current domain being evaluated. The o macro comes from the sender's domain, while l refers to the sender's local part. Include or redirect can change evaluation context, so do not assume d and o remain interchangeable inside a dependency.
Macro transformers can select parts, reverse them and change delimiters. IPv6 expansion is not the same dotted-decimal string as IPv4. Use RFC 7208 §7.2 and RFC 7208 §7.3 and an implementation trace for the actual form rather than guessing from an IPv4 example.
Malformed expanded names and overlong labels require particular care. Under RFC 7208 §4.8, the specification notes implementation differences for some invalid domain-spec results. Keep fixtures within valid DNS syntax and test the evaluator used in your environment; do not claim all receivers handle every malformed input identically.
Review privacy and availability
As described in RFC 7208 §11.6, a macro using local-part or full-sender data can expose message-related identity information through DNS queries to the namespace operator and relevant DNS infrastructure. Review the minimum data required before using such a design, especially with a third-party policy service.
The policy also depends on the availability and integrity of the answering DNS system. Record who operates it, how positive answers are generated, how changes are reviewed and what happens during outages. Under RFC 7208 §4.6.4, DNS-query-causing terms and void lookups remain subject to SPF limits; exists does not provide unlimited external policy calls.
Build useful acceptance fixtures
Test an authorised input, an unauthorised input, IPv6 if used, a DNS outage and a valid but unusual sender local part if it affects the query. Save the exact expanded name, query type, DNS answer and terminal SPF result for each fixture.
Also test wildcard behaviour and changes to the target zone. A record can remain syntactically correct while the answering service changes its permission logic. Close the review only when the DNS decision can be explained and reproduced.
The practical takeaway
For exists, the expanded DNS question is the policy evidence. Review its inputs, answer semantics, privacy exposure and error behaviour before relying on the resulting pass.
Record the decision and its limits
For the same 192.0.2.9 input, distinguish three fixtures: A=127.0.0.2 gives a match and default-qualified pass; a successful empty A answer gives no match and reaches -all; a temporary DNS error ends evaluation as temperror rather than fail. The error rule is RFC 7208 §5 and RFC 7208 §4.6.2. These are expected outcomes, not observed DNS or evaluator runs.
[ Takeaway ]
Exists tests for an A answer, not an IP address match. Expand actual inputs and identify who receives the query. Separate no-match, DNS error and answering-service changes.
[ By role ]
What this means for you
Choose your role for practical next steps.
IT / Mail Admin
Save expanded queries.
A macro string alone cannot show what a real evaluation queried.
Next steps
- Test IPv4 and IPv6 inputs.
- Inspect wildcard answers.
- Retain error-path fixtures.
CISO / SecOps
Review DNS data exposure.
Macro-derived names may carry sender information outside the mail system.
Next steps
- Minimise identity data in queries.
- Review third-party recipients.
- Control changes to positive-answer logic.
Founder / Non-technical
Ask who runs the decision service.
A short DNS expression may hide an operational dependency that needs ownership and continuity planning.
Next steps
- Identify the DNS operator.
- Understand outage impact.
- Require a reproducible decision example.
[ FAQs ]
Frequently asked questions
Does exists compare the returned A address with the sender IP?
No. Any returned A record makes the mechanism match.
Does exists query AAAA for IPv6 senders?
No. It performs an A query even for an IPv6 connection.
What does %{ir} do in the IPv4 example?
It uses the connecting IP and reverses its dotted components, producing 9.2.0.192 for 192.0.2.9.
Are %{d} and %{o} always identical?
No. d is the current evaluation domain; o is the sender domain. Recursive evaluation can make the distinction important.
Can a wildcard accidentally authorise everyone?
Yes. If it yields A answers for all expanded queries, exists can match all those inputs.
Can macros expose mailbox information?
Yes. Sender or local-part macros can place that information in DNS queries. Review necessity and recipients of the data.
Does exists avoid SPF lookup limits?
No. It is a counted DNS-query-causing term, and void-lookup behaviour also matters.
What evidence makes a macro policy reviewable?
Concrete input values, the exact expanded query, DNS answer, SPF outcome and ownership of the answering namespace.
[ Sources ]
Sources
- RFC 7208
Sections §4.8 · §4.6.2 · §4.6.4 · §5.7 · §7.1 · §7.2 · §7.3 · §11.6 · §2.4 · §4.1
[ Glossary ]
Glossary
- SPF exists mechanism
- A macro-expanded A query matches when it returns any A record, including for an IPv6 connection.
Enterprise provenance
Why top financial institutions and governments retired their email security dashboards.
Traditional email authentication platforms sell you a dashboard and ask your engineers to do the labour. In high-stakes environments, manual oversight means delayed enforcement, configuration drift and unmonitored shadow domains.
EmailAuth is the agentic email provenance platform. Our agents enforce p=reject, keep third-party senders aligned and move your domains to full RFC 9989 compliance, the new DMARC standard, with human-in-the-loop auditability.
SaaS · Dedicated tenancy · Air-gapped on-prem · BYOK encryption