Network Working Group M. Wong
Request for Comments: 4408 W. Schlitt
Category: Experimental April 2006
Sender Policy Framework (SPF) for
Authorizing Use of Domains in E-Mail, Version 1
Status of This Memo
This memo defines an Experimental Protocol for the Internet
community. It does not specify an Internet standard of any kind.
Discussion and suggestions for improvement are requested.
Distribution of this memo is unlimited.
Copyright Notice
Copyright (C) The Internet Society (2006).
IESG Note
The following documents (RFC 4405, RFC 4406, RFC 4407, and RFC 4408)
are published simultaneously as Experimental RFCs, although there is
no general technical consensus and efforts to reconcile the two
approaches have failed. As such, these documents have not received
full IETF review and are published "AS-IS" to document the different
approaches as they were considered in the MARID working group.
The IESG takes no position about which approach is to be preferred
and cautions the reader that there are serious open issues for each
approach and concerns about using them in tandem. The IESG believes
that documenting the different approaches does less harm than not
documenting them.
Note that the Sender ID experiment may use DNS records that may have
been created for the current SPF experiment or earlier versions in
this set of experiments. Depending on the content of the record,
this may mean that Sender-ID heuristics would be applied incorrectly
to a message. Depending on the actions associated by the recipient
with those heuristics, the message may not be delivered or may be
discarded on receipt.
Participants relying on Sender ID experiment DNS records are warned
that they may lose valid messages in this set of circumstances.
aParticipants publishing SPF experiment DNS records should consider
the advice given in section 3.4 of RFC 4406 and may wish to publish
both v=spf1 and spf2.0 records to avoid the conflict.
Wong & Schlitt Experimental [Page 1]
RFC 4408 Sender Policy Framework (SPF) April 2006
Participants in the Sender-ID experiment need to be aware that the
way Resent-* header fields are used will result in failure to receive
legitimate email when interacting with standards-compliant systems
(specifically automatic forwarders which comply with the standards by
not adding Resent-* headers, and systems which comply with RFC 822
but have not yet implemented RFC 2822 Resent-* semantics). It would
be inappropriate to advance Sender-ID on the standards track without
resolving this interoperability problem.
The community is invited to observe the success or failure of the two
approaches during the two years following publication, in order that
a community consensus can be reached in the future.
Abstract
E-mail on the Internet can be forged in a number of ways. In
particular, existing protocols place no restriction on what a sending
host can use as the reverse-path of a message or the domain given on
the SMTP HELO/EHLO commands. This document describes version 1 of
the Sender Policy Framework (SPF) protocol, whereby a domain may
explicitly authorize the hosts that are allowed to use its domain
name, and a receiving host may check such authorization.
Table of Contents
1. Introduction ....................................................4
1.1. Protocol Status ............................................4
1.2. Terminology ................................................5
2. Operation .......................................................5
2.1. The HELO Identity ..........................................5
2.2. The MAIL FROM Identity .....................................5
2.3. Publishing Authorization ...................................6
2.4. Checking Authorization .....................................6
2.5. Interpreting the Result ....................................7
2.5.1. None ................................................8
2.5.2. Neutral .............................................8
2.5.3. Pass ................................................8
2.5.4. Fail ................................................8
2.5.5. SoftFail ............................................9
2.5.6. TempError ...........................................9
2.5.7. PermError ...........................................9
3. SPF Records .....................................................9
3.1. Publishing ................................................10
3.1.1. DNS Resource Record Types ..........................10
3.1.2. Multiple DNS Records ...............................11
3.1.3. Multiple Strings in a Single DNS record ............11
3.1.4. Record Size ........................................11
3.1.5. Wildcard Records ...................................11
Wong & Schlitt Experimental [Page 2]
RFC 4408 Sender Policy Framework (SPF) April 2006
4. The check_host() Function ......................................12
4.1. Arguments .................................................12
4.2. Results ...................................................13
4.3. Initial Processing ........................................13
4.4. Record Lookup .............................................13
4.5. Selecting Records .........................................13
4.6. Record Evaluation .........................................14
4.6.1. Term Evaluation ....................................14
4.6.2. Mechanisms .........................................15
4.6.3. Modifiers ..........................................15
4.7. Default Result ............................................16
4.8. Domain Specification ......................................16
5. Mechanism Definitions ..........................................16
5.1. "all" .....................................................17
5.2. "include" .................................................18
5.3. "a" .......................................................19
5.4. "mx" ......................................................20
5.5. "ptr" .....................................................20
5.6. "ip4" and "ip6" ...........................................21
5.7. "exists" ..................................................22
6. Modifier Definitions ...........................................22
6.1. redirect: Redirected Query ................................23
6.2. exp: Explanation ..........................................23
7. The Received-SPF Header Field ..................................25
8. Macros .........................................................27
8.1. Macro Definitions .........................................27
8.2. Expansion Examples ........................................30
9. Implications ...................................................31
9.1. Sending Domains ...........................................31
9.2. Mailing Lists .............................................32
9.3. Forwarding Services and Aliases ...........................32
9.4. Mail Services .............................................34
9.5. MTA Relays ................................................34
10. Security Considerations .......................................35
10.1. Processing Limits ........................................35
10.2. SPF-Authorized E-Mail May Contain Other False
Identities ...............................................37
10.3. Spoofed DNS and IP Data ..................................37
10.4. Cross-User Forgery .......................................37
10.5. Untrusted Information Sources ............................38
10.6. Privacy Exposure .........................................38
11. Contributors and Acknowledgements .............................38
12. IANA Considerations ...........................................39
12.1. The SPF DNS Record Type ..................................39
12.2. The Received-SPF Mail Header Field .......................39
13. References ....................................................39
13.1. Normative References .....................................39
13.2. Informative References ...................................40
Wong & Schlitt Experimental [Page 3]
RFC 4408 Sender Policy Framework (SPF) April 2006
Appendix A. Collected ABNF .......................................42
Appendix B. Extended Examples ....................................44
B.1. Simple Examples ..........................................44
B.2. Multiple Domain Example ..................................45
B.3. DNSBL Style Example ......................................46
B.4. Multiple Requirements Example ............................46
1. Introduction
The current E-Mail infrastructure has the property that any host
injecting mail into the mail system can identify itself as any domain
name it wants. Hosts can do this at a variety of levels: in
particular, the session, the envelope, and the mail headers.
Although this feature is desirable in some circumstances, it is a
major obstacle to reducing Unsolicited Bulk E-Mail (UBE, aka spam).
Furthermore, many domain name holders are understandably concerned
about the ease with which other entities may make use of their domain
names, often with malicious intent.
This document defines a protocol by which domain owners may authorize
hosts to use their domain name in the "MAIL FROM" or "HELO" identity.
Compliant domain holders publish Sender Policy Framework (SPF)
records 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.
An additional benefit to mail receivers is that after the use of an
identity is verified, local policy decisions about the mail can be
made based on the sender's domain, rather than the host's IP address.
This is advantageous because reputation of domain names is likely to
be more accurate than reputation of host IP addresses. Furthermore,
if a claimed identity fails verification, local policy can take
stronger action against such E-Mail, such as rejecting it.
1.1. Protocol Status
SPF has been in development since the summer of 2003 and has seen
deployment beyond the developers beginning in December 2003. The
design of SPF slowly evolved until the spring of 2004 and has since
stabilized. There have been quite a number of forms of SPF, some
written up as documents, some submitted as Internet Drafts, and many
discussed and debated in development forums.
The goal of this document is to clearly document the protocol defined
by earlier draft specifications of SPF as used in existing
implementations. This conception of SPF is sometimes called "SPF
Classic". It is understood that particular implementations and
Wong & Schlitt Experimental [Page 4]
RFC 4408 Sender Policy Framework (SPF) April 2006
deployments may differ from, and build upon, this work. It is hoped
that we have nonetheless captured the common understanding of SPF
version 1.
1.2. Terminology
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in [RFC2119].
This document is concerned with the portion of a mail message
commonly called "envelope sender", "return path", "reverse path",
"bounce address", "2821 FROM", or "MAIL FROM". Since these terms are
either not well defined or often used casually, this document defines
the "MAIL FROM" identity in Section 2.2. Note that other terms that
may superficially look like the common terms, such as "reverse-path",
are used only with the defined meanings from normative documents.
2. Operation
2.1. The HELO Identity
The "HELO" identity derives from either the SMTP HELO or EHLO command
(see [RFC2821]). These commands supply the SMTP client (sending
host) for the SMTP session. Note that requirements for the domain
presented in the EHLO or HELO command are not always clear to the
sending party, and SPF clients must be prepared for the "HELO"
identity to be malformed or an IP address literal. At the time of
this writing, many legitimate E-Mails are delivered with invalid HELO
domains.
It is RECOMMENDED that SPF clients 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>. </sender>
2.2. The MAIL FROM Identity
The "MAIL FROM" identity derives from the SMTP MAIL command (see
[RFC2821]). This command supplies the "reverse-path" for a message,
which generally consists of the sender mailbox, and is the mailbox to
which notification messages are to be sent if there are problems
delivering the message.
[RFC2821] allows the reverse-path to be null (see Section 4.5.5 in
RFC 2821). In this case, there is no explicit sender mailbox, and
such a message can be assumed to be a notification message from the
mail system itself. When the reverse-path is null, this document
Wong & Schlitt Experimental [Page 5]
RFC 4408 Sender Policy Framework (SPF) April 2006
defines the "MAIL FROM" identity to be the mailbox composed of the
localpart "postmaster" and the "HELO" identity (which may or may not
have been checked separately before).
SPF clients MUST check the "MAIL FROM" identity. SPF clients check
the "MAIL FROM" identity by applying the check_host() function to the
"MAIL FROM" identity as the <sender>. </sender>
2.3. Publishing Authorization
An SPF-compliant domain MUST publish a valid SPF record as described
in Section 3. This record authorizes the use of the domain name in
the "HELO" and "MAIL FROM" identities by the MTAs it specifies.
If domain owners choose to publish SPF records, it is RECOMMENDED
that they end in "-all", or redirect to other records that do, so
that a definitive determination of authorization can be made.
Domain holders may publish SPF records that explicitly authorize no
hosts if mail should never originate using that domain.
When changing SPF records, care must be taken to ensure that there is
a transition period so that the old policy remains valid until all
legitimate E-Mail has been checked.
2.4. Checking Authorization
A mail receiver can perform a set of SPF checks for each mail message
it receives. An SPF check tests the authorization of a client host
to emit mail with a given identity. 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. At least the "MAIL FROM" identity MUST be checked, but it
is RECOMMENDED that the "HELO" identity also be checked beforehand.
Without explicit approval of the domain owner, 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
(see Section 9.2), but some do not change any other identities in the
message. The scenario described in Section 9.3, sub-section 1.2, is
another example. Documents that define other identities should
define the method for explicit approval.
It is possible that mail receivers will use the SPF check as part of
a larger set of tests on incoming mail. The results of other tests
may influence whether or not a particular SPF check is performed.
For example, finding the sending host's IP address on a local white
Wong & Schlitt Experimental [Page 6]
RFC 4408 Sender Policy Framework (SPF) April 2006
list may cause all other tests to be skipped and all mail from that
host to be accepted.
When a mail receiver decides to perform an SPF check, it MUST use a
correctly-implemented check_host() function (Section 4) evaluated
with the correct parameters. Although the test as a whole is
optional, once it has been decided to perform a test it must be
performed as specified so that the correct semantics are preserved
between publisher and receiver.
To make the test, the mail receiver MUST evaluate the check_host()
function with the arguments set as follows:
<ip> - the IP address of the SMTP client that is emitting the </ip>
mail, either IPv4 or IPv6.
<domain> - the domain portion of the "MAIL FROM" or "HELO" identity. </domain>
<sender> - the "MAIL FROM" or "HELO" identity. </sender>
Note that the <domain> argument may not be a well-formed domain name. </domain>
For example, if the reverse-path was null, then the EHLO/HELO domain
is used, with its associated problems (see Section 2.1). In these
cases, check_host() is defined in Section 4.3 to return a "None"
result.
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 E-Mail from such domains,
especially in the case of invalid "MAIL FROM". In order to prevent
the circumvention of SPF records, rejecting E-Mail from invalid
domains should be considered.
Implementations must take care to correctly extract the <domain> from </domain>
the data given with the SMTP MAIL FROM command as many MTAs will
still accept such things as source routes (see [RFC2821], Appendix
C), the %-hack (see [RFC1123]), and bang paths (see [RFC1983]).
These archaic features have been maliciously used to bypass security
systems.
2.5. Interpreting the Result
This section describes how software that performs the authorization
should interpret the results of the check_host() function. The
authorization check SHOULD be performed during the processing of the
SMTP transaction that sends the mail. This allows errors to be
returned directly to the sending MTA by way of SMTP replies.
Wong & Schlitt Experimental [Page 7]
RFC 4408 Sender Policy Framework (SPF) April 2006
Performing the authorization after the SMTP transaction has finished
may cause problems, such as the following: (1) It may be difficult to
accurately extract the required information from potentially
deceptive headers; (2) legitimate E-Mail may fail because the
sender's policy may have since changed.
Generating non-delivery notifications to forged identities that have
failed the authorization check is generally abusive and against the
explicit wishes of the identity owner.
2.5.1. None
A result of "None" means that no records were published by the domain
or that no checkable sender domain could be determined from the given
identity. The checking software cannot ascertain whether or not the
client host is authorized.
2.5.2. Neutral
The domain owner has explicitly stated that he cannot or does not
want to assert whether or not the IP address is authorized. 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 domain owners
from testing the use of SPF records (see Section 9.1).
2.5.3. Pass
A "Pass" result means that 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.
2.5.4. Fail
A "Fail" result is an explicit statement that the client is not
authorized to use the domain in the given identity. The checking
software can choose to mark the mail based on this or to reject the
mail outright.
If the checking software chooses to reject the mail during the SMTP
transaction, then it SHOULD use an SMTP reply code of 550 (see
[RFC2821]) and, if supported, the 5.7.1 Delivery Status Notification
(DSN) code (see [RFC3464]), in addition to an appropriate reply text.
The check_host() function may 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
Wong & Schlitt Experimental [Page 8]
RFC 4408 Sender Policy Framework (SPF) April 2006
checking software, it should be made 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
2.5.5. SoftFail
A "SoftFail" result should be treated as somewhere between a "Fail"
and a "Neutral". The domain believes the host is not authorized but
is not willing to make that strong of a statement. Receiving
software SHOULD NOT reject the message based solely on this result,
but MAY subject the message to closer scrutiny than normal.
The domain owner wants to discourage the use of this host and thus
desires limited feedback when a "SoftFail" result occurs. For
example, the recipient's Mail User Agent (MUA) could highlight the
"SoftFail" status, or the receiving MTA could give the sender a
message using a technique called "greylisting" whereby the MTA can
issue an SMTP reply code of 451 (4.3.0 DSN code) with a note the
first time the message is received, but accept it the second time.
2.5.6. TempError
A "TempError" result means that the SPF client encountered a
transient 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 DSN
code.
2.5.7. PermError
A "PermError" result means that the domain's published records could
not be correctly interpreted. This signals an error condition that
requires manual intervention to be resolved, as opposed to the
TempError result. Be aware that if the domain owner uses macros
(Section 8), it is possible that this result is due to the checked
identities having an unexpected format.
3. SPF Records
An SPF record is a DNS Resource Record (RR) that declares which hosts
are, and are not, authorized to use a domain name for the "HELO" and
"MAIL FROM" identities. Loosely, the record partitions all hosts
into permitted and not-permitted sets (though some hosts might fall
into neither category).
Wong & Schlitt Experimental [Page 9]
RFC 4408 Sender Policy Framework (SPF) April 2006
The SPF record is a single string of text. An example record is the
following:
v=spf1 +mx a:colo.example.com/28 -all
This record has a version of "spf1" and three directives: "+mx",
"a:colo.example.com/28" (the + is implied), and "-all".
3.1. Publishing
Domain owners wishing to be SPF compliant must publish SPF records
for the hosts that are used in the "MAIL FROM" and "HELO" identities.
The SPF records are placed in the DNS tree at the host name it
pertains to, not a subdomain under it, such as is done with SRV
records. This is the same whether the TXT or SPF RR type (see
Section 3.1.1) is used.
The example above in Section 3 might be published via these lines in
a domain zone file:
example.com. TXT "v=spf1 +mx a:colo.example.com/28 -all"
smtp-out.example.com. TXT "v=spf1 a -all"
When publishing via TXT records, beware of other TXT records
published there for other purposes. They may cause problems with
size limits (see Section 3.1.4).
3.1.1. DNS Resource Record Types
This document defines a new DNS RR of type SPF, code 99. The format
of this type is identical to the TXT RR [RFC1035]. For either type,
the character content of the record is encoded as [US-ASCII].
It is recognized that the current practice (using a TXT record) is
not optimal, but it is necessary because there are a number of DNS
server and resolver implementations in common use that cannot handle
the new RR type. The two-record-type scheme provides a forward path
to the better solution of using an RR type reserved for this purpose.
An SPF-compliant domain name SHOULD have SPF records of both RR
types. A compliant domain name MUST have a record of at least one
type. If a domain has records of both types, they MUST have
identical content. For example, instead of publishing just one
record as in Section 3.1 above, it is better to publish:
example.com. IN TXT "v=spf1 +mx a:colo.example.com/28 -all"
example.com. IN SPF "v=spf1 +mx a:colo.example.com/28 -all"
Wong & Schlitt Experimental [Page 10]
RFC 4408 Sender Policy Framework (SPF) April 2006
Example RRs in this document are shown with the TXT record type;
however, they could be published with the SPF type or with both
types.
3.1.2. Multiple DNS Records
A domain name MUST NOT have multiple records that would cause an
authorization check to select more than one record. See Section 4.5
for the selection rules.
3.1.3. Multiple Strings in a Single DNS record
As defined in [RFC1035] sections 3.3.14 and 3.3, a single text DNS
record (either TXT or SPF RR types) can be composed of more than one
string. If a published record contains multiple 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..."
MUST be treated as equivalent to
IN TXT "v=spf1 .... firstsecond string..."
SPF or TXT records containing multiple strings are useful in
constructing records that would exceed the 255-byte maximum length of
a string within a single TXT or SPF RR record.
3.1.4. Record Size
The published SPF record for a given domain name SHOULD remain small
enough that the results of a query for it will fit within 512 octets.
This will keep even older DNS implementations from falling over to
TCP. Since the answer size is dependent on many things outside the
scope of this document, it is only possible to give this guideline:
If the combined length of the DNS name and the text of all the
records of a given type (TXT or SPF) is under 450 characters, then
DNS answers should fit in UDP packets. Note that when computing the
sizes for queries of the TXT format, one must take into account any
other TXT records published at the domain name. Records that are too
long to fit in a single UDP packet MAY be silently ignored by SPF
clients.
3.1.5. Wildcard Records
Use of wildcard records for publishing is not recommended. Care must
be taken if wildcard records are used. If a domain publishes
wildcard MX records, it may want to publish wildcard declarations,
Wong & Schlitt Experimental [Page 11]
RFC 4408 Sender Policy Framework (SPF) April 2006
subject to the same requirements and problems. In particular, the
declaration must be repeated for any host that has any RR records at
all, and for subdomains thereof. For example, the example given in
[RFC1034], Section 4.3.3, could be extended with the following:
X.COM. MX 10 A.X.COM
X.COM. TXT "v=spf1 a:A.X.COM -all"
*.X.COM. MX 10 A.X.COM
*.X.COM. TXT "v=spf1 a:A.X.COM -all"
A.X.COM. A 1.2.3.4
A.X.COM. MX 10 A.X.COM
A.X.COM. TXT "v=spf1 a:A.X.COM -all"
*.A.X.COM. MX 10 A.X.COM
*.A.X.COM. TXT "v=spf1 a:A.X.COM -all"
Notice that SPF records must be repeated twice for every name within
the domain: once for the name, and once with a wildcard to cover the
tree under the name.
Use of wildcards is discouraged in general as they cause every name
under the domain to exist and queries against arbitrary names will
never return RCODE 3 (Name Error).
4. The check_host() Function
The check_host() function fetches SPF records, parses them, and
interprets them to determine whether a particular host is or is not
permitted to send mail with a given identity. Mail receivers that
perform this check MUST correctly evaluate the check_host() function
as described here.
Implementations MAY use a different algorithm than the canonical
algorithm defined here, so long as the results are the same in all
cases.
4.1. Arguments
The check_host() function takes these arguments:
<ip> - the IP address of the SMTP client that is emitting the </ip>
mail, either IPv4 or IPv6.
<domain> - the domain that provides the sought-after authorization </domain>
information; initially, the domain portion of the "MAIL
FROM" or "HELO" identity.
Wong & Schlitt Experimental [Page 12]
RFC 4408 Sender Policy Framework (SPF) April 2006
<sender> - the "MAIL FROM" or "HELO" identity. </sender>
The domain portion of <sender> will usually be the same as the </sender>
<domain> argument when check_host() is initially evaluated. However, </domain>
this will generally not be true for recursive evaluations (see
Section 5.2 below).
Actual implementations of the check_host() function may need
additional arguments.
4.2. Results
The function check_host() can return one of several results described
in Section 2.5. Based on the result, the action to be taken is
determined by the local policies of the receiver.
4.3. Initial Processing
If the <domain> is malformed (label longer than 63 characters, zero- </domain>
length label not at the end, etc.) or is not a fully qualified domain
name, or if the DNS lookup returns "domain does not exist" (RCODE 3),
check_host() immediately returns the result "None".
If the <sender> has no localpart, substitute the string "postmaster" </sender>
for the localpart.
4.4. Record Lookup
In accordance with how the records are published (see Section 3.1
above), a DNS query needs to be made for the <domain> name, querying </domain>
for either RR type TXT, SPF, or both. If both SPF and TXT RRs are
looked up, the queries MAY be done in parallel.
If all DNS lookups that are made return a server failure (RCODE 2),
or other error (RCODE other than 0 or 3), or time out, then
check_host() exits immediately with the result "TempError".
4.5. Selecting Records
Records begin with a version section:
record = version terms *SP
version = "v=spf1"
Starting with the set of records that were returned by the lookup,
record selection proceeds in two steps:
Wong & Schlitt Experimental [Page 13]
RFC 4408 Sender Policy Framework (SPF) April 2006
1. Records that do not begin with a version section of exactly
"v=spf1" are discarded. Note that the version section is
terminated either by an SP character or the end of the record. A
record with a version section of "v=spf10" does not match and must
be discarded.
2. If any records of type SPF are in the set, then all records of
type TXT are discarded.
After the above steps, there should be exactly one record remaining
and evaluation can proceed. If there are two or more records
remaining, then check_host() exits immediately with the result of
"PermError".
If no matching records are returned, an SPF client MUST assume that
the domain makes no SPF declarations. SPF processing MUST stop and
return "None".
4.6. Record Evaluation
After one SPF record has been selected, the check_host() function
parses and interprets it to find a result for the current test. If
there are any syntax errors, check_host() returns immediately with
the result "PermError".
Implementations MAY choose to parse the entire record first and
return "PermError" if the record is not syntactically well formed.
However, in all cases, any syntax errors anywhere in the record MUST
be detected.
4.6.1. Term Evaluation
There are two types of terms: mechanisms and modifiers. A record
contains an ordered list of these as specified in the following
Augmented Backus-Naur Form (ABNF).
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
name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." )
Most mechanisms allow a ":" or "/" character after the name.
Wong & Schlitt Experimental [Page 14]
RFC 4408 Sender Policy Framework (SPF) April 2006
Modifiers always contain an equals ('=') character immediately after
the name, and before any ":" or "/" characters that may be part of
the macro-string.
Terms that do not contain any of "=", ":", or "/" are mechanisms, as
defined in Section 5.
As per the definition of the ABNF notation in [RFC4234], 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 specified in Section 4.7.
When a mechanism is evaluated, one of three things can happen: it can
match, not match, or throw 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 throws an exception,
mechanism processing ends and the exception value is returned.
The possible qualifiers, and the results they 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 and the explanation string is computed as
described in Section 6.2.
The specific mechanisms are described in Section 5.
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.
Wong & Schlitt Experimental [Page 15]
RFC 4408 Sender Policy Framework (SPF) April 2006
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.
Note that records SHOULD always 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
Several of these mechanisms and modifiers have a <domain-spec></domain-spec>
section. The <domain-spec> string is macro expanded (see Section 8). </domain-spec>
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. </target-name>
Note: The result of the macro expansion is not subject to any further
escaping. Hence, this facility cannot produce all characters that
are legal in a DNS label (e.g., the control characters). However,
this facility is powerful enough to express legal host names and
common utility labels (such as "_spf") that are used in DNS.
For several mechanisms, the <domain-spec> is optional. If it is not </domain-spec>
provided, the <domain> is used as the <target-name>. </target-name></domain>
5. Mechanism Definitions
This section defines two types of mechanisms.
Basic mechanisms contribute to the language framework. They do not
specify a particular type of authorization scheme.
all
include
Designated sender mechanisms are used to designate a set of <ip></ip>
addresses as being permitted or not permitted to use the <domain> for </domain>
sending mail.
Wong & Schlitt Experimental [Page 16]
RFC 4408 Sender Policy Framework (SPF) April 2006
a
mx
ptr
ip4
ip6
exists
The following conventions apply to all mechanisms that perform a
comparison between <ip> and an IP address at any point: </ip>
If no CIDR-length is given in the directive, then <ip> and the IP </ip>
address are compared for equality. (Here, CIDR is Classless Inter-
Domain Routing.)
If a CIDR-length is specified, then only the specified number of
high-order bits of <ip> and the IP address are compared for equality. </ip>
When any mechanism fetches host addresses to compare with <ip>, when </ip>
<ip> is an IPv4 address, A records are fetched, when <ip> is an IPv6 </ip></ip>
address, AAAA records are fetched. Even if the SMTP connection is
via IPv6, an IPv4-mapped IPv6 IP address (see [RFC3513], Section
2.5.5) MUST still be considered an IPv4 address.
Several mechanisms rely on information fetched from 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
throws the exception "TempError". If the server returns "domain does
not exist" (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. Any "redirect" modifier
(Section 6.1) has no effect when there is an "all" mechanism.
Wong & Schlitt Experimental [Page 17]
RFC 4408 Sender Policy Framework (SPF) April 2006
5.2. "include"
include = "include" ":" domain-spec
The "include" mechanism triggers a recursive evaluation of
check_host(). The domain-spec is expanded as per Section 8. Then
check_host() is evaluated with the resulting string as the <domain>. </domain>
The <ip> and <sender> arguments remain the same as in the current </sender></ip>
evaluation of check_host().
In hindsight, the name "include" was poorly chosen. Only the
evaluated result of the referenced SPF record is used, rather than
acting as if the referenced SPF record was literally included in the
first. For example, evaluating a "-all" directive in the referenced
record does not terminate the overall processing and does not
necessarily result in an overall "Fail". (Better names for this
mechanism would have been "if-pass", "on-pass", etc.)
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".
Wong & Schlitt Experimental [Page 18]
RFC 4408 Sender Policy Framework (SPF) April 2006
Whether this mechanism matches, does not match, or throws an
exception depends on the result of the recursive evaluation of
check_host():
+---------------------------------+---------------------------------+
| A recursive check_host() result | Causes the "include" mechanism |
| of: | to: |
+---------------------------------+---------------------------------+
| Pass | match |
| | |
| Fail | not match |
| | |
| SoftFail | not match |
| | |
| Neutral | not match |
| | |
| TempError | throw TempError |
| | |
| PermError | throw PermError |
| | |
| None | throw PermError |
+---------------------------------+---------------------------------+
The "include" mechanism is intended for crossing administrative
boundaries. Although it is possible to use includes to consolidate
multiple domains that share the same set of designated hosts, domains
are encouraged to use redirects where possible, and to minimize the
number of includes within a single administrative domain. 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".
5.3. "a"
This mechanism matches if <ip> is one of the <target-name>'s IP </target-name></ip>
addresses.
A = "a" [ ":" domain-spec ] [ dual-cidr-length ]
An address lookup is done on the <target-name>. The <ip> is compared </ip></target-name>
to the returned address(es). If any address matches, the mechanism
matches.
Wong & Schlitt Experimental [Page 19]
RFC 4408 Sender Policy Framework (SPF) April 2006
5.4. "mx"
This mechanism matches if <ip> is one of the MX hosts for a domain </ip>
name.
MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ]
check_host() first performs an MX lookup on the <target-name>. Then </target-name>
it performs an address lookup on each MX name returned. The <ip> is </ip>
compared to each returned IP address. To prevent Denial of Service
(DoS) attacks, more than 10 MX names MUST NOT be looked up during the
evaluation of an "mx" mechanism (see Section 10). If any address
matches, the mechanism matches.
Note regarding implicit MXs: If the <target-name> has no MX records, </target-name>
check_host() MUST NOT pretend the target is its single MX, and MUST
NOT default to an A lookup on the <target-name> directly. This </target-name>
behavior breaks with the legacy "implicit MX" rule. See [RFC2821],
Section 5. If such behavior is desired, the publisher should specify
an "a" directive.
5.5. "ptr"
This mechanism tests whether the DNS reverse-mapping for <ip> exists </ip>
and correctly points to a domain name within a particular domain.
PTR = "ptr" [ ":" domain-spec ]
First, the <ip>'s name is looked up using this procedure: perform a </ip>
DNS reverse-mapping for <ip>, looking up the corresponding PTR record </ip>
in "in-addr.arpa." if the address is an IPv4 one and in "ip6.arpa."
if it is an IPv6 address. For each record returned, validate the
domain name by looking up its IP address. To prevent DoS attacks,
more than 10 PTR names MUST NOT be looked up during the evaluation of
a "ptr" mechanism (see Section 10). If <ip> is among the returned IP </ip>
addresses, then that domain name is validated. In pseudocode:
sending-domain_names := ptr_lookup(sending-host_IP); if more than 10
sending-domain_names are found, use at most 10. for each name in
(sending-domain_names) {
IP_addresses := a_lookup(name);
if the sending-domain_IP is one of the IP_addresses {
validated-sending-domain_names += name;
} }
Check all validated domain names to see if they end in the
<target-name> domain. If any do, this mechanism matches. If no </target-name>
validated domain name can be found, or if none of the validated
Wong & Schlitt Experimental [Page 20]
RFC 4408 Sender Policy Framework (SPF) April 2006
domain names end in the <target-name>, this mechanism fails to match. </target-name>
If a DNS error occurs while doing the PTR RR lookup, then this
mechanism fails to match. If a DNS error occurs while doing an A RR
lookup, then that domain name is skipped and the search continues.
Pseudocode:
for each name in (validated-sending-domain_names) {
if name ends in <domain-spec>, return match. </domain-spec>
if name is <domain-spec>, return match. </domain-spec>
}
return no-match.
This mechanism matches if the <target-name> is either an ancestor of </target-name>
a validated domain name or if the <target-name> and a validated </target-name>
domain name are the same. For example: "mail.example.com" is within
the domain "example.com", but "mail.bad-example.com" is not.
Note: Use of this mechanism is discouraged because it is slow, it is
not as reliable as other mechanisms in cases of DNS errors, and it
places a large burden on the arpa name servers. If used, proper PTR
records must be in place for the domain's hosts and the "ptr"
mechanism should be one of the last mechanisms checked.
5.6. "ip4" and "ip6"
These mechanisms test whether <ip> is contained within a given IP </ip>
network.
IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ]
IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ]
ip4-cidr-length = "/" 1*DIGIT
ip6-cidr-length = "/" 1*DIGIT
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 section per></as>
; e.g., 2001:DB8::CD30
The <ip> is compared to the given network. If CIDR-length high-order </ip>
bits match, the mechanism matches.
Wong & Schlitt Experimental [Page 21]
RFC 4408 Sender Policy Framework (SPF) April 2006
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. "exists"
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 domain-spec is expanded as per Section 8. The resulting domain
name is used for a DNS A RR lookup. If any A record is returned,
this mechanism matches. The lookup type is A even when the
connection type is IPv6.
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 </target-name>
"1.2.0.192.someuser._spf.example.com". This makes fine-grained
decisions possible at the level of the user and client IP address.
This mechanism enables queries that mimic the style of tests that
existing anti-spam DNS blacklists (DNSBL) use.
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") MAY
appear anywhere in the record, but SHOULD appear at the end, after
all mechanisms. 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 in a record,
or how often. This allows implementations of this document to
gracefully handle records with modifiers that are defined in other
specifications.
Wong & Schlitt Experimental [Page 22]
RFC 4408 Sender Policy Framework (SPF) April 2006
6.1. redirect: Redirected Query
If all mechanisms fail to match, and a "redirect" modifier is
present, then processing proceeds as follows:
redirect = "redirect" "=" domain-spec
The domain-spec portion of the redirect section is expanded as per
the macro rules in Section 8. Then check_host() is evaluated with
the resulting string as the <domain>. The <ip> and <sender></sender></ip></domain>
arguments remain the same as 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 may 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 </sender>
domain "B" will correctly work for mailboxes in domain "A",
especially if domain "B" uses mechanisms involving localparts. An
"include" directive may be more appropriate.
For clarity, it is RECOMMENDED that any "redirect" modifier appear as
the very last term in a record.
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
Wong & Schlitt Experimental [Page 23]
RFC 4408 Sender Policy Framework (SPF) April 2006
is present, then either a default explanation string or an empty
explanation string may be returned.
The <domain-spec> is macro expanded (see Section 8) and becomes the </domain-spec>
<target-name>. The DNS TXT record for the <target-name> is fetched. </target-name></target-name>
If <domain-spec> is empty, or there are any DNS processing errors </domain-spec>
(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 </explain-string>
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 [RFC2821]
Section 2.4 says that responses are in [US-ASCII], the explanation
string is also 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, such as shown in Section
2.5.4.
Suppose example.com has this record:
v=spf1 mx -all exp=explain._spf.%{d}
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
Note: During recursion into an "include" mechanism, an exp= modifier
from the <target-name> MUST NOT be used. In contrast, when executing </target-name>
Wong & Schlitt Experimental [Page 24]
RFC 4408 Sender Policy Framework (SPF) April 2006
a "redirect" modifier, an exp= modifier from the original domain MUST
NOT be used.
7. The Received-SPF Header Field
It is RECOMMENDED that SMTP receivers record the result of SPF
processing in the message header. If an SMTP receiver chooses to do
so, it SHOULD use the "Received-SPF" header field defined here for
each identity that was checked. This information is intended for the
recipient. (Information intended for the sender is described in
Section 6.2, Explanation.)
The Received-SPF header field is a trace field (see [RFC2822] 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 / "x-" name / name
identity = "mailfrom" ; for the "MAIL FROM" identity
/ "helo" ; for the "HELO" identity
/ name ; other identities
dot-atom = <unquoted per as word></unquoted>
quoted-string = <quoted per as string></quoted>
comment = <comment per as string></comment>
CFWS = <comment or folding white space as per></comment>
<