In SPF, how does the include mechanism differ from the redirect= modifier, and when should a domain use each?
answer
- a question versus a handover
- only pass makes include match
- redirect runs when nothing matched
- all silences redirect
- one ADMD or across boundaries
basics
~20 sAn SPF include asks another domain's record about the client and matches only on pass; otherwise the parent's own terms and ending decide. redirect= runs only when nothing matched and no all exists, and its target's result becomes the answer.
solid answer
~40 s`include:` is a mechanism. It evaluates the named domain's record with the same client address and sender, and matches only if that record returns `pass`; `fail`, `softfail` and `neutral` mean not-match, so evaluation continues in the parent, and the parent's own `all` still sets the policy. A `temperror` or `permerror` is returned as is, and a target with no record gives `permerror`. `redirect=` is a modifier: it is used only when no mechanism matched, is ignored if the record contains `all` anywhere, and makes the target's result the result. Use `include` to authorise another organisation's senders inside your own policy; use `redirect=` when several domains you run should share one record, policy and all.
code
dns · 7 lines; include: the CRM's verdict only matters when it is pass; example.com keeps its own -all
example.com. TXT "v=spf1 ip4:192.0.2.25 include:_spf.crm.example.net -all"
; redirect: two domains run by the same team share one record and its policy
billing.example.com. TXT "v=spf1 redirect=_spf.example.com"
support.example.com. TXT "v=spf1 redirect=_spf.example.com"
_spf.example.com. TXT "v=spf1 ip4:192.0.2.25 -all"go deeper
Recall that include asks another record and only a pass counts, while redirect hands over the whole decision when nothing else matched.
Explain the include result table, why a target with no record is permerror, and the two conditions under which a redirect is ever used.
Spot dead redirects next to an all, includes of records that no longer exist, and redirects pointed at another organisation's domain.
Use redirect to give a family of owned domains one policy source, and decide who owns that shared record and its change review.
## include: ask another record a yes-or-no question `include:` is a **mechanism**, so it sits in the left-to-right list like any other. When it is reached, the checker runs a full, recursive SPF evaluation of the named domain, keeping the same client address and the same sender. RFC 7208 section 5.2 then maps the inner result to the outer mechanism: | Result of the included record | Effect on the `include` mechanism | |---|---| | `pass` | **match**: the include's own qualifier gives the result | | `fail` | not match: evaluation continues in the parent | | `softfail` | not match | | `neutral` | not match | | `temperror` | returns `temperror` | | `permerror` | returns `permerror` | | `none` (no record) | returns `permerror` | The RFC admits the name was poorly chosen and suggests "if-match" would have been better. Nothing is literally copied in: only the inner **result** is used. A `-all` inside the included record does not end the parent's evaluation and does not make the parent fail; it only means "not a match here". The qualifier written on the include applies when it matches: `include:` and `+include:` give `pass`, `-include:` gives `fail`, `?include:` gives `neutral`. Because the parent keeps its own ending, **the policy for everyone else stays yours**. That is why `include` is meant for crossing administrative boundaries: authorising a CRM's or a ticketing system's senders while your record still ends in your own `-all` or `~all`. ## A worked trace Take `example.com` publishing `v=spf1 ip4:192.0.2.25 include:_spf.crm.example.net -all`: - **A CRM sending host.** `ip4` does not match; the CRM's record returns `pass`, so the include matches and the result is `pass`. - **An unknown host.** `ip4` does not match; the CRM's record reaches its own `-all` and returns `fail`, which is only a not-match here; the parent's `-all` then gives `fail`. - **The CRM retires its record.** The include now returns `permerror` for every client that reaches it, while the gateway at 192.0.2.25 still passes because `ip4` matches first. Order decides who is exposed to a broken target. ## redirect=: hand the whole decision over `redirect=` is a **modifier**. It never matches; it is consulted only after the mechanisms are done (section 6.1): 1. If any mechanism matched, `redirect=` is never used. 2. If the record contains an `all` mechanism anywhere, `redirect=` MUST be ignored, whatever the order of the terms. 3. Otherwise the target domain is evaluated with the same client address and sender, and **its result becomes this record's result**, including its own ending. 4. If the target publishes no SPF record, or the name is malformed, the result is `permerror`, not `none`. It SHOULD be the last term, may appear only once, and the target may itself redirect again. The typical use is several domains run by one team sharing one record: ```dns billing.example.com. TXT "v=spf1 redirect=_spf.example.com" support.example.com. TXT "v=spf1 redirect=_spf.example.com" _spf.example.com. TXT "v=spf1 ip4:192.0.2.25 include:_spf.tickets.example.org -all" ``` A change to `_spf.example.com` now updates the hosts and the policy of every domain pointing at it. ## The two side by side | Question | `include:` | `redirect=` | |---|---|---| | Kind of term | mechanism | modifier | | When is it consulted? | when evaluation reaches it | only if nothing matched and no `all` exists | | What decides unlisted hosts? | the parent's own `all` | the target's record | | Target has no record | `permerror` | `permerror` | | Whose `exp=` text is used? | the parent's; the target's `exp=` MUST NOT be used | the target's; the original's MUST NOT be used | | Intended for | another organisation's senders | domains under one administration | ## Choosing between them - **Outside senders inside your policy**: `include:` the operator's published record, keeping your own ending. - **Many domains, one mail system you run**: `redirect=` to a shared record. Section 5.2 even prefers `redirect=` (or a plain `mx:`) to `include:` within one administrative domain. - **Avoid `redirect=` to a domain someone else runs.** The sender stays the same in the redirected evaluation, so another organisation's record, especially one using local-part macros, is not written for your addresses; section 6.1 notes that `include` is generally more appropriate. - **Do not combine `redirect=` with `all`**: the redirect is dead text. Both terms trigger further DNS queries; how they count against the record's lookup budget is covered with the lookup limit.
- Why does an included record ending in -all not make the parent return fail?Because `include` only uses the inner result as a yes or no. A `fail` from the included record maps to not-match, and the parent carries on with its next term and eventually its own `all`. RFC 7208 section 5.2 says the name was poorly chosen for exactly this reason: nothing from the included record is copied into the parent.
- What happens to redirect= in v=spf1 mx redirect=_spf.example.com ~all?It is ignored. RFC 7208 sections 5.1 and 6.1 say a `redirect=` MUST be ignored whenever the record contains an `all` mechanism, regardless of order, so an unlisted host reaches `~all` and gets `softfail`. Either drop the `~all` or drop the redirect.
- Which explanation text does a receiver use when an include or a redirect is involved?With `include`, the target's `exp=` MUST NOT be used, because the explanation should come from the domain whose policy is being applied. With `redirect=`, the original record's `exp=` MUST NOT be used and the redirected record's explanation takes priority, since redirect consolidates policy inside one administration.
include is phoning a partner's front desk to ask whether a visitor is on their list: a yes lets the visitor in, a no just means you keep checking your own list and your own door rule. redirect is a sign, used only when your list has no entry and no catch-all rule, that sends the visitor to another door whose rule is final.
- include copies the other domain's mechanisms into your record.
- An included record ending in -all makes the whole check fail.
- redirect= is evaluated wherever it appears, like a mechanism.
- A redirect still applies when the record also ends in ~all.
- An include whose target has no SPF record is simply skipped.
- redirect= is the right way to authorise an outside sending service.