kilabit.info
Build | sr.ht | GitHub | Twitter

This document provide note and summary of RFC 7208, Sender Policy Framework (SPF) for Authorizing Use of Domains in Email, Version 1. The content of this document are merged with errata that are reported before 2019-04-04.

1. Introduction

This document defines a protocol by which ADministrative Management Domains (ADMD) can authorize hosts to use their domain names in the "MAIL FROM" or "HELO" identities. Compliant ADMDs publish Sender Policy Framework (SPF) records in the DNS specifying which hosts are permitted to use their names, and compliant mail receivers use the published SPF records to test the authorization of sending Mail Transfer Agents (MTAs) using a given "HELO" or "MAIL FROM" identity during a mail transaction.

2. Operational Overview

2.1. Publishing Authorization

An SPF-compliant domain publishes valid SPF records to authorize the use of the relevant domain names in the "HELO" and "MAIL FROM" identities by the MTAs specified therein.

SPF results can be used to make both positive (source is authorized) and negative (source is not authorized) determinations. If ADMDs choose to publish SPF records and want to support receivers making negative authorization determinations, it is necessary for them to publish records that end in "-all", or redirect to other records that do; otherwise, no definitive determination of authorization can be made.

When changing SPF records, care has to be taken to ensure that there is a transition period so that the old policy remains valid until all legitimate email can reasonably expect to have been checked.

2.2. Checking Authorization

A mail receiver can perform a set of SPF checks for each mail message it receives. Typically, such checks are done by a receiving MTA, but can be performed elsewhere in the mail processing chain so long as the required information is available and reliable.

Without explicit approval of the publishing ADMD, checking other identities against SPF version 1 records is NOT RECOMMENDED because there are cases that are known to give incorrect results. For example, almost all mailing lists rewrite the "MAIL FROM" identity, but some do not change any other identities in the message. Documents that define other identities will have to define the method for explicit approval.

To make the test, the mail receiver MUST evaluate the check_host() function.

Although invalid, malformed, or non-existent domains cause SPF checks to return "none" because no SPF record can be found, it has long been the policy of many MTAs to reject email from such domains, especially in the case of invalid "MAIL FROM". Rejecting email will prevent one method of circumventing of SPF records.

Implementations have to take care to correctly extract the <domain> from the data given with the SMTP MAIL FROM command as many MTAs will still accept such things as source routes, the %-hack (see [RFC1123]), and bang paths (see [RFC1983]). These archaic features have been maliciously used to bypass security systems.

2.3. The "HELO" Identity

It is RECOMMENDED that SPF verifiers not only check the "MAIL FROM" identity but also separately check the "HELO" identity by applying the check_host() function (Section 4) to the "HELO" identity as the <sender>. If a conclusive determination about the message can be made based on a check of "HELO", then the use of DNS resources to process the typically more complex "MAIL FROM" can be avoided. Additionally, since SPF records published for "HELO" identities refer to a single host, when available, they are a very reliable source of host authorization status. Checking "HELO" before "MAIL FROM" is the RECOMMENDED sequence if both are checked.

This SPF check can only be performed when the "HELO" string is a valid, multi-label domain name.

2.4. The "MAIL FROM" Identity

SPF verifiers MUST check the "MAIL FROM" identity if a "HELO" check either has not been performed or has not reached a definitive policy result by applying the check_host() function to the "MAIL FROM" identity as the <sender>.

If the reverse-path is null, this document defines the "MAIL FROM" identity to be the mailbox composed of the local-part "postmaster" and the "HELO" identity (which might or might not have been checked separately before).

2.5. Location of Checks

The authorization check is performed during the SMTP transaction at the time of the MAIL command, and uses the MAIL FROM value and the client IP address. Performing the check at later times or with other input can cause problems such as the following:

  • It might be difficult to accurately extract the required information from potentially deceptive headers.

  • Legitimate email might fail the authorization check because the sender’s policy has since changed.

2.6. Results of Evaluation

Moved to section 4.2.

3. SPF Records

The SPF record is expressed as a single string of text found in the RDATA of a single DNS TXT resource record; multiple SPF records are not permitted for the same owner name.

3.1. DNS Resource Record

SPF records MUST be published as a DNS TXT (type 16) Resource Record (RR) only. The character content of the record is encoded as [US-ASCII].

3.2. Multiple DNS Records

A domain name MUST NOT have multiple records that would cause an authorization check to select more than one record.

3.3. Multiple Strings in a Single DNS Record

If a published record contains multiple character-strings, then the record MUST be treated as if those strings are concatenated together without adding spaces. For example:

IN TXT "v=spf1 .... first" "second string..."

is equivalent to:

IN TXT "v=spf1 .... firstsecond string..."

3.4. Record Size

If the size of the DNS message, the combined length of the DNS name and the text of all the records of a given type is under 450 octets, then DNS answers ought to fit in UDP packets. Records that are too long to fit in a single UDP packet could be silently ignored by SPF verifiers due to firewall and other issues that interfere with the operation of DNS over TCP or using EDNS0.

Note that when computing the sizes for replies to queries of the TXT format, one has to take into account any other TXT records published at the domain name. Similarly, the sizes for replies to all queries related to SPF have to be evaluated to fit in a single 512-octet UDP packet.

3.5. Wildcard Records

Use of wildcard records for publishing is discouraged, and care has to be taken if they are used.

SPF records have to be listed twice for every name within the zone: once for the name, and once with a wildcard to cover the tree under the name, in order to cover all domains in use in outgoing mail.

4. The check_host() Function

The check_host() function fetches SPF records, parses them, and evaluates them to determine whether a particular host is or is not permitted to send mail with a given identity. Receiving ADMDs that perform this check MUST correctly evaluate the check_host() function as described here.

4.1. Arguments

The check_host() function takes these arguments:

  • <ip>: the IP address of the SMTP client that is emitting the mail, either IPv4 or IPv6.

  • <domain>: the domain that provides the sought-after authorization information; initially, the domain portion of the "MAIL FROM" or "HELO" identity.

  • <sender>: the "MAIL FROM" or "HELO" identity.

4.2. Results

This section enumerates and briefly defines the possible outputs of check_host() function.

  • "none": means either,

    • no syntactically valid DNS domain name was extracted from the SMTP session that could be used as the one to be authorized, or

    • no SPF records were retrieved from the DNS.

  • "neutral": means the ADMD has explicitly stated that it is not asserting whether the IP address is authorized.

  • "pass": an explicit statement that the client is authorized to inject mail with the given identity.

  • "fail": an explicit statement that the client is not authorized to use the domain in the given identity.

  • "softfail": a weak statement by the publishing ADMD that the host is probably not authorized. It has not published a stronger, more definitive policy that results in a "fail".

  • "temperror": the SPF verifier encountered a transient (generally DNS) error while performing the check. A later retry may succeed without further DNS operator action.

  • "permerror": the domain’s published records could not be correctly interpreted. This signals an error condition that definitely requires DNS operator intervention to be resolved.

4.3. Initial Processing

If the <domain> is malformed (e.g., label longer than 63 characters, zero-length label not at the end, etc.) or is not a multi-label domain name, or if the DNS lookup returns "Name Error" (RCODE 3, also known as "NXDOMAIN" [RFC2308]), check_host() immediately returns the result "none".

If the <sender> has no local-part, substitute the string "postmaster" for the local-part.

4.4. Record Lookup

A DNS query needs to be made for the <domain> name, querying for type TXT only.

If the DNS lookup returns a server failure (RCODE 2) or some other error (RCODE other than 0 or 3), or if the lookup times out, then check_host() terminates immediately with the result "temperror".

4.5. Selecting Records

Records begin with a version section:

record   = version terms *SP
version  = "v=spf1"

If the resultant record set includes no records, check_host() produces the "none" result. If the resultant record set includes more than one record, check_host() produces the "permerror" result.

4.6. Record Evaluation

The check_host() function parses and interprets the SPF record to find a result for the current test. if there are any syntax errors anywhere in the record, check_host() returns immediately with the result "permerror", without further interpretation or evaluation.

4.6.1. Term Evaluation

There are two types of terms: mechanisms and modifiers.

terms            = *( 1*SP ( directive / modifier ) )

directive        = [ qualifier ] mechanism
qualifier        = "+" / "-" / "?" / "~"
mechanism        = ( all / include
                   / a / mx / ptr / ip4 / ip6 / exists )
modifier         = redirect / explanation / unknown-modifier
unknown-modifier = name "=" macro-string
                 ; where name is not any known modifier

name             = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." )

Most mechanisms allow a ":" or "/" character after the name.

Modifiers always contain an equals ('=') character immediately after the name, and before any ":" or "/" characters that might be part of the macro-string.

Terms that do not contain any of "=", ":", or "/" are mechanisms.

Mechanism and modifier names are case-insensitive.

4.6.2. Mechanisms

Each mechanism is considered in turn from left to right. If there are no more mechanisms, the result is the default result.

When a mechanism is evaluated, one of three things can happen: it can match, not match, or return an exception.

If it matches, processing ends and the qualifier value is returned as the result of that record. If it does not match, processing continues with the next mechanism. If it returns an exception, mechanism processing ends and the exception value is returned.

The possible qualifiers, and the results they cause check_host() to return, are as follows:

"+" pass
"-" fail
"~" softfail
"?" neutral

The qualifier is optional and defaults to "+".

When a mechanism matches and the qualifier is "-", then a "fail" result is returned.

4.6.3. Modifiers

Modifiers are not mechanisms. They do not return match or not-match. Instead, they provide additional information. Although modifiers do not directly affect the evaluation of the record, the "redirect" modifier has an effect after all the mechanisms have been evaluated.

4.6.4. DNS Lookup Limits

The following terms cause DNS queries: the "include", "a", "mx", "ptr", and "exists" mechanisms, and the "redirect" modifier.

SPF implementations MUST limit the total number of those terms to 10 during SPF evaluation, to avoid unreasonable load on the DNS. If this limit is exceeded, the implementation MUST return "permerror".

The other terms — the "all", "ip4", and "ip6" mechanisms, and the "exp" modifier — do not cause DNS queries at the time of SPF evaluation (the "exp" modifier only causes a lookup at a later time), and their use is not subject to this limit.

When evaluating the "mx" mechanism, the number of "MX" resource records queried is included in the overall limit of 10 mechanisms/modifiers that cause DNS lookups as described above. In addition to that limit, the evaluation of each "MX" record MUST NOT result in querying more than 10 address records — either "A" or "AAAA" resource records. If this limit is exceeded, the "mx" mechanism MUST produce a "permerror" result.

When evaluating the "ptr" mechanism or the %{p} macro, the number of "PTR" resource records queried is included in the overall limit of 10 mechanisms/modifiers that cause DNS lookups as described above. In addition to that limit, the evaluation of each "PTR" record MUST NOT result in querying more than 10 address records — either "A" or "AAAA" resource records. If this limit is exceeded, all records other than the first 10 MUST be ignored.

The check_host() elapsed time SHOULD have limited to least 20 seconds. If such a limit is exceeded, the result of authorization SHOULD be "temperror".

There may be cases where it is useful to limit the number of "terms" for which DNS queries return either a positive answer (RCODE 0) with an answer count of 0, or a "Name Error" (RCODE 3) answer. These are sometimes collectively referred to as "void lookups". SPF implementations SHOULD limit "void lookups" to two. An implementation MAY choose to make such a limit configurable. In this case, a default of two is RECOMMENDED. Exceeding the limit produces a "permerror" result.

4.7. Default Result

If none of the mechanisms match and there is no "redirect" modifier, then the check_host() returns a result of "neutral", just as if "?all" were specified as the last directive.

If there is a "redirect" modifier, check_host() proceeds as defined in Section 6.1.

It is better to use either a "redirect" modifier or an "all" mechanism to explicitly terminate processing. For example:

v=spf1 +mx -all

or

v=spf1 +mx redirect=_spf.example.com

4.8. Domain Specification

The <domain-spec> string is subject to macro expansion (see Section 7). The resulting string is the common presentation form of a fully qualified DNS name: a series of labels separated by periods. This domain is called the <target-name> in the rest of this document.

For several mechanisms, the <domain-spec> is optional. If it is not provided, the <domain> from the check_host() arguments (see Section 4.1) is used as the <target-name>. "domain" and <domain-spec> are syntactically identical after macro expansion. "domain" is an input value for check_host(), while <domain-spec> is computed by check_host().

The result of evaluating check_host() with a syntactically invalid domain is undefined. Examples include names with empty labels, such as "foo..example.com", and labels that are longer than 63 characters. Some implementations choose to treat such errors as not-match and therefore ignore such names, while others return a "permerror" exception.

5. Mechanism Definitions

This section defines two types of mechanisms: basic language framework mechanisms and designated sender mechanisms.

Basic mechanisms contribute to the language framework. They do not specify a particular type of authorization scheme. The basic mechanisms are as follows:

all
include

Designated sender mechanisms are used to identify a set of <ip> addresses as being permitted or not permitted to use the <domain> for sending mail. The designated sender mechanisms are as follows:

a
mx
ptr (do not use)
ip4
ip6
exists

The following conventions apply to all mechanisms that perform a comparison between <ip> and an IP address at any point:

If no CIDR prefix length is given in the directive, then <ip> and the IP address are compared for equality.

If a CIDR prefix length is specified, then only the specified number of high-order bits of <ip> and the IP address are compared for equality.

When any mechanism fetches host addresses to compare with <ip>, when <ip> is an IPv4, "A" records are fetched; when <ip> is an IPv6 address, "AAAA" records are fetched. SPF implementations on IPv6 servers need to handle both "AAAA" and "A" records, for clients on IPv4-mapped IPv6 addresses [RFC4291]. IPv4 <ip> addresses are only listed in an SPF record using the "ip4" mechanism.

Several mechanisms rely on information fetched from the DNS. For these DNS queries, except where noted, if the DNS server returns an error (RCODE other than 0 or 3) or the query times out, the mechanism stops and the topmost check_host() returns "temperror". If the server returns "Name Error" (RCODE 3), then evaluation of the mechanism continues as if the server returned no error (RCODE 0) and zero answer records.

5.1. "all"

all = "all"

The "all" mechanism is a test that always matches. It is used as the rightmost mechanism in a record to provide an explicit default. For example:

v=spf1 a mx -all

Mechanisms after "all" will never be tested and MUST be ignored.

Any "redirect" modifier MUST be ignored when there is an "all" mechanism in the record, regardless of the relative ordering of the terms.

5.2. "include"

include = "include"  ":" domain-spec

The "include" mechanism triggers a recursive evaluation of check_host().

  1. The <domain-spec> is expanded as per section 7.

  2. check_host() is evaluated with the resulting string as the <domain>. The <ip> and <sender> arguments remain the same as in the current evaluation of check_host().

  3. The recursive evaluation returns match, not-match, or an error.

  4. If it returns match, then the appropriate result for the "include" mechanism is used (e.g., "include" or "+include" produces a "pass" result and "-include" produces "fail").

  5. If it returns not-match or an error, the parent check_host() resumes processing as per the table below, with the previous value of <domain> restored.

The "include" mechanism makes it possible for one domain to designate multiple administratively independent domains. For example, a vanity domain "example.net" might send mail using the servers of administratively independent domains "example.com" and "example.org".

Example.net could say

IN TXT "v=spf1 include:example.com include:example.org -all"

This would direct check_host() to, in effect, check the records of "example.com" and "example.org" for a "pass" result. Only if the host were not permitted for either of those domains would the result be "fail".

Whether this mechanism matches, does not match, or returns an exception depends on the result of the recursive evaluation of check_host():

+-------------------------------------+------------------------------------+
| A recursive check_host() result of: | Causes the "include" mechanism to: |
+-------------------------------------+------------------------------------+
| pass                                | match                              |
| fail                                | not match                          |
| softfail                            | not match                          |
| neutral                             | not match                          |
| temperror                           | return temperror                   |
| permerror                           | return permerror                   |
| none                                | return permerror                   |
+-------------------------------------+------------------------------------+

The "include" mechanism is intended for crossing administrative boundaries.

When remaining within one administrative authority, "include" is usually not the best choice. For example, if example.com and example.org were managed by the same entity, and if the permitted set of hosts for both domains was "mx:example.com", it would be possible for example.org to specify "include:example.com", but it would be preferable to specify "redirect=example.com" or even "mx:example.com".

The "redirect" modifier is more suitable for consolidating both authorizations and policy into a common set to be shared within an ADMD. Redirect is much more like a common code element to be shared among records in a single ADMD. It is possible to control both authorized hosts and policy for an arbitrary number of domains from a single record.

5.3. "a"

a = "a" [ ":" domain-spec ] [ dual-cidr-length ]

This mechanism matches if <ip> is one of the <target-name>'s IP addresses. For clarity, this means the "a" mechanism also matches AAAA records.

An address lookup is done on the <target-name> using the type of lookup (A or AAAA) appropriate for the connection type (IPv4 or IPv6). The <ip> is compared to the returned address(es). If any address matches, the mechanism matches.

5.4. "mx"

This mechanism matches if <ip> is one of the MX hosts for a domain name.

mx               = "mx"     [ ":" domain-spec ] [ dual-cidr-length ]
  • check_host() first performs an MX lookup on the <target-name>.

    • To prevent denial-of-service (DoS) attacks, the processing limits defined in Section 4.6.4 MUST be followed.

    • If the MX lookup limit is exceeded, then "permerror" is returned and the evaluation is terminated.

  • Then it performs an address lookup on each MX name returned.

  • The <ip> is compared to each returned IP address.

  • If any address matches, the mechanism matches.

  • If the <target-name> has no MX record, check_host() MUST NOT apply the implicit MX rules of [RFC5321] by querying for an A or AAAA record for the same name.

5.5. "ptr" (do not use)

This mechanism tests whether the DNS reverse-mapping for <ip> exists and correctly points to a domain name within a particular domain. This mechanism SHOULD NOT be published.

The <ip>'s name is looked up using this procedure:

  • Perform a DNS reverse-mapping for <ip>: Look up the corresponding PTR record in "in-addr.arpa." if the address is an IPv4 address and in "ip6.arpa." if it is an IPv6 address.

  • Check all domain names to see if they either match the <target-name> domain or are a subdomain of the <target-name> domain.

  • If any do, this domain name can be validated.

  • If no domain name can be found, or if none of the domain names match or are a subdomain of the <target-name>, this mechanism fails to match.

  • If a DNS error occurs while doing the PTR RR lookup, then this mechanism fails to match.

This mechanism may match if

  • a validated domain name is a subdomain of the <target-name>, or

  • the <target-name> and a domain name are the same.

For example, "mail.example.com" is within the domain "example.com", but "mail.bad-example.com" is not.

The domain names received must also be validated for the mechanism to match.

  • For each matched record, validate the domain name by looking up its IP addresses. To prevent DoS attacks, the PTR processing limits defined in Section 4.6.4 MUST be applied. If they are exceeded, processing is terminated and the mechanism does not match.

  • If <ip> is among the returned IP addresses, then that domain name is validated.

If a DNS error occurs while doing an A RR lookup, then that domain name is skipped and the search continues.

The mechanism matches if a domain name is found that properly matches the target name and can be properly validated. While these tests can be done in either order, performing the match before validating prevents needless DNS queries being performed.

Note: This mechanism is not as reliable as other mechanisms in cases of DNS errors. If used, proper PTR records have to be in place for the domain’s hosts and the "ptr" mechanism SHOULD be one of the last mechanisms checked. After many years of SPF deployment experience, it has been concluded that it is unnecessary and more reliable alternatives should be used instead. It is, however, still in use as part of the SPF protocol, so compliant check_host() implementations MUST support it.

5.6. "ip4" and "ip6"

These mechanisms test whether <ip> is contained within a given IP network.

ip4              = "ip4"      ":" ip4-network   [ ip4-cidr-length ]
ip6              = "ip6"      ":" ip6-network   [ ip6-cidr-length ]

ip4-cidr-length  = "/" ("0" / %x31-39 0*1DIGIT) ; value range 0-32
ip6-cidr-length  = "/" ("0" / %x31-39 0*2DIGIT) ; value range 0-128
dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ]

ip4-network      = qnum "." qnum "." qnum "." qnum
qnum             = DIGIT                 ; 0-9
                   / %x31-39 DIGIT       ; 10-99
                   / "1" 2DIGIT          ; 100-199
                   / "2" %x30-34 DIGIT   ; 200-249
                   / "25" %x30-35        ; 250-255
                 ; as per conventional dotted-quad notation, e.g., 192.0.2.0

ip6-network      = <as per Section 2.2 of [RFC4291]>
                 ; e.g., 2001:db8::cd30

The <ip> is compared to the given network.

  • If CIDR prefix length high-order bits match, the mechanism matches.

  • If ip4-cidr-length is omitted, it is taken to be "/32".

  • If ip6-cidr-length is omitted, it is taken to be "/128".

  • It is not permitted to omit parts of the IP address instead of using CIDR notations. That is, use 192.0.2.0/24 instead of 192.0.2.

5.7. "exist"

This mechanism is used to construct an arbitrary domain name that is used for a DNS A record query. It allows for complicated schemes involving arbitrary parts of the mail envelope to determine what is permitted.

exists           = "exists"   ":" domain-spec
  • The resulting domain name is used for a DNS A RR lookup (even when the connection type is IPv6).

  • If any A record is returned, this mechanism matches.

  • Domains can use this mechanism to specify arbitrarily complex queries. For example, suppose example.com publishes the record: …​. v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all …​.

The <target-name> might expand to "1.2.0.192.someuser._spf.example.com". This makes fine-grained decisions possible at the level of the user and client IP address.

6. Modifier Definitions

Modifiers are name/value pairs that provide additional information.

  • Modifiers always have an "=" separating the name and the value.

  • The modifiers defined in this document ("redirect" and "exp") SHOULD appear at the end of the record, after all mechanisms, though syntactically they can appear anywhere in the record.

  • Ordering of these two modifiers does not matter.

  • These two modifiers MUST NOT appear in a record more than once each. If they do, then check_host() exits with a result of "permerror".

  • Unrecognized modifiers MUST be ignored no matter where, or how often, they appear in a record. This allows implementations conforming to this document to gracefully handle records with modifiers that are defined in other specifications.

6.1. redirect: Redirected Query

The "redirect" modifier is intended for consolidating both authorizations and policy into a common set to be shared within a single ADMD.

redirect         = "redirect" "=" domain-spec
  • For clarity, any "redirect" modifier SHOULD appear as the very last term in a record.

  • Any "redirect" modifier MUST be ignored if there is an "all" mechanism anywhere in the record.

If all mechanisms fail to match, and a "redirect" modifier is present, then processing proceeds as follows:

  • The <domain-spec> portion of the redirect section is expanded as per the macro rules in Section 7.

    • Then check_host() is evaluated with the resulting string as the <domain>.

    • The <ip> and <sender> arguments remain the same as in the current evaluation of check_host().

  • The result of this new evaluation of check_host() is then considered the result of the current evaluation with the exception that if no SPF record is found, or if the <target-name> is malformed, the result is a "permerror" rather than "none".

  • Note that the newly queried domain can itself specify redirect processing.

This facility is intended for use by organizations that wish to apply the same record to multiple domains. For example:

la.example.com. TXT "v=spf1 redirect=_spf.example.com"
ny.example.com. TXT "v=spf1 redirect=_spf.example.com"
sf.example.com. TXT "v=spf1 redirect=_spf.example.com"
_spf.example.com. TXT "v=spf1 mx:example.com -all"

In this example, mail from any of the three domains is described by the same record. This can be an administrative advantage.

Note: In general, the domain "A" cannot reliably use a redirect to another domain "B" not under the same administrative control. Since the <sender> stays the same, there is no guarantee that the record at domain "B" will correctly work for mailboxes in domain "A", especially if domain "B" uses mechanisms involving local-parts. An "include" directive will generally be more appropriate.

6.2. exp: Explanation

explanation      = "exp" "=" domain-spec

If check_host() results in a "fail" due to a mechanism match (such as "-all"), and the "exp" modifier is present, then the explanation string returned is computed as described below.

If no "exp" modifier is present, then either a default explanation string or an empty explanation string MUST be returned to the calling application.

  • The <domain-spec> is macro expanded (see Section 7) and becomes the <target-name>.

  • The DNS TXT RRset for the <target-name> is fetched.

  • If there are any DNS processing errors (any RCODE other than 0), or if no records are returned, or if more than one record is returned, or if there are syntax errors in the explanation string, then proceed as if no "exp" modifier was given.

  • The fetched TXT record’s strings are concatenated with no spaces, and then treated as an explain-string, which is macro-expanded. This final result is the explanation string.

  • Implementations MAY limit the length of the resulting explanation string to allow for other protocol constraints and/or reasonable processing limits.

  • Since the explanation string is intended for an SMTP response and Section 2.4 of [RFC5321] says that responses are in [US-ASCII], the explanation string MUST be limited to [US-ASCII].

  • Software evaluating check_host() can use this string to communicate information from the publishing domain in the form of a short message or URL.

  • Software SHOULD make it clear that the explanation string comes from a third party. For example, it can prepend the macro string "%{o} explains: " to the explanation.

  • During recursion into an "include" mechanism, an "exp" modifier from the <target-name> MUST NOT be used. This is because "include" is meant to cross administrative boundaries and the explanation provided should be the one from the receiving ADMD.

  • In contrast, when executing a "redirect" modifier, an "exp" modifier from the original domain MUST NOT be used. "redirect" is meant to operate as a tool to consolidate policy records within an ADMD so the redirected explanation is the one that ought to have priority.

Here are some examples of possible explanation TXT records at explain._spf.example.com:

"Mail from example.com should only be sent by its own servers."

— a simple, constant message

"%{i} is not one of %{d}'s designated mail servers."

— a message with a little more information, including the IP address that failed the check

"See http://%{d}/why.html?s=%{S}&i=%{I}"

— a complicated example that constructs a URL with the arguments to check_host() so that a web page can be generated with detailed, custom instructions

7. Macros

7.1. Formal Specification

domain-spec      = macro-string domain-end

domain-end       = ( "." toplabel [ "." ] ) / macro-expand

toplabel         = ( *alphanum ALPHA *alphanum ) /
                   ( 1*alphanum "-" *( alphanum / "-" ) alphanum )

alphanum         = ALPHA / DIGIT

explain-string   = *( macro-string / SP )

macro-string     = *( macro-expand / macro-literal )

macro-expand     = ( "%{" macro-letter transformers *delimiter "}" )
                   / "%%" / "%_" / "%-"

macro-literal    = %x21-24 / %x26-7E
                   ; visible characters except "%"

macro-letter     = "s" / "l" / "o" / "d" / "i" / "p" / "h" /
                   "c" / "r" / "t" / "v"

transformers     = *DIGIT [ "r" ]

delimiter        = "." / "-" / "+" / "," / "/" / "_" / "="

Some special cases:

  • A literal "%" is expressed by "%%".

  • "%_" expands to a single " " space.

  • "%-" expands to a URL-encoded space, viz., "%20".

7.2. Macro Definitions

The following macro letters are expanded in term arguments:

s = <sender>
l = local-part of <sender>
o = domain of <sender>
d = <domain>
i = <ip>
p = the validated domain name of <ip> (do not use)
v = the string "in-addr" if <ip> is ipv4, or "ip6" if <ip> is ipv6
h = HELO/EHLO domain

The following macro letters are allowed only in "exp" text:

c = SMTP client IP (easily readable format)
r = domain name of host performing the check
t = current timestamp

7.3. Macro Processing Details

A '%' character not followed by a '{', '%', '-', or '_' character is a syntax error. So:

        -exists:%(ir).sbl.example.org

is incorrect and will cause check_host() to yield a "permerror". Instead, the following is legal:

        -exists:%{ir}.sbl.example.org

Optional transformers are the following:

*DIGIT = zero or more digits

'r'    = reverse value, splitting on dots by default

If transformers or delimiters are provided, the replacement value for a macro letter is split into parts separated by one or more of the specified delimiter characters. After performing any reversal operation and/or removal of left-hand parts, the parts are rejoined using "." and not the original splitting characters.

  • By default, strings are split on "." (dots).

  • Note that no special treatment is given to leading, trailing, or consecutive delimiters in input strings, and so the list of parts might contain empty strings.

  • Some older implementations of SPF prohibit trailing dots in domain names, so trailing dots SHOULD NOT be published, although they MUST be accepted by implementations conforming to this document.

  • Macros can specify delimiter characters that are used instead of ".".

  • The "r" transformer indicates a reversal operation: if the client IP address were 192.0.2.1, the macro %{i} would expand to "192.0.2.1" and the macro %{ir} would expand to "1.2.0.192".

  • The DIGIT transformer indicates the number of right-hand parts to use, after optional reversal.

    • If a DIGIT is specified, the value MUST be nonzero.

    • If no DIGITs are specified, or if the value specifies more parts than are available, all the available parts are used.

    • If the DIGIT was 5, and only 3 parts were available, the macro interpreter would pretend the DIGIT was 3.

    • Implementations MUST support at least a value of 127, as that is the maximum number of labels in a domain name (less the zero-length label at the end).

  • The "s" macro expands to the <sender> argument. It is an email address with a local-part, an "@" character, and a domain.

  • The "l" macro expands to just the local-part.

  • The "o" macro expands to just the domain part.

  • Note that "s", "l", and "o" values remain the same during recursive and chained evaluations due to "include" and/or "redirect".

  • If the original <sender> had no local-part, the local-part was set to "postmaster" in initial processing (see Section 4.3).

  • For IPv4 addresses, both the "i" and "c" macros expand to the standard dotted-quad format.

  • For IPv6 addresses, the "i" macro expands to a dot-format address; it is intended for use in %{ir}.

  • The "c" macro can expand to any of the hexadecimal colon-format addresses specified in Section 2.2 of [RFC4291]. It is intended for humans to read.

  • The "p" macro expands to the validated domain name of <ip>. The procedure for finding the validated domain name is defined in Section 5.5.

    • If the <domain> is present in the list of validated domains, it SHOULD be used.

    • Otherwise, if a subdomain of the <domain> is present, it SHOULD be used.

    • Otherwise, any name from the list can be used.

    • If there are no validated domain names or if a DNS error occurs, the string "unknown" is used.

    • This macro SHOULD NOT be published (see Section 5.5 for the discussion).

  • The "h" macro expands to the parameter that was provided to the SMTP server via the HELO or EHLO SMTP verb. For sessions where that verb was provided more than once, the most recent instance is used.

  • The "r" macro expands to the name of the receiving MTA. This SHOULD be a fully qualified domain name, but if one does not exist (as when the checking is done by a Mail User Agent (MUA)) or if policy restrictions dictate otherwise, the word "unknown" SHOULD be substituted. The domain name can be different from the name found in the MX record that the client MTA used to locate the receiving MTA.

  • The "t" macro expands to the decimal representation of the approximate number of seconds since the Epoch (Midnight, January 1, 1970, UTC) at the time of the evaluation. This is the same value as the value that is returned by the Portable Operating System Interface (POSIX) time() function in most standards-compliant libraries.

  • When the result of macro expansion is used in a domain name query, if the expanded domain name exceeds 253 characters (the maximum length of a domain name in this format), the left side is truncated to fit, by removing successive domain labels (and their following dots) until the total length does not exceed 253 characters.

  • Uppercase macros expand exactly as their lowercase equivalents, and are then URL escaped. URL escaping MUST be performed for characters not in the "unreserved" set, which is defined in [RFC3986].

  • Care has to be taken by the sending ADMD so that macro expansion for legitimate email does not exceed the 63-character limit on DNS labels. The local-part of email addresses, in particular, can have more than 63 characters between dots.

  • To minimize DNS lookup resource requirements, it is better if sending ADMDs avoid using the "s", "l", "o", or "h" macros in conjunction with any mechanism directive. Although these macros are powerful and allow per-user records to be published, they severely limit the ability of implementations to cache results of check_host() and they reduce the effectiveness of DNS caches.

  • If no directive processed during the evaluation of check_host() contains an "s", "l", "o", or "h" macro, then the results of the evaluation can be cached on the basis of <domain> and <ip> alone for as long as the DNS record involved with the shortest Time to Live (TTL) has not expired.

7.4. Expansion Examples

The <sender> is strong-bad@email.example.com. The IPv4 SMTP client IP is 192.0.2.3. The IPv6 SMTP client IP is 2001:db8::cb01. The PTR domain name of the client IP is mx.example.org.

Example of macro expansion,

  • %{s}: strong-bad@email.example.com

  • %{o}: email.example.com

  • %{d}: email.example.com

  • %{d4}: email.example.com

  • %{d3}: email.example.com

  • %{d2}: example.com

  • %{d1}: com

  • %{dr}: com.example.email

  • %{d2r}: example.email

  • %{l}: strong-bad

  • %{l-}: strong.bad

  • %{lr}: strong-bad

  • %{lr-}: bad.strong

  • %{l1r-}: strong

  • %{ir}.%{v}._spf.%{d2}: `3.2.0.192.in-addr._spf.example.com

  • %{lr-}.lp._spf.%{d2}: bad.strong.lp._spf.example.com

  • %{lr-}.lp.%{ir}.%{v}._spf.%{d2}: bad.strong.lp.3.2.0.192.in-addr._spf.example.com

  • %{ir}.%{v}.%{l1r-}.lp._spf.%{d2}: 3.2.0.192.in-addr.strong.lp._spf.example.com

  • %{d2}.trusted-domains.example.net: example.com.trusted-domains.example.net

  • %{ir}.%{v}._spf.%{d2}: 1.0.b.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6._spf.example.com

8. Result Handling

There are essentially two classes of handling choices:

- Handling within the SMTP session that attempted to deliver the message, such as by returning a permanent SMTP error (rejection) or temporary SMTP error ("try again later");

- Permitting the message to pass (a successful SMTP reply code) and adding an additional header field that indicates the result returned by check_host() and other salient details; this is discussed in more detail in Section 9.

8.1. None

The SPF verifier has no information at all about the authorization or lack thereof of the client to use the checked identity or identities. The check_host() function completed without errors but was not able to reach any conclusion.

8.2. Neutral

A policy for the identity was discovered, there is no definite assertion (positive or negative) about the client.

A "neutral" result MUST be treated exactly like the "none" result; the distinction exists only for informational purposes. Treating "neutral" more harshly than "none" would discourage ADMDs from testing the use of SPF records (see Section 10.1).

8.3. Pass

The client is authorized to inject mail with the given identity. The domain can now, in the sense of reputation, be considered responsible for sending the message. Further policy checks can now proceed with confidence in the legitimate use of the identity. This is further discussed in Appendix G.1.

8.4. Fail

The client is not authorized to use the domain in the given identity. Disposition of SPF fail messages is a matter of local policy. See Appendix G.2 for considerations on developing local policy.

  • If the checking software chooses to reject the mail during the SMTP transaction, then it SHOULD use an SMTP reply code of 550 (see [RFC5321]) and, if supported, the 5.7.1 enhanced status code (see [RFC3463], Section 3.8), in addition to an appropriate reply text.

  • The check_host() function will return either a default explanation string or one from the domain that published the SPF records (see Section 6.2).

  • If the information does not originate with the checking software, it is good to make it clear that the text is provided by the sender’s domain. For example:

    550 5.7.1 SPF MAIL FROM check failed:
    550 5.7.1 The domain example.com explains:
    550 5.7.1 Please see http://www.example.com/mailpolicy.html
  • If the checking software chooses not to reject the mail during the SMTP transaction, then it SHOULD add a Received-SPF or Authentication-Results header field (see Section 9) to communicate this result to downstream message processors. While this is true for all SPF results, it is of particular importance for "fail" results since the message is explicitly not authorized by the ADMD.

8.5. Softfail

A "softfail" result ought to be treated as somewhere between "fail" and "neutral"/"none". The ADMD believes the host is not authorized but is not willing to make a strong policy statement.

  • Receiving software SHOULD NOT reject the message based solely on this result, but MAY subject the message to closer scrutiny than normal.

  • The ADMD wants to discourage the use of this host and thus desires limited feedback when a "softfail" result occurs. For example, the recipient’s MUA could highlight the "softfail" status, or the receiving MTA could give the sender a message using greylisting [RFC6647], with a note the first time the message is received, but accept it on a later attempt based on receiver policy.

8.6. Temperror

The SPF verifier encountered a transient (generally DNS) error while performing the check.

  • Checking software can choose to accept or temporarily reject the message.

  • If the message is rejected during the SMTP transaction for this reason, the software SHOULD use an SMTP reply code of 451 and, if supported, the 4.4.3 enhanced status code (see Section 3.5 of [RFC3463]).

  • These errors can be caused by problems in either the sender’s or receiver’s DNS software. See Appendix G.4 for considerations on developing local policy.

8.7. Permerror

The domain’s published records could not be correctly interpreted.

  • This signals an error condition that definitely requires DNS operator intervention to be resolved.

  • If the message is rejected during the SMTP transaction for this reason, the software SHOULD use an SMTP reply code of 550 and, if supported, the 5.5.2 enhanced status code (see [RFC3463], Section 3.6).

  • Be aware that if the ADMD uses macros (Section 7), it is possible that this result is due to the checked identities having an unexpected format.

  • It is also possible that this result is generated by certain SPF verifiers due to the input arguments having an unexpected format; see Section 4.8.

  • See Appendix G.3 for considerations on developing local policy.

9. Recording the Result

It is RECOMMENDED that SMTP receivers record the result of SPF processing in the message header.

Two methods are presented:

  • Section 9.1 defines the Received-SPF field, which is the results field originally defined for SPF use.

    • Received-SPF is intended to include enough information to enable reconstruction of the SPF evaluation of the message.

    • Received-SPF relies on compliance of agents within the receiving ADMD to adhere to the header field ordering rules of [RFC5321] and [RFC5322]

  • Section 9.2 discusses the Authentication-Results header field [RFC7001], which was specified more recently and is designed for use by SPF and other authentication methods.

    • Authentication-Results is designed only to relay the result itself and related output details of likely use to end users (e.g., what property of the message was actually authenticated and what it contained), leaving reconstructive work to the purview of system logs and the Received field contents.

    • Authentication-Results includes some provisions to protect against non-compliant implementations.

  • An SPF verifier operator could choose to use both to serve different downstream agents. In such cases, care needs to be taken to ensure that both fields are conveying the same details, or unexpected results can occur.

9.1. The Received-SPF Header Field

  • The Received-SPF header field is a trace field (see [RFC5322], Section 3.6.7) and SHOULD be prepended to the existing header, above the Received: field that is generated by the SMTP receiver.

  • It MUST appear above all other Received-SPF fields in the message.

The header field has the following format:

header-field     = "Received-SPF:" [CFWS] result FWS [comment FWS]
[ key-value-list ] CRLF
result           = "pass" / "fail" / "softfail" / "neutral" /
"none" / "temperror" / "permerror"
key-value-list   = key-value-pair *( ";" [CFWS] key-value-pair )
[";"]
key-value-pair   = key [CFWS] "=" ( dot-atom / quoted-string )
key              = "client-ip" / "envelope-from" / "helo" /
"problem" / "receiver" / "identity" /
"mechanism" / name
identity         = "mailfrom"   ; for the "MAIL FROM" identity
/ "helo"     ; for the "HELO" identity
/ name       ; other identities
dot-atom         = <unquoted word as per [RFC5322]>
quoted-string    = <quoted string as per [RFC5322]>
comment          = <comment string as per [RFC5322]>
CFWS             = <comment or folding white space as per [RFC5322]>
FWS              = <folding white space as per [RFC5322]>
CRLF             = <standard end-of-line token as per [RFC5322]>
  • The header field SHOULD include a "(…​)" style comment after the result, conveying supporting information for the result, such as <ip>, <sender>, and <domain>.

  • SPF verifiers SHOULD give enough information so that the SPF results can be verified — that is, at least "client-ip", "helo", and, if the "MAIL FROM" identity was checked, "envelope-from".

The following key-value pairs are designed for later machine parsing,

  • client-ip: the IP address of the SMTP client

  • envelope-from: the envelope sender mailbox

  • helo: the host name given in the HELO or EHLO command

  • mechanism: the mechanism that matched (if no mechanisms matched, substitute the word "default")

  • problem: if an error was returned, details about the error

  • receiver: the host name of the SPF verifier

  • identity: the identity that was checked; see the <identity> ABNF rule

Other keys MAY be defined by SPF verifiers.

SPF verifiers MUST make sure that the Received-SPF header field does not contain invalid characters, is not excessively long (see [RFC5322], Section 2.1.1), and does not contain malicious data that has been provided by the sender.

Examples of various header field styles that could be generated are the following:

Received-SPF: pass (mybox.example.org: domain of
 myname@example.com designates 192.0.2.1 as permitted sender)
   receiver=mybox.example.org; client-ip=192.0.2.1;
   envelope-from="myname@example.com"; helo=foo.example.com;

Received-SPF: fail (mybox.example.org: domain of
                 myname@example.com does not designate
                 192.0.2.1 as permitted sender)
                 identity=mailfrom; client-ip=192.0.2.1;
                 envelope-from="myname@example.com";

Received-SPF: pass (mybox.example.org: domain of
    myname@example.com designates 192.0.2.1 as permitted sender)
       receiver=mybox.example.org; client-ip=192.0.2.1;
       mechanism=ip4:192.0.2.1; envelope-from="myname@example.com";
       helo=foo.example.com;

9.2. SPF Results in the Authentication-Results Header Field

The Authentication-Results header field is designed to communicate lists of tests a border MTA did and their results. The specified elements of the field provide less information than the Received-SPF field:

   Authentication-Results: myhost.example.org; spf=pass
     smtp.mailfrom=example.net

   Received-SPF: pass (myhost.example.org: domain of
    myname@example.com designates 192.0.2.1 as permitted sender)
       receiver=mybox.example.org; client-ip=192.0.2.1;
       envelope-from="myname@example.com"; helo=foo.example.com;

It is, however, possible to add CFWS in the "reason" part of an Authentication-Results header field and provide the equivalent information, if desired.

As an example, an expanded Authentication-Results header field might look like (for a "MAIL FROM" check in this example):

   Authentication-Results: myhost.example.org; spf=pass
     reason="client-ip=192.0.2.1; smtp.helo=foo.example.com"
     smtp.mailfrom=user@example.net

10. Effects on Infrastructure

This section provides operational advice and instruction only. It is non-normative.

10.1. Sending Domains

Originating ADMDs that wish to be compliant with this specification will need to determine the list of relays ([RFC5598], Section 2.2.2) that they allow to use their domain name in the "HELO" and "MAIL FROM" identities when relaying to other ADMDs. It is recognized that forming such a list is not just a simple technical exercise, but involves policy decisions with both technical and administrative considerations.

10.1.1. DNS Resource Considerations

For example, consider a domain set up as follows:

example.com.     IN MX   10 mx.example.com.
IN MX   20 mx2.example.com.
mx.example.com.  IN A    192.0.2.1
mx2.example.com. IN A    192.0.2.129

Assume the administrative point is to authorize (pass) mx and mx2 while failing every other host. Compare the following solutions:

Best record:

example.com.   IN TXT  "v=spf1 ip4:192.0.2.1 ip4:192.0.2.129 -all"

Good record:

$ORIGIN example.com.
@              IN TXT  "v=spf1 a:authorized-spf.example.com -all"
authorized-spf IN A    192.0.2.1
IN A    192.0.2.129

Expensive record:

example.com.   IN TXT  "v=spf1 mx:example.com -all"

Wasteful, bad record:

example.com.   IN TXT  "v=spf1 ip4:192.0.2.0/24 mx -all"

10.1.2. Administrator’s Considerations

There might be administrative considerations: using "a" over "ip4" or "ip6" allows hosts to be renumbered easily at the cost of a DNS query per receiver. Using "mx" over "a" allows the set of mail hosts to be changed easily. Unless such changes are common, it is better to use the less resource-intensive mechanisms like "ip4" and "ip6" over "a" or "a" over "mx".

Publishing SPF records for domains that send no mail is a well-established best practice. The record for a domain that sends no mail is:

www.example.com.   IN TXT  "v=spf1 -all"

Publishing SPF records for individual hosts is also best practice. The host name is generally the identity used in the 5321.HELO/.EHLO command. In the case of messages with a null 5321.MailFrom, this is used as the domain for 5321.MailFrom SPF checks, in addition to being used in 5321.HELO/.EHLO-based SPF checks. The standard SPF record for an individual host that is involved in mail processing is:

relay.example.com.   IN TXT  "v=spf1 a -all"

Validating correct deployment is difficult. [RFC6652] describes one mechanism for soliciting feedback on SPF failures. Another suggestion can be found in Appendix C.

Regardless of the method used, understanding the ADMD’s outbound mail architecture is essential to effective deployment.

10.1.3. Bounces

In this case, the only entity available for performing an SPF check is the "HELO" identity defined in Section 1.1.4. SPF functionality is enhanced by administrators ensuring this identity is set correctly and has an appropriate SPF record. It is normal to have the "HELO" identity set to the host name instead of the domain. Zone file generation for significant numbers of hosts can be consolidated using the "redirect" modifier and scripted for initial deployment.

10.2. Receivers

There is no comprehensive normative requirement for specific handling of a message based on SPF results. The information presented in Section 8 and in Appendix G is offered for receiver consideration when forming local handling policies.

The primary considerations are that SPF might return "pass" for mail that is ultimately harmful (e.g., spammers that arrange for SPF to pass using disposable domain names, or virus or spam outbreaks from within trusted sources), and might also return "fail" for mail that is ultimately legitimate (e.g., legitimate mail that has traversed a mail alias). It is important to take both of these cases under consideration when establishing local handling policy.

10.3. Mediator

A mediator takes 'delivery’ of a message and posts a 'submission’ of a new message. The mediator can make the newly posted message be as similar to or as different from the original message as they wish. Examples include mailing lists (see Section 5.3 of [RFC5598]) and ReSenders (Section 5.2 of [RFC5598]). This is discussed in [RFC5321], Section 3.9. For the operation of SPF, the essential concern is the email address in the 5321.MailFrom command for the new message.

Because SPF evaluation is based on the IP address of the "last" sending SMTP server, the address of the mediator will be used, rather than the address of the SMTP server that sent the message to the mediator. Some mediators retain the email address from the original message, while some use a new address.

If the address is the same as for the original message, and the original message had an associated SPF record, then the SPF evaluation will fail unless mitigations such as those described in Appendix D are used.

11. Security Considerations

11.1. Processing Limits

The processing limits outlined in Section 4.6.4 are designed to prevent attacks such as the following:

  • A malicious party could create an SPF record with many references to a victim’s domain and send many emails to different SPF verifiers; those SPF verifiers would then create a DoS attack. In effect, the SPF verifiers are being used to amplify the attacker’s bandwidth by using fewer octets in the SMTP session than are used by the DNS queries. Using SPF verifiers also allows the attacker to hide the true source of the attack. This potential attack is based on large volumes of mail being transmitted.

  • Whereas implementations of check_host() are supposed to limit the number of DNS lookups, malicious domains could publish records that exceed these limits in an attempt to waste computation effort at their targets when they send them mail. Malicious domains could also design SPF records that cause particular implementations to use excessive memory or CPU or to trigger bugs. If a receiver is configured to accept mail with an SPF result of "temperror", such an attack might result in mail that would otherwise have been rejected due to an SPF "fail" result being accepted. This potential attack is based on specially crafted SPF records being used to exhaust DNS resources of the victim.

  • Malicious parties could send a large volume of mail purporting to come from the intended target to a wide variety of legitimate mail hosts. These legitimate machines would then present a DNS load on the target as they fetched the relevant records.

  • Malicious parties could, in theory, use SPF records as a vehicle for DNS lookup amplification for a DoS attack. In this scenario, the attacker publishes an SPF record in its own DNS that uses "a" and "mx" mechanisms directed toward the intended victim, e.g., "a:example.com a:foo.example.com a:bar.example.com

    1. and then distributes mail with a MAIL FROM value including its own domain in large volume to a wide variety of destinations. Any such destination operating an SPF verifier will begin querying all of the names associated with the "a" mechanisms in that record. The names used in the record needn’t exist for the attack to be effective. Operational experience since the publication of [RFC4408] suggests that mitigation of this class of attack can be accomplished with minimal impact on the deployed base by having the verifier abort processing and return "permerror" (Section 2.6.7) as soon as more than two "void lookups" have been encountered (defined in Section 4.6.4).

Of these, the case of a third party referenced in the SPF record is the easiest for a DoS attack to effectively exploit. As a result, limits that might seem reasonable for an individual mail server can still allow an unreasonable amount of bandwidth amplification. Therefore, the processing limits need to be quite low.

11.2. SPF-Authorized Email May Contain Other False Identities

The "MAIL FROM" and "HELO" identity authorizations do not provide assurance about the authorization/authenticity of other identities used in the message. It is entirely possible for a malicious sender to inject a message using his own domain in the identities used by SPF and have that domain’s SPF record authorize the sending host, and yet the message can easily list other identities in its header. Unless the user or the MUA takes care to note that the authorized identity does not match the other more commonly presented identities (such as the From: header field), the user might be lulled into a false sense of security.

11.3. Spoofed DNS and IP Data

There are two aspects of this protocol that malicious parties could exploit to undermine the validity of the check_host() function:

  • The evaluation of check_host() relies heavily on DNS. A malicious attacker could attack the DNS infrastructure and cause check_host() to see spoofed DNS data, and then return incorrect results. This could include returning "pass" for an <ip> value where the actual domain’s record would evaluate to "fail". See [RFC3833] for a description of DNS weaknesses, and see [RFC4033] for a countermeasure.

  • The client IP address, <ip>, is assumed to be correct. In a modern, correctly configured system, the risk of this not being true is nil.

11.4. Cross-User Forgery

By definition, SPF policies just map domain names to sets of authorized MTAs, not whole email addresses to sets of authorized users. Although the "l" macro (Section 7) provides a limited way to define individual sets of authorized MTAs for specific email addresses, it is generally impossible to verify, through SPF, the use of specific email addresses by individual users of the same MTA.

It is up to mail services and their MTAs to directly prevent cross-user forgery: based on SMTP AUTH ([RFC4954]), users have to be restricted to using only those email addresses that are actually under their control (see Section 6.1 of [RFC6409]). Another means to verify the identity of individual users is message cryptography, such as Pretty Good Privacy (PGP) ([RFC4880]) or S/MIME ([RFC5751]).

11.5. Untrusted Information Sources

An SPF-compliant receiver gathers information from the SMTP commands it receives and from the published DNS records of the sending domain holder (e.g., "HELO" domain name, the "MAIL FROM" address from the envelope, and SPF DNS records published by the domain holder). These parameters are not validated in the SMTP process.

All of these pieces of information are generated by actors outside of the authority of the receiver, and thus are not guaranteed to be accurate or legitimate.

11.5.1. Recorded Results

This information, passed to the receiver in the Received-SPF: or Authentication-Results: trace fields, can be returned to the client MTA as an SMTP rejection message. If such an SMTP rejection message is generated, the information from the trace fields has to be checked for such problems as invalid characters and excessively long lines.

11.5.2. External Explanations

When the authorization check fails, an explanation string could be included in the reject response. Both the sender and the rejecting receiver need to be aware that the explanation was determined by the publisher of the SPF record checked and, in general, not the receiver. The explanation can contain malicious URLs, or it might be offensive or misleading.

Explanations returned to sender domains due to "exp" modifiers (Section 6.2) were generated by the sender policy published by the domain holders themselves. As long as messages are only returned with non-delivery notifications ([RFC3464]) to domains publishing the explanation strings from their own DNS SPF records, the only affected parties are the original publishers of the domain’s SPF records.

In practice, such non-delivery notifications can be misdirected, such as when an MTA accepts an email and only later generates the notification to a forged address, or when an email forwarder does not direct the bounce back to the original sender.

11.5.3. Macro Expansion

Macros (Section 7) allow senders to inject arbitrary text (any non-null [US-ASCII] character) into receiver DNS queries. It is necessary to be prepared for hostile or unexpected content.

11.6. Privacy Exposure

Checking SPF records causes DNS queries to be sent to the domain owner. These DNS queries, especially if they are caused by the "exists" mechanism, can contain information about who is sending email and likely to which MTA the email is being sent. This can introduce some privacy concerns, which are more or less of an issue depending on local laws and the relationship between the ADMD and the person sending the email.

11.7. Delivering Mail Producing a "Fail" Result

Operators that choose to deliver mail for which SPF produces a "fail" result need to understand that they are admitting content that is explicitly not authorized by the purported sender. While there are known failure modes that can be considered "false negatives", the distinct choice to admit those messages increases end-user exposure to likely harm. This is especially true for domains belonging to known good actors that are typically well-behaved; unauthorized mail from those sources might well be subjected to much higher skepticism and content analysis.

SPF does not, however, include the capacity to distinguish good actors from bad ones, nor does it handle the concept of known actors versus unknown ones. Those notions are out of scope for this specification.