idnits 2.17.1 draft-ietf-spfbis-4408bis-06.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- == There are 1 instance of lines with non-RFC2606-compliant FQDNs in the document. == There are 6 instances of lines with non-RFC6890-compliant IPv4 addresses in the document. If these are example addresses, they should be changed. == There are 1 instance of lines with private range IPv4 addresses in the document. If these are generic example addresses, they should be changed to use any of the ranges defined in RFC 6890 (or successor): 192.0.2.x, 198.51.100.x or 203.0.113.x. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 1342 has weird spacing: '...pe-from the e...' == The document seems to contain a disclaimer for pre-RFC5378 work, but was first submitted on or after 10 November 2008. The disclaimer is usually necessary only for documents that revise or obsolete older RFCs, and that take significant amounts of text from those RFCs. If you can contact all authors of the source material and they are willing to grant the BCP78 rights to the IETF Trust, you can and should remove the disclaimer. Otherwise, the disclaimer is needed and you can ignore this comment. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (August 23, 2012) is 4254 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: 'CFWS' is mentioned on line 2387, but not defined ** Obsolete normative reference: RFC 5451 (Obsoleted by RFC 7001) ** Downref: Normative reference to an Informational RFC: RFC 5598 -- Possible downref: Non-RFC (?) normative reference: ref. 'US-ASCII' -- Obsolete informational reference (is this intentional?): RFC 4408 (Obsoleted by RFC 7208) -- Obsolete informational reference (is this intentional?): RFC 5751 (Obsoleted by RFC 8551) Summary: 2 errors (**), 0 flaws (~~), 7 warnings (==), 4 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group S. Kitterman 3 Internet-Draft Kitterman Technical Services 4 Obsoletes: 4408 (if approved) August 23, 2012 5 Intended status: Standards Track 6 Expires: February 24, 2013 8 Sender Policy Framework (SPF) for Authorizing Use of Domains in Email, 9 Version 1 10 draft-ietf-spfbis-4408bis-06.txt 12 Abstract 14 Email on the Internet can be forged in a number of ways. In 15 particular, existing protocols place no restriction on what a sending 16 host can use as the "MAIL FROM" of a message or the domain given on 17 the SMTP HELO/EHLO commands. This document describes version 1 of 18 the Sender Policy Framework (SPF) protocol, whereby an ADMD can 19 explicitly authorize the hosts that are allowed to use its domain 20 names, and a receiving host can check such authorization. 22 This document obsoletes RFC4408. 24 Status of this Memo 26 This Internet-Draft is submitted in full conformance with the 27 provisions of BCP 78 and BCP 79. 29 Internet-Drafts are working documents of the Internet Engineering 30 Task Force (IETF). Note that other groups may also distribute 31 working documents as Internet-Drafts. The list of current Internet- 32 Drafts is at http://datatracker.ietf.org/drafts/current/. 34 Internet-Drafts are draft documents valid for a maximum of six months 35 and may be updated, replaced, or obsoleted by other documents at any 36 time. It is inappropriate to use Internet-Drafts as reference 37 material or to cite them other than as "work in progress." 39 This Internet-Draft will expire on February 24, 2013. 41 Copyright Notice 43 Copyright (c) 2012 IETF Trust and the persons identified as the 44 document authors. All rights reserved. 46 This document is subject to BCP 78 and the IETF Trust's Legal 47 Provisions Relating to IETF Documents 48 (http://trustee.ietf.org/license-info) in effect on the date of 49 publication of this document. Please review these documents 50 carefully, as they describe your rights and restrictions with respect 51 to this document. Code Components extracted from this document must 52 include Simplified BSD License text as described in Section 4.e of 53 the Trust Legal Provisions and are provided without warranty as 54 described in the Simplified BSD License. 56 This document may contain material from IETF Documents or IETF 57 Contributions published or made publicly available before November 58 10, 2008. The person(s) controlling the copyright in some of this 59 material may not have granted the IETF Trust the right to allow 60 modifications of such material outside the IETF Standards Process. 61 Without obtaining an adequate license from the person(s) controlling 62 the copyright in such materials, this document may not be modified 63 outside the IETF Standards Process, and derivative works of it may 64 not be created outside the IETF Standards Process, except to format 65 it for publication as an RFC or to translate it into languages other 66 than English. 68 Table of Contents 70 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 6 71 1.1. Protocol Status . . . . . . . . . . . . . . . . . . . . . 6 72 1.2. Experimental History . . . . . . . . . . . . . . . . . . . 7 73 1.3. Terminology . . . . . . . . . . . . . . . . . . . . . . . 7 74 1.3.1. Keywords . . . . . . . . . . . . . . . . . . . . . . . 7 75 1.3.2. Imported Definitions . . . . . . . . . . . . . . . . . 7 76 1.3.3. Mail From Definition . . . . . . . . . . . . . . . . . 7 77 1.3.4. HELO Definition . . . . . . . . . . . . . . . . . . . 8 78 1.3.5. Deprecated . . . . . . . . . . . . . . . . . . . . . . 8 79 2. Operation . . . . . . . . . . . . . . . . . . . . . . . . . . 9 80 2.1. The "HELO" Identity . . . . . . . . . . . . . . . . . . . 9 81 2.2. The "MAIL FROM" Identity . . . . . . . . . . . . . . . . . 9 82 2.3. Publishing Authorization . . . . . . . . . . . . . . . . . 9 83 2.4. Checking Authorization . . . . . . . . . . . . . . . . . . 10 84 2.5. Interpreting the Result . . . . . . . . . . . . . . . . . 11 85 2.5.1. None . . . . . . . . . . . . . . . . . . . . . . . . . 12 86 2.5.2. Neutral . . . . . . . . . . . . . . . . . . . . . . . 12 87 2.5.3. Pass . . . . . . . . . . . . . . . . . . . . . . . . . 12 88 2.5.4. Fail . . . . . . . . . . . . . . . . . . . . . . . . . 12 89 2.5.5. Softfail . . . . . . . . . . . . . . . . . . . . . . . 13 90 2.5.6. TempError . . . . . . . . . . . . . . . . . . . . . . 13 91 2.5.7. PermError . . . . . . . . . . . . . . . . . . . . . . 13 92 3. SPF Records . . . . . . . . . . . . . . . . . . . . . . . . . 14 93 3.1. DNS Resource Records . . . . . . . . . . . . . . . . . . . 14 94 3.2. Multiple DNS Records . . . . . . . . . . . . . . . . . . . 14 95 3.3. Multiple Strings in a Single DNS record . . . . . . . . . 15 96 3.4. Record Size . . . . . . . . . . . . . . . . . . . . . . . 15 97 3.5. Wildcard Records . . . . . . . . . . . . . . . . . . . . . 15 98 4. The check_host() Function . . . . . . . . . . . . . . . . . . 17 99 4.1. Arguments . . . . . . . . . . . . . . . . . . . . . . . . 17 100 4.2. Results . . . . . . . . . . . . . . . . . . . . . . . . . 17 101 4.3. Initial Processing . . . . . . . . . . . . . . . . . . . . 17 102 4.4. Record Lookup . . . . . . . . . . . . . . . . . . . . . . 18 103 4.5. Selecting Records . . . . . . . . . . . . . . . . . . . . 18 104 4.6. Record Evaluation . . . . . . . . . . . . . . . . . . . . 18 105 4.6.1. Term Evaluation . . . . . . . . . . . . . . . . . . . 19 106 4.6.2. Mechanisms . . . . . . . . . . . . . . . . . . . . . . 19 107 4.6.3. Modifiers . . . . . . . . . . . . . . . . . . . . . . 20 108 4.6.4. DNS Lookup Limits . . . . . . . . . . . . . . . . . . 20 109 4.7. Default Result . . . . . . . . . . . . . . . . . . . . . . 21 110 4.8. Domain Specification . . . . . . . . . . . . . . . . . . . 21 111 5. Mechanism Definitions . . . . . . . . . . . . . . . . . . . . 22 112 5.1. "all" . . . . . . . . . . . . . . . . . . . . . . . . . . 23 113 5.2. "include" . . . . . . . . . . . . . . . . . . . . . . . . 23 114 5.3. "a" . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 115 5.4. "mx" . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 116 5.5. "ptr" (deprecated) . . . . . . . . . . . . . . . . . . . . 25 117 5.6. "ip4" and "ip6" . . . . . . . . . . . . . . . . . . . . . 27 118 5.7. "exists" . . . . . . . . . . . . . . . . . . . . . . . . . 27 119 6. Modifier Definitions . . . . . . . . . . . . . . . . . . . . . 29 120 6.1. redirect: Redirected Query . . . . . . . . . . . . . . . . 29 121 6.2. exp: Explanation . . . . . . . . . . . . . . . . . . . . . 30 122 7. Recording The Result . . . . . . . . . . . . . . . . . . . . . 32 123 7.1. The Received-SPF Header Field . . . . . . . . . . . . . . 32 124 7.2. SPF Results in the Authentication-Results Header Field . . 34 125 8. Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 126 8.1. Macro Definitions . . . . . . . . . . . . . . . . . . . . 36 127 8.2. Expansion Examples . . . . . . . . . . . . . . . . . . . . 39 128 9. Implications . . . . . . . . . . . . . . . . . . . . . . . . . 41 129 9.1. Sending Domains . . . . . . . . . . . . . . . . . . . . . 41 130 9.1.1. DNS Resource Considerations . . . . . . . . . . . . . 41 131 9.1.2. Administrator's Considerations . . . . . . . . . . . . 42 132 9.1.3. Bounces . . . . . . . . . . . . . . . . . . . . . . . 43 133 9.2. Mediators . . . . . . . . . . . . . . . . . . . . . . . . 43 134 9.2.1. Mailing Lists . . . . . . . . . . . . . . . . . . . . 43 135 9.2.2. Forwarding Services and Aliases . . . . . . . . . . . 44 136 9.2.3. Mail Services . . . . . . . . . . . . . . . . . . . . 46 137 9.2.4. MTA Relays . . . . . . . . . . . . . . . . . . . . . . 46 138 9.3. Receivers . . . . . . . . . . . . . . . . . . . . . . . . 47 139 9.3.1. Policy For SPF Pass . . . . . . . . . . . . . . . . . 47 140 9.3.2. Policy For SPF Fail . . . . . . . . . . . . . . . . . 47 141 9.3.3. Policy For SPF Permerror . . . . . . . . . . . . . . . 48 142 10. Security Considerations . . . . . . . . . . . . . . . . . . . 49 143 10.1. Processing Limits . . . . . . . . . . . . . . . . . . . . 49 144 10.2. SPF-Authorized Email May Contain Other False Identities . 49 145 10.3. Spoofed DNS and IP Data . . . . . . . . . . . . . . . . . 50 146 10.4. Cross-User Forgery . . . . . . . . . . . . . . . . . . . . 50 147 10.5. Untrusted Information Sources . . . . . . . . . . . . . . 50 148 10.5.1. Recorded Results . . . . . . . . . . . . . . . . . . . 50 149 10.5.2. External Explanations . . . . . . . . . . . . . . . . 51 150 10.5.3. Macro Expansion . . . . . . . . . . . . . . . . . . . 51 151 10.6. Privacy Exposure . . . . . . . . . . . . . . . . . . . . . 51 152 11. Contributors and Acknowledgements . . . . . . . . . . . . . . 52 153 12. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 53 154 12.1. The SPF DNS Record Type . . . . . . . . . . . . . . . . . 53 155 12.2. The Received-SPF Mail Header Field . . . . . . . . . . . . 53 156 12.3. SPF Modifier Registration . . . . . . . . . . . . . . . . 53 157 13. References . . . . . . . . . . . . . . . . . . . . . . . . . . 54 158 13.1. Normative References . . . . . . . . . . . . . . . . . . . 54 159 13.2. Informative References . . . . . . . . . . . . . . . . . . 55 160 Appendix A. Collected ABNF . . . . . . . . . . . . . . . . . . . 57 161 Appendix B. Extended Examples . . . . . . . . . . . . . . . . . . 60 162 B.1. Simple Examples . . . . . . . . . . . . . . . . . . . . . 60 163 B.2. Multiple Domain Example . . . . . . . . . . . . . . . . . 61 164 B.3. DNSBL Style Example . . . . . . . . . . . . . . . . . . . 62 165 B.4. Multiple Requirements Example . . . . . . . . . . . . . . 62 166 Appendix C. Change History . . . . . . . . . . . . . . . . . . . 63 167 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 66 169 1. Introduction 171 The current email infrastructure has the property that any host 172 injecting mail into the system can use any DNS domain name it wants 173 in each of the various identifiers specified by [RFC5321] and 174 [RFC5322]. Although this feature is desirable in some circumstances, 175 it is a major obstacle to reducing Unsolicited Bulk Email (UBE, aka 176 spam). Furthermore, many domain owning ADMDs (ADministrative 177 Management Domains, see [RFC5598]) are understandably concerned about 178 the ease with which other entities can make use of their domain 179 names, often with malicious intent. 181 This document defines a protocol by which ADMDs can authorize hosts 182 to use their domain names in the "MAIL FROM" or "HELO" identities. 183 Compliant ADMDs publish Sender Policy Framework (SPF) records in the 184 DNS specifying which hosts are permitted to use their names, and 185 compliant mail receivers use the published SPF records to test the 186 authorization of sending Mail Transfer Agents (MTAs) using a given 187 "HELO" or "MAIL FROM" identity during a mail transaction. 189 An additional benefit to mail receivers is that after the use of an 190 identity is verified, local policy decisions about the mail can be 191 made based on the sender's domain, rather than the host's IP address. 192 This is advantageous because reputation of domain names is likely to 193 be more accurate than reputation of host IP addresses. Furthermore, 194 if a claimed identity fails verification, local policy can take 195 stronger action against such email, such as rejecting it. 197 1.1. Protocol Status 199 SPF has been in development since the summer of 2003 and has seen 200 deployment beyond the developers beginning in December 2003. The 201 design of SPF slowly evolved until the spring of 2004 and has since 202 stabilized. There have been quite a number of forms of SPF, some 203 written up as documents, some submitted as Internet Drafts, and many 204 discussed and debated in development forums. The protocol was 205 originally defined in [RFC4408], which this document replaces. 207 The goal of this work is to clearly document the protocol defined by 208 earlier draft specifications of SPF as used in existing 209 implementations. This conception of SPF is sometimes called "SPF 210 Classic". It is understood that particular implementations and 211 deployments will differ from, and build upon, this work. It is hoped 212 that we have nonetheless captured the common understanding of SPF 213 version 1. 215 1.2. Experimental History 217 This document updates and replaces RFC 4408 that was part of a group 218 of simultaneously published Experimental RFCs (RFC 4405, RFC 4406, 219 RFC 4407, and RFC 4408) in 2006. At that time the IESG requested the 220 community observe the success or failure of the two approaches 221 documented in these RFCs during the two years following publication, 222 in order that a community consensus could be reached in the future. 224 SPF is widely deployed by large and small email providers alike. 225 There are multiple, interoperable implementations. 227 For SPF (as documented in RFC 4408) a careful effort was made to 228 collect and document lessons learned and errata during the two year 229 period. The errata list has been stable (no new submissions) and 230 only minor protocol lessons learned were identified. Resolution of 231 the IESG's experiment is documented in [RFC6686]. 233 1.3. Terminology 235 1.3.1. Keywords 237 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 238 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 239 "OPTIONAL" in this document are to be interpreted as described in 240 [RFC2119]. 242 1.3.2. Imported Definitions 244 The ABNF tokens "ALPHA", "DIGIT", and "SP" are defined in [RFC5234]. 246 The token "local-part" is defined in [RFC5321]. 248 "dot-atom", "quoted-string", "comment", "CFWS", "FWS", and "CRLF" are 249 defined in [RFC5322]. 251 1.3.3. Mail From Definition 253 This document is concerned with the portion of a mail message 254 commonly called "envelope sender", "return path", "reverse path", 255 "bounce address", "5321 FROM", "MAIL FROM", or RFC5321.MailFrom. 256 Since these terms are either not well defined or often used casually, 257 this document uses "MAIL FROM" for consistency. This means the 258 RFC5321.MailFrom as defined in [RFC5598]. Note that other terms that 259 might superficially look like the common terms, such as "reverse- 260 path", are used only with the defined meanings from normative 261 documents. 263 1.3.4. HELO Definition 265 This document also makes use of the HELO/EHLO identity. The "HELO" 266 identity derives from either the SMTP HELO or EHLO command (see 267 [RFC5321]). Since HELO and EHLO can, in many cases, be used 268 interchangeably, they are identified commonly as "HELO" in this 269 document. This means RFC5321.HELO/.EHLO as defined in [RFC5598]. 270 These commands supply the identity of the SMTP client (sending host) 271 for the SMTP session. 273 1.3.5. Deprecated 275 There are [RFC4408] features that are marked "deprecated". In the 276 context of this document, deprecated means that senders SHOULD NOT 277 publish SPF records that make use of such features because they might 278 be removed entirely in future updates to the protocol. Such features 279 do, however, remain part of the SPF protocol and receiving systems 280 MUST support them unless this document explicitly says otherwise. 282 2. Operation 284 2.1. The "HELO" Identity 286 It is RECOMMENDED that SPF verifiers not only check the "MAIL FROM" 287 identity, but also separately check the "HELO" identity by applying 288 the check_host() function (Section 4) to the "HELO" identity as the 289 . Checking "HELO" promotes consistency of results and can 290 reduce DNS resource usage. Additionally, since SPF records published 291 for "HELO" identities refer to a single host, when available, they 292 are a very reliable source of host authorization status. 294 Note that requirements for the domain presented in the EHLO or HELO 295 command are not always clear to the sending party, and SPF verifiers 296 MUST be prepared for the "HELO" identity to be malformed or an IP 297 address literal. This SPF check can only be performed when the 298 "HELO" string is a valid fully qualified domain. 300 2.2. The "MAIL FROM" Identity 302 SPF verifiers MUST check the ""MAIL FROM" identity if a completed 303 "HELO" check has not reached a definitive policy result by applying 304 the check_host() function to the "MAIL FROM" identity as the 305 . 307 [RFC5321] allows the reverse-path to be null (see Section 4.5.5 in 308 [RFC5321]). In this case, there is no explicit sender mailbox, and 309 such a message can be assumed to be a notification message from the 310 mail system itself. When the reverse-path is null, this document 311 defines the "MAIL FROM" identity to be the mailbox composed of the 312 local-part "postmaster" and the "HELO" identity (which might or might 313 not have been checked separately before). 315 2.3. Publishing Authorization 317 An SPF-compliant domain MUST have valid SPF records as described in 318 Section 3. These records authorize the use of the relevant domain 319 names in the "HELO" and "MAIL FROM" identities by the MTAs specified 320 therein. 322 SPF results can be used to make both positive (source is authorized) 323 and negative (source is not authorized) determinations. If domain 324 owners choose to publish SPF records and want to support receivers 325 making negative authorization determinations, then they MUST publish 326 records that end in "-all", or redirect to other records that do, 327 otherwise, no definitive determination of authorization can be made. 328 Potential issues and mitigations associated with negative 329 determinations are discussed in Section 9. 331 ADMDs can publish SPF records that explicitly authorize no hosts for 332 domain names that are neither used in the domain part of email 333 addresses nor expected to originate mail. 335 When changing SPF records, care has to be taken to ensure that there 336 is a transition period so that the old policy remains valid until all 337 legitimate email can reasonably expect to have been checked. This 338 can be as much as 30 days. 340 2.4. Checking Authorization 342 A mail receiver can perform a set of SPF checks for each mail message 343 it receives. An SPF check tests the authorization of a client host 344 to emit mail with a given identity. Typically, such checks are done 345 by a receiving MTA, but can be performed elsewhere in the mail 346 processing chain so long as the required information is available and 347 reliable. At least the "MAIL FROM" identity MUST be checked, but it 348 is RECOMMENDED that the "HELO" identity also be checked beforehand. 350 Without explicit approval of the domain owner, checking other 351 identities against SPF version 1 records is NOT RECOMMENDED because 352 there are cases that are known to give incorrect results. For 353 example, almost all mailing lists rewrite the "MAIL FROM" identity 354 (see Section 9.2.1), but some do not change any other identities in 355 the message. The scenario described in Section 9.2.2, sub-section 356 1.2, is another example. Documents that define other identities will 357 have to define the method for explicit approval. 359 It is possible that mail receivers will use the SPF check as part of 360 a larger set of tests on incoming mail. The results of other tests 361 might influence whether or not a particular SPF check is performed. 362 For example, finding the sending host's IP address on a local white 363 list might cause all other tests to be skipped and all mail from that 364 host to be accepted. 366 When a mail receiver decides to perform an SPF check, it MUST use a 367 correctly-implemented check_host() function (Section 4) evaluated 368 with the correct parameters. Although the test as a whole is 369 optional, once it has been decided to perform a test it MUST be 370 performed as specified so that the correct semantics are preserved 371 between publisher and receiver. 373 To make the test, the mail receiver MUST evaluate the check_host() 374 function with the arguments set as follows: 376 - the IP address of the SMTP client that is emitting the 377 mail, either IPv4 or IPv6. 379 - the domain portion of the "MAIL FROM" or "HELO" identity. 381 - the "MAIL FROM" or "HELO" identity. 383 Note that the argument might not be a well-formed domain 384 name. For example, if the reverse-path was null, then the EHLO/HELO 385 domain is used, with its associated problems (see Section 2.1). In 386 these cases, check_host() is defined in Section 4.3 to return a 387 "none" result. 389 Although invalid, malformed, or non-existent domains cause SPF checks 390 to return "none" because no SPF record can be found, it has long been 391 the policy of many MTAs to reject email from such domains, especially 392 in the case of invalid "MAIL FROM". Rejecting email will prevent one 393 method of circumventing of SPF records. 395 Implementations MUST take care to correctly extract the from 396 the data given with the SMTP MAIL FROM command as many MTAs will 397 still accept such things as source routes (see [RFC5321], Appendix 398 C), the %-hack (see [RFC1123]), and bang paths (see [RFC1983]). 399 These archaic features have been maliciously used to bypass security 400 systems. 402 2.5. Interpreting the Result 404 This section describes how software that performs the authorization 405 interprets the results of the check_host() function. The 406 authorization check SHOULD be performed during the processing of the 407 SMTP transaction that sends the mail. This allows errors to be 408 returned directly to the sending MTA by way of SMTP replies. 410 Performing the authorization other than using the return-path and 411 client address at the time of the MAIL command during the SMTP 412 transaction can cause problems, such as the following: (1) It might 413 be difficult to accurately extract the required information from 414 potentially deceptive headers; (2) legitimate email might fail 415 because the sender's policy had since changed. 417 Generating non-delivery notifications to forged identities that have 418 failed the authorization check is a source of backscatter and SHOULD 419 be avoided. [RFC3834] section 2 describes backscatter and the 420 problems it causes. 422 2.5.1. None 424 A result of "none" means either (a) no syntactically valid DNS domain 425 name was extracted from the SMTP session that could be used as the 426 one to be authorized, or (b) no TXT records were retrieved from the 427 DNS that appeared to be intended for use by SPF verifiers. 429 2.5.2. Neutral 431 The domain owner has explicitly stated that they cannot or do not 432 want to assert whether the IP address is authorized or not. A 433 "neutral" result MUST be treated exactly like the "none" result; the 434 distinction exists only for informational purposes. Treating 435 "neutral" more harshly than "none" would discourage domain owners 436 from testing the use of SPF records (see Section 9.1). 438 2.5.3. Pass 440 A "pass" result means that the client is authorized to inject mail 441 with the given identity. The domain can now, in the sense of 442 reputation, be considered responsible for sending the message. 443 Further policy checks can now proceed with confidence in the 444 legitimate use of the identity. This is further discussed in 445 Section 9.3.1. 447 2.5.4. Fail 449 A "fail" result is an explicit statement that the client is not 450 authorized to use the domain in the given identity. Disposition of 451 SPF fail messages is a matter of local policy. See Section 9.3.2 for 452 considerations on developing local policy. 454 If the checking software chooses to reject the mail during the SMTP 455 transaction, then it SHOULD use an SMTP reply code of 550 (see 456 [RFC5321]) and, if supported, the 5.7.1 enhanced status code (see 457 [RFC3463]), in addition to an appropriate reply text. The 458 check_host() function will return either a default explanation string 459 or one from the domain that published the SPF records (see 460 Section 6.2). If the information does not originate with the 461 checking software, it should be made clear that the text is provided 462 by the sender's domain. For example: 464 550-5.7.1 SPF MAIL FROM check failed: 465 550-5.7.1 The domain example.com explains: 466 550 5.7.1 Please see http://www.example.com/mailpolicy.html 468 If the checking software chooses not to reject the mail during the 469 SMTP transaction, then it SHOULD add a Received-SPF or 470 Authentication-Results header field (see Section 7) to communicate 471 this result to downstream message processors. While this is true for 472 all SPF results, it is of particular importance for "fail" results 473 since the message is explicitly not authorized by the domain owner. 475 2.5.5. Softfail 477 A "softfail" result ought to be treated as somewhere between "fail" 478 and "neutral"/"none". The domain owner believes the host is not 479 authorized but is not willing to make a strong policy statement. 480 Receiving software SHOULD NOT reject the message based solely on this 481 result, but MAY subject the message to closer scrutiny than normal. 483 The domain owner wants to discourage the use of this host and thus 484 desires limited feedback when a "softfail" result occurs. For 485 example, the recipient's Mail User Agent (MUA) could highlight the 486 "softfail" status, or the receiving MTA could give the sender a 487 message using greylisting, [RFC6647], with a note the first time the 488 message is received, but accept it on a later attempt based on 489 receiver policy. 491 2.5.6. TempError 493 A "temperror" result means the SPF verifier encountered a transient 494 (DNS) error while performing the check. Checking software can choose 495 to accept or temporarily reject the message. If the message is 496 rejected during the SMTP transaction for this reason, the software 497 SHOULD use an SMTP reply code of 451 and, if supported, the 4.4.3 498 enhanced status code. These errors can be caused by problems in 499 either the sender's or receiver's DNS software. 501 2.5.7. PermError 503 A "permerror" result means the domain's published records could not 504 be correctly interpreted. This signals an error condition that 505 definitely requires manual intervention to be resolved. If the 506 message is rejected during the SMTP transaction for this reason, the 507 software SHOULD use an SMTP reply code of 550 and, if supported, the 508 5.5.2 enhanced status code. Be aware that if the domain owner uses 509 macros (Section 8), it is possible that this result is due to the 510 checked identities having an unexpected format. 512 3. SPF Records 514 An SPF record is a DNS TXT (type 16) Resource Record (RR) that 515 declares which hosts are, and are not, authorized to use a domain 516 name for the "HELO" and "MAIL FROM" identities. Loosely, the record 517 partitions all hosts into permitted and not-permitted sets (though 518 some hosts might fall into neither category). 520 The SPF record is a single string of text. An example record is the 521 following: 523 v=spf1 +mx a:colo.example.com/28 -all 525 This record has a version of "spf1" and three directives: "+mx", 526 "a:colo.example.com/28" (the + is implied), and "-all". 528 Each SPF record is placed in the DNS tree at the host name it 529 pertains to, not a subdomain under it, such as is done with SRV 530 records [RFC2782]. 532 The example in Section 3 might be published via these lines in a 533 domain zone file: 535 example.com. TXT "v=spf1 +mx a:colo.example.com/28 -all" 536 smtp-out.example.com. TXT "v=spf1 a -all" 538 Since TXT records have multiple uses, beware of other TXT records 539 published there for other purposes. They might cause problems with 540 size limits (see Section 3.4) and care MUST be taken to ensure only 541 SPF records are used for SPF processing. 543 ADMDs publishing SPF records SHOULD try to keep the number of 544 "include" mechanisms and chained "redirect" modifiers to a minimum. 545 ADMDs SHOULD also try to minimize the amount of other DNS information 546 needed to evaluate a record. Section 4.6.4 and Section 9.1.1 provide 547 some suggestions on how to achieve this. 549 3.1. DNS Resource Records 551 SPF records MUST be published as type TXT [RFC1035]. The character 552 content of the record is encoded as [US-ASCII]. Use of alternate DNS 553 RR types was supported in SPF's experimental phase, but has been 554 discontinued. See Appendix A of [RFC6686] for further information. 556 3.2. Multiple DNS Records 558 A domain name MUST NOT have multiple records that would cause an 559 authorization check to select more than one record. See Section 4.5 560 for the selection rules. 562 3.3. Multiple Strings in a Single DNS record 564 As defined in [RFC1035] sections 3.3.14 and 3.3, a single text DNS 565 record can be composed of more than one string. If a published 566 record contains multiple character-strings, then the record MUST be 567 treated as if those strings are concatenated together without adding 568 spaces. For example: 570 IN TXT "v=spf1 .... first" "second string..." 572 MUST be treated as equivalent to 574 IN TXT "v=spf1 .... firstsecond string..." 576 TXT records containing multiple strings are useful in constructing 577 records that would exceed the 255-byte maximum length of a character- 578 string within a single TXT record. 580 3.4. Record Size 582 The published SPF record for a given domain name SHOULD remain small 583 enough that the results of a query for it will fit within 512 octets. 584 This UDP limit is defined in [RFC1035] section 2.3.4. This will keep 585 even older DNS implementations from falling over to TCP. Since the 586 answer size is dependent on many things outside the scope of this 587 document, it is only possible to give this guideline: If the combined 588 length of the DNS name and the text of all the records of a given 589 type is under 450 characters, then DNS answers ought to fit in UDP 590 packets. Note that when computing the sizes for queries of the TXT 591 format, one MUST take into account any other TXT records published at 592 the domain name. Records that are too long to fit in a single UDP 593 packet could be silently ignored by SPF verifiers due to firewall and 594 other issues that cause DNS over TCP to be less reliable than DNS 595 over UDP. 597 3.5. Wildcard Records 599 Use of wildcard records for publishing is NOT RECOMMENDED. Care has 600 to be taken if wildcard records are used. If a zone includes 601 wildcard MX records, it might want to publish wildcard declarations, 602 subject to the same requirements and problems. In particular, the 603 declaration MUST be repeated for any host that has any RR records at 604 all, and for subdomains thereof. Consider the example in [RFC1034], 605 Section 4.3.3. Based on that, we can do the following: 607 EXAMPLE.COM. MX 10 A.EXAMPLE.COM 608 EXAMPLE.COM. TXT "v=spf1 a:A.EXAMPLE.COM -all" 610 *.EXAMPLE.COM. MX 10 A.EXAMPLE.COM 611 *.EXAMPLE.COM. TXT "v=spf1 a:A.EXAMPLE.COM -all" 613 A.EXAMPLE.COM. A 203.0.113.1 614 A.EXAMPLE.COM. MX 10 A.EXAMPLE.COM 615 A.EXAMPLE.COM. TXT "v=spf1 a:A.EXAMPLE.COM -all" 617 *.A.EXAMPLE.COM. MX 10 A.EXAMPLE.COM 618 *.A.EXAMPLE.COM. TXT "v=spf1 a:A.EXAMPLE.COM -all" 620 SPF records MUST be listed twice for every name within the zone: once 621 for the name, and once with a wildcard to cover the tree under the 622 name, in order to cover all domains in use in outgoing mail. 624 4. The check_host() Function 626 This description is not an API (Application Program Interface) 627 definition, but rather a function description used to illustrate the 628 algorithm. A compliant SPF implementation MUST do something 629 semantically equivalent to this description. 631 The check_host() function fetches SPF records, parses them, and 632 evaluates them to determine whether a particular host is or is not 633 permitted to send mail with a given identity. Mail receivers that 634 perform this check MUST correctly evaluate the check_host() function 635 as described here. 637 Implementations MAY use a different algorithm than the canonical 638 algorithm defined here, so long as the results are the same in all 639 cases. 641 4.1. Arguments 643 The check_host() function takes these arguments: 645 - the IP address of the SMTP client that is emitting the 646 mail, either IPv4 or IPv6. 648 - the domain that provides the sought-after authorization 649 information; initially, the domain portion of the "MAIL 650 FROM" or "HELO" identity. 652 - the "MAIL FROM" or "HELO" identity. 654 The domain portion of will usually be the same as the 655 argument when check_host() is initially evaluated. However, 656 this will generally not be true for recursive evaluations (see 657 Section 5.2 below). 659 4.2. Results 661 The function check_host() can return one of several results described 662 in Section 2.5. Based on the result, the action to be taken is 663 determined by the local policies of the receiver. 665 4.3. Initial Processing 667 If the is malformed (e.g. label longer than 63 characters, 668 zero-length label not at the end, etc.) or is not a fully qualified 669 domain name, or if the DNS lookup returns "domain does not exist" 670 (RCODE 3), check_host() immediately returns the result "none". 671 Properly formed domains are fully qualified email domains as 672 described in [RFC5321] Section 2.3.5. For implementations that 673 support internationalized domain names, such domain names MUST be 674 encoded as A-labels, as described in Section 2.3 of [RFC5890]. 676 If the has no local-part, substitute the string "postmaster" 677 for the local-part. 679 4.4. Record Lookup 681 In accordance with how the records are published (see Section 3 682 above), a DNS query needs to be made for the name, querying 683 for type TXT only. 685 If all DNS lookups that are made return a server failure (RCODE 2), 686 or other error (RCODE other than 0 or 3), or time out, then 687 check_host() terminates immediately with the result "temperror". 688 Alternatively, for a server failure (RCODE 2) result, check_host() 689 MAY track failures and treat multiple failures within 24 hours for 690 the same domain as "permerror". 692 This alternative is intended to shorten the queue time of messages 693 that cannot be accepted, by returning a permanent negative completion 694 reply code to the client, instead of a transient one. [RFC2308] 695 suggests on an algorithm for doing such tracking and handling of 696 server failure codes. 698 4.5. Selecting Records 700 Records begin with a version section: 702 record = version terms *SP 703 version = "v=spf1" 705 Starting with the set of records that were returned by the lookup, 706 discard records that do not begin with a version section of exactly 707 "v=spf1". Note that the version section is terminated either by an 708 SP character or the end of the record. A record with a version 709 section of "v=spf10" does not match and MUST be discarded. 711 If the resultant record set includes no records, check_host() 712 produces the "none" result. If the resultant record set includes 713 more than one record, check_host() produces the "permerror" result. 715 4.6. Record Evaluation 717 After one SPF record has been selected, the check_host() function 718 parses and interprets it to find a result for the current test. If 719 there are any syntax errors, check_host() returns immediately with 720 the result "permerror". 722 Implementations MAY choose to parse the entire record first and 723 return "permerror" if the record is not syntactically well formed. 724 However, in all cases, any syntax errors anywhere in the record MUST 725 be detected. 727 4.6.1. Term Evaluation 729 There are two types of terms: mechanisms and modifiers. A record 730 contains an ordered list of these as specified in the following 731 Augmented Backus-Naur Form (ABNF). 733 terms = *( 1*SP ( directive / modifier ) ) 735 directive = [ qualifier ] mechanism 736 qualifier = "+" / "-" / "?" / "~" 737 mechanism = ( all / include 738 / A / MX / PTR / IP4 / IP6 / exists ) 739 modifier = redirect / explanation / unknown-modifier 740 unknown-modifier = name "=" macro-string 741 ; where name is not any known modifier 743 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 745 Most mechanisms allow a ":" or "/" character after the name. 747 Modifiers always contain an equals ('=') character immediately after 748 the name, and before any ":" or "/" characters that might be part of 749 the macro-string. 751 Terms that do not contain any of "=", ":", or "/" are mechanisms, as 752 defined in Section 5. 754 As per the definition of the ABNF notation in [RFC5234], mechanism 755 and modifier names are case-insensitive. 757 4.6.2. Mechanisms 759 Each mechanism is considered in turn from left to right. If there 760 are no more mechanisms, the result is specified in Section 4.7. 762 When a mechanism is evaluated, one of three things can happen: it can 763 match, not match, or throw an exception. 765 If it matches, processing ends and the qualifier value is returned as 766 the result of that record. If it does not match, processing 767 continues with the next mechanism. If it returns an exception, 768 mechanism processing ends and the exception value is returned. 770 The possible qualifiers, and the results they cause check_host() to 771 return are as follows: 773 "+" pass 774 "-" fail 775 "~" softfail 776 "?" neutral 778 The qualifier is optional and defaults to "+". 780 When a mechanism matches and the qualifier is "-", then a "fail" 781 result is returned and the explanation string is computed as 782 described in Section 6.2. 784 The specific mechanisms are described in Section 5. 786 4.6.3. Modifiers 788 Modifiers are not mechanisms. They do not return match or not-match. 789 Instead, they provide additional information. Although modifiers do 790 not directly affect the evaluation of the record, the "redirect" 791 modifier has an effect after all the mechanisms have been evaluated. 793 4.6.4. DNS Lookup Limits 795 SPF implementations MUST limit the number of mechanisms and modifiers 796 ("terms") that cause any DNS query to at most 10 during SPF 797 evaluation. Specifically, the "include", "a", "mx", "ptr", and 798 "exists" mechanisms as well as the "redirect" modifier count against 799 this limit. The "all", "ip4", and "ip6" mechanisms do not count 800 against this limit. If this number is exceeded during a check, a 801 permerror MUST be returned. The "exp" modifier does not count 802 against this limit because the DNS lookup to fetch the explanation 803 string occurs after the SPF record evaluation has been completed. 805 When evaluating the "mx" and "ptr" mechanisms, or the %{p} macro, 806 there MUST be a limit of no more than 10 MX or PTR RRs looked up and 807 checked. If more than 10 "mx" or "ptr" records are returned for this 808 further lookup, a permerror MUST be returned. This limit is per 809 mechanism or macro in the record and in addition to the lookup limits 810 above. 812 MTAs or other processors SHOULD impose a limit on the maximum amount 813 of elapsed time to evaluate check_host(). Such a limit SHOULD allow 814 at least 20 seconds. If such a limit is exceeded, the result of 815 authorization SHOULD be "temperror". 817 4.7. Default Result 819 If none of the mechanisms match and there is no "redirect" modifier, 820 then the check_host() returns a result of "neutral", just as if 821 "?all" were specified as the last directive. If there is a 822 "redirect" modifier, check_host() proceeds as defined in Section 6.1. 824 Note that records SHOULD always use either a "redirect" modifier or 825 an "all" mechanism to explicitly terminate processing. Although the 826 latter has default (specifically "?all"), it aids debugging efforts 827 if it is explicitly included. 829 For example: 831 v=spf1 +mx -all 832 or 833 v=spf1 +mx redirect=_spf.example.com 835 4.8. Domain Specification 837 Several of these mechanisms and modifiers have a domain-spec section. 838 The domain-spec string is subject to macro expansion (see Section 8). 839 The resulting string is the common presentation form of a fully- 840 qualified DNS name: a series of labels separated by periods. This 841 domain is called the in the rest of this document. 843 Note: The result of the macro expansion is not subject to any further 844 escaping. Hence, this facility cannot produce all characters that 845 are legal in a DNS label (e.g., the control characters). However, 846 this facility is powerful enough to express legal host names and 847 common utility labels (such as "_spf") that are used in DNS. 849 For several mechanisms, the is optional. If it is not 850 provided, the is used as the . Domain and 851 domain-spec are syntactically identical after macro expansion. 852 Domain is an input value for check_host() while domain-spec is 853 computed by check_host(). 855 5. Mechanism Definitions 857 This section defines two types of mechanisms. 859 Basic mechanisms contribute to the language framework. They do not 860 specify a particular type of authorization scheme. 862 all 863 include 865 Designated sender mechanisms are used to designate a set of 866 addresses as being permitted or not permitted to use the for 867 sending mail. 869 a 870 mx 871 ptr (deprecated) 872 ip4 873 ip6 874 exists 876 The following conventions apply to all mechanisms that perform a 877 comparison between and an IP address at any point: 879 If no CIDR prefix length is given in the directive, then and the 880 IP address are compared for equality. (Here, CIDR is Classless 881 Inter-Domain Routing, described in [RFC4632].) 883 If a CIDR prefix length is specified, then only the specified number 884 of high-order bits of and the IP address are compared for 885 equality. 887 When any mechanism fetches host addresses to compare with , when 888 is an IPv4 address, A records are fetched; when is an IPv6 889 address, AAAA records are fetched. Even if the SMTP connection uses 890 IPv6, an IPv4-mapped IPv6 IP address (see [RFC4291], Section 2.5.5) 891 MUST still be considered an IPv4 address and MUST be evaluated using 892 IPv4 mechanisms (i.e. "ip4" and "a"). 894 Several mechanisms rely on information fetched from the DNS. For 895 these DNS queries, except where noted, if the DNS server returns an 896 error (RCODE other than 0 or 3) or the query times out, the mechanism 897 stops and the topmost check_host() returns "temperror". If the 898 server returns "domain does not exist" (RCODE 3), then evaluation of 899 the mechanism continues as if the server returned no error (RCODE 0) 900 and zero answer records. 902 5.1. "all" 904 all = "all" 906 The "all" mechanism is a test that always matches. It is used as the 907 rightmost mechanism in a record to provide an explicit default. 909 For example: 911 v=spf1 a mx -all 913 Mechanisms after "all" will never be tested. Mechanisms listed after 914 "all" MUST be ignored. Any "redirect" modifier (Section 6.1) MUST be 915 ignored when there is an "all" mechanism in the record. 917 5.2. "include" 919 include = "include" ":" domain-spec 921 The "include" mechanism triggers a recursive evaluation of 922 check_host(). 924 1. The domain-spec is expanded as per Section 8. 926 2. Check_host() is evaluated with the resulting string as the 927 . The and arguments remain the same as in 928 the current evaluation of check_host(). 930 3. The recursive evaluation returns either match, not match, or an 931 error. If it matches, then the appropriate result for the 932 include: mechanism is used (e.g. include or +include gives a 933 "pass" result and -include gives "fail). 935 4. If there is no match, the parent check_host() resumes processing 936 as per the table below, with the previous value of 937 restored. 939 In hindsight, the name "include" was poorly chosen. Only the 940 evaluated result of the referenced SPF record is used, rather than 941 acting as if the referenced SPF record was literally included in the 942 first. For example, evaluating a "-all" directive in the referenced 943 record does not terminate the overall processing and does not 944 necessarily result in an overall "fail". (Better names for this 945 mechanism would have been "if-match", "on-match", etc.) 947 The "include" mechanism makes it possible for one domain to designate 948 multiple administratively-independent domains. For example, a vanity 949 domain "example.net" might send mail using the servers of 950 administratively-independent domains example.com and example.org. 952 Example.net could say 954 IN TXT "v=spf1 include:example.com include:example.org -all" 956 This would direct check_host() to, in effect, check the records of 957 example.com and example.org for a "pass" result. Only if the host 958 were not permitted for either of those domains would the result be 959 "fail". 961 Whether this mechanism matches, does not match, or returns an 962 exception depends on the result of the recursive evaluation of 963 check_host(): 965 +---------------------------------+---------------------------------+ 966 | A recursive check_host() result | Causes the "include" mechanism | 967 | of: | to: | 968 +---------------------------------+---------------------------------+ 969 | pass | match | 970 | | | 971 | fail | not match | 972 | | | 973 | softfail | not match | 974 | | | 975 | neutral | not match | 976 | | | 977 | temperror | throw temperror | 978 | | | 979 | permerror | throw permerror | 980 | | | 981 | none | throw permerror | 982 +---------------------------------+---------------------------------+ 984 The "include" mechanism is intended for crossing administrative 985 boundaries. For example, if example.com and example.org were managed 986 by the same entity, and if the permitted set of hosts for both 987 domains was 988 "mx:example.com", it would be possible for example.org to specify 989 "include:example.com", but it would be preferable to specify 990 "redirect=example.com" or even "mx:example.com". 992 With the "include" mechanism an administratively external set of 993 hosts can be authorized, but determination of sender policy is still 994 a function of the original domain's SPF record (as determined by the 995 "all" mechanism in that record). The redirect modifier is more 996 suitable for consolidating both authorizations and policy into a 997 common set to be shared within an ADMD. Redirect is much more like a 998 common code element to be shared among records in a single ADMD. It 999 is possible to control both authorized hosts and policy for an 1000 arbitrary number of domains from a single record. 1002 5.3. "a" 1004 This mechanism matches if is one of the 's IP 1005 addresses. 1007 a = "a" [ ":" domain-spec ] [ dual-cidr-length ] 1009 An address lookup is done on the . The is compared 1010 to the returned address(es). If any address matches, the mechanism 1011 matches. 1013 5.4. "mx" 1015 This mechanism matches if is one of the MX hosts for a domain 1016 name. 1018 mx = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 1020 check_host() first performs an MX lookup on the . Then 1021 it performs an address lookup on each MX name returned. The is 1022 compared to each returned IP address. To prevent Denial of Service 1023 (DoS) attacks, more than 10 MX names MUST NOT be looked up during the 1024 evaluation of an "mx" mechanism (see Section 10). If any address 1025 matches, the mechanism matches. 1027 Note regarding implicit MXs: If the has no MX records, 1028 check_host() MUST NOT pretend the target is its single MX, and MUST 1029 NOT default to an A or AAAA lookup on the directly. 1030 This behavior diverges from the legacy "implicit MX" rule, (See 1031 [RFC5321], Section 5. If such behavior is desired, the publisher 1032 should specify an "a" directive). 1034 5.5. "ptr" (deprecated) 1036 This mechanism tests whether the DNS reverse-mapping for exists 1037 and correctly points to a domain name within a particular domain. 1038 This mechanism is deprecated and SHOULD NOT be used. 1040 ptr = "ptr" [ ":" domain-spec ] 1042 The 's name is looked up using this procedure: 1044 1. Perform a DNS reverse-mapping for 1045 2. Look up the corresponding PTR record in "in-addr.arpa." if the 1046 address is an IPv4 one and in "ip6.arpa." if it is an IPv6 1047 address. 1049 3. For each record returned, validate the domain name by looking up 1050 its IP address. To prevent DoS attacks, more than 10 PTR names 1051 MUST NOT be looked up during the evaluation of a "ptr" mechanism 1052 (see Section 4.6.4). 1054 4. If is among the returned IP addresses, then that domain name 1055 is validated. 1057 Check all validated domain names to see if they either match the 1058 domain or are a subdomain of the domain. 1059 If any do, this mechanism matches. If no validated domain name can 1060 be found, or if none of the validated domain names match or are a 1061 subdomain of the , this mechanism fails to match. If a 1062 DNS error occurs while doing the PTR RR lookup, then this mechanism 1063 fails to match. If a DNS error occurs while doing an A RR lookup, 1064 then that domain name is skipped and the search continues. 1066 Pseudocode: 1068 sending-domain_names := ptr_lookup(sending-host_IP); 1069 if more than 10 sending-domain_names are found, use at most 10. 1070 for each name in (sending-domain_names) { 1071 IP_addresses := a_lookup(name); 1072 if the sending-domain_IP is one of the IP_addresses { 1073 validated-sending-domain_names += name; 1074 } 1075 } 1077 for each name in (validated-sending-domain_names) { 1078 if name ends in , return match. 1079 if name is , return match. 1080 } 1081 return no-match. 1083 This mechanism matches if the is either a subdomain of 1084 a validated domain name or if the and a validated 1085 domain name are the same. For example: "mail.example.com" is within 1086 the domain "example.com", but "mail.bad-example.com" is not. 1088 Note: This mechanism has been deprecated because it is slow, it is 1089 not as reliable as other mechanisms in cases of DNS errors, and it 1090 places a large burden on the .arpa name servers. If used, proper PTR 1091 records MUST be in place for the domain's hosts and the "ptr" 1092 mechanism should be one of the last mechanisms checked. After many 1093 years of SPF deployment experience it has been concluded it is 1094 unnecessary and more reliable alternatives used instead. It is, 1095 however, still in use and part of the SPF protocol, so compliant 1096 check_host() implementations MUST support it. 1098 5.6. "ip4" and "ip6" 1100 These mechanisms test whether is contained within a given IP 1101 network. 1103 ip4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 1104 ip6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 1106 ip4-cidr-length = "/" 1*DIGIT 1107 ip6-cidr-length = "/" 1*DIGIT 1108 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 1110 ip4-network = qnum "." qnum "." qnum "." qnum 1111 qnum = DIGIT ; 0-9 1112 / %x31-39 DIGIT ; 10-99 1113 / "1" 2DIGIT ; 100-199 1114 / "2" %x30-34 DIGIT ; 200-249 1115 / "25" %x30-35 ; 250-255 1116 ; as per conventional dotted quad notation. e.g., 192.0.2.0 1117 ip6-network = 1118 ; e.g., 2001:DB8::CD30 1120 The is compared to the given network. If CIDR prefix length 1121 high-order bits match, the mechanism matches. 1123 If ip4-cidr-length is omitted, it is taken to be "/32". If 1124 ip6-cidr-length is omitted, it is taken to be "/128". It is not 1125 permitted to omit parts of the IP address instead of using CIDR 1126 notations. That is, use 192.0.2.0/24 instead of 192.0.2. 1128 5.7. "exists" 1130 This mechanism is used to construct an arbitrary domain name that is 1131 used for a DNS A record query. It allows for complicated schemes 1132 involving arbitrary parts of the mail envelope to determine what is 1133 permitted. 1135 exists = "exists" ":" domain-spec 1137 The domain-spec is expanded as per Section 8. The resulting domain 1138 name is used for a DNS A RR lookup. If any A record is returned, 1139 this mechanism matches. The lookup type is A even when the 1140 connection type is IPv6. 1142 Domains can use this mechanism to specify arbitrarily complex 1143 queries. For example, suppose example.com publishes the record: 1145 v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all 1147 The might expand to 1148 "1.2.0.192.someuser._spf.example.com". This makes fine-grained 1149 decisions possible at the level of the user and client IP address. 1151 This mechanism enables queries that mimic the style of tests that 1152 existing DNS white/black lists (DNSxLs) use, as described in 1153 [RFC5782]. The query will either return NXDOMAIN (no match), any 1154 valid answer (match), or an error. 1156 6. Modifier Definitions 1158 Modifiers are name/value pairs that provide additional information. 1159 Modifiers always have an "=" separating the name and the value. 1161 The modifiers defined in this document ("redirect" and "exp") MAY 1162 appear anywhere in the record, but SHOULD appear at the end, after 1163 all mechanisms. Ordering of these two modifiers does not matter. 1164 These two modifiers MUST NOT appear in a record more than once each. 1165 If they do, then check_host() exits with a result of "permerror". 1167 Unrecognized modifiers MUST be ignored no matter where in a record, 1168 or how often. This allows implementations of this document to 1169 gracefully handle records with modifiers that are defined in other 1170 specifications. 1172 6.1. redirect: Redirected Query 1174 The redirect modifier is intended for consolidating both 1175 authorizations and policy into a common set to be shared within a 1176 single ADMD. Redirect is like a common code element to be shared 1177 among records in a single ADMD. It is possible to control both 1178 authorized hosts and policy for an arbitrary number of domains from a 1179 single record. 1181 redirect = "redirect" "=" domain-spec 1183 If all mechanisms fail to match, and a "redirect" modifier is 1184 present, then processing proceeds as follows: 1186 The domain-spec portion of the redirect section is expanded as per 1187 the macro rules in Section 8. Then check_host() is evaluated with 1188 the resulting string as the . The and 1189 arguments remain the same as in the current evaluation of 1190 check_host(). 1192 The result of this new evaluation of check_host() is then considered 1193 the result of the current evaluation with the exception that if no 1194 SPF record is found, or if the target-name is malformed, the result 1195 is a "permerror" rather than "none". 1197 Note that the newly-queried domain can itself specify redirect 1198 processing. 1200 This facility is intended for use by organizations that wish to apply 1201 the same record to multiple domains. For example: 1203 la.example.com. TXT "v=spf1 redirect=_spf.example.com" 1204 ny.example.com. TXT "v=spf1 redirect=_spf.example.com" 1205 sf.example.com. TXT "v=spf1 redirect=_spf.example.com" 1206 _spf.example.com. TXT "v=spf1 mx:example.com -all" 1208 In this example, mail from any of the three domains is described by 1209 the same record. This can be an administrative advantage. 1211 Note: In general, the domain "A" cannot reliably use a redirect to 1212 another domain "B" not under the same administrative control. Since 1213 the stays the same, there is no guarantee that the record at 1214 domain "B" will correctly work for mailboxes in domain "A", 1215 especially if domain "B" uses mechanisms involving local-parts. An 1216 "include" directive is generally be more appropriate. 1218 For clarity, it is RECOMMENDED that any "redirect" modifier appear as 1219 the very last term in a record. 1221 6.2. exp: Explanation 1223 explanation = "exp" "=" domain-spec 1225 If check_host() results in a "fail" due to a mechanism match (such as 1226 "-all"), and the "exp" modifier is present, then the explanation 1227 string returned is computed as described below. If no "exp" modifier 1228 is present, then either a default explanation string or an empty 1229 explanation string MUST be returned. 1231 The domain-spec is macro expanded (see Section 8) and becomes the 1232 . The DNS TXT record for the is fetched. 1234 If there are any DNS processing errors (any RCODE other than 0), or 1235 if no records are returned, or if more than one record is returned, 1236 or if there are syntax errors in the explanation string, then proceed 1237 as if no exp modifier was given. 1239 The fetched TXT record's strings are concatenated with no spaces, and 1240 then treated as an explain-string, which is macro-expanded. This 1241 final result is the explanation string. Implementations MAY limit 1242 the length of the resulting explanation string to allow for other 1243 protocol constraints and/or reasonable processing limits. Since the 1244 explanation string is intended for an SMTP response and [RFC5321] 1245 Section 2.4 says that responses are in [US-ASCII], the explanation 1246 string MUST be limited to US-ASCII. 1248 Software evaluating check_host() can use this string to communicate 1249 information from the publishing domain in the form of a short message 1250 or URL. Software SHOULD make it clear that the explanation string 1251 comes from a third party. For example, it can prepend the macro 1252 string "%{o} explains: " to the explanation, such as shown in 1253 Section 2.5.4. 1255 Suppose example.com has this record: 1257 v=spf1 mx -all exp=explain._spf.%{d} 1259 Here are some examples of possible explanation TXT records at 1260 explain._spf.example.com: 1262 "Mail from example.com should only be sent by its own servers." 1263 -- a simple, constant message 1265 "%{i} is not one of %{d}'s designated mail servers." 1266 -- a message with a little more information, including the IP 1267 address that failed the check 1269 "See http://%{d}/why.html?s=%{S}&i=%{I}" 1270 -- a complicated example that constructs a URL with the 1271 arguments to check_host() so that a web page can be 1272 generated with detailed, custom instructions 1274 Note: During recursion into an "include" mechanism, an exp= modifier 1275 from the MUST NOT be used. In contrast, when executing 1276 a "redirect" modifier, an exp= modifier from the original domain MUST 1277 NOT be used. 1279 7. Recording The Result 1281 It is RECOMMENDED that SMTP receivers record the result of SPF 1282 processing in the message header. There are two methods for doing 1283 this: the Received-SPF header field defined here and the more generic 1284 Authentication-Results header field defined in [RFC5451]. Because 1285 these fields are generally used within a receiving ADMD, it is a 1286 local policy choice which to include. In general, the more broadly 1287 applicable Authentication-Results header field ought to be used, but 1288 it SHOULD be used in such a way that it conveys the same information 1289 that the verifier would have provided in a Received-SPF header field 1290 if that had been used. 1292 If an SMTP receiver chooses to do so, it SHOULD use one of these 1293 header fields for each identity that was checked. This information 1294 is intended for the recipient. (Information intended for the sender 1295 is described in Section 6.2, Explanation.) 1297 7.1. The Received-SPF Header Field 1299 The Received-SPF header field is a trace field (see [RFC5322] Section 1300 3.6.7) and SHOULD be prepended to the existing header, above the 1301 Received: field that is generated by the SMTP receiver. It MUST 1302 appear above all other Received-SPF fields in the message. The 1303 header field has the following format: 1305 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 1306 [ key-value-list ] CRLF 1308 result = "pass" / "fail" / "softfail" / "neutral" / 1309 "none" / "temperror" / "permerror" 1311 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 1312 [";"] 1314 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 1316 key = "client-ip" / "envelope-from" / "helo" / 1317 "problem" / "receiver" / "identity" / 1318 mechanism / name 1320 identity = "mailfrom" ; for the "MAIL FROM" identity 1321 / "helo" ; for the "HELO" identity 1322 / name ; other identities 1324 dot-atom = 1325 quoted-string = 1326 comment = 1327 CFWS = 1328 FWS = 1329 CRLF = 1331 The header field SHOULD include a "(...)" style comment after the 1332 result, conveying supporting information for the result, such as 1333 , , and . 1335 The following key-value pairs are designed for later machine parsing. 1336 SPF verifiers SHOULD give enough information so that the SPF results 1337 can be verified. That is, at least "client-ip", "helo", and, if the 1338 "MAIL FROM" identity was checked, "envelope-from". 1340 client-ip the IP address of the SMTP client 1342 envelope-from the envelope sender mailbox 1344 helo the host name given in the HELO or EHLO command 1346 mechanism the mechanism that matched (if no mechanisms matched, 1347 substitute the word "default") 1349 problem if an error was returned, details about the error 1350 receiver the host name of the SPF verifier 1352 identity the identity that was checked; see the ABNF 1353 rule 1355 Other keys MAY be defined by SPF verifiers. 1357 SPF verifiers MUST make sure that the Received-SPF header field does 1358 not contain invalid characters, is not excessively long (See 1359 [RFC5322] Section 2.1.1), and does not contain malicious data that 1360 has been provided by the sender. 1362 Examples of various header field styles that could be generated are 1363 the following: 1365 Received-SPF: pass (mybox.example.org: domain of 1366 myname@example.com designates 192.0.2.1 as permitted sender) 1367 receiver=mybox.example.org; client-ip=192.0.2.1; 1368 envelope-from="myname@example.com"; helo=foo.example.com; 1370 Received-SPF: fail (mybox.example.org: domain of 1371 myname@example.com does not designate 1372 192.0.2.1 as permitted sender) 1373 identity=mailfrom; client-ip=192.0.2.1; 1374 envelope-from="myname@example.com"; 1376 7.2. SPF Results in the Authentication-Results Header Field 1378 As mentioned in Section 7, the Authentication-Results header field is 1379 designed to communicate lists of tests a border MTA did and their 1380 results. The specified elements of the field provide less 1381 information than the SPF-Received field: 1383 Authentication-Results: myhost.example.org; spf=pass 1384 smtp.mailfrom=example.net 1386 Received-SPF: pass (myhost.example.org: domain of 1387 myname@example.com designates 192.0.2.1 as permitted sender) 1388 receiver=mybox.example.org; client-ip=192.0.2.1; 1389 envelope-from="myname@example.com"; helo=foo.example.com; 1391 It is, however, possible to add CFWS in the "reason" part of an 1392 Authentication-Results header field and provide the equivalent 1393 information. Receivers SHOULD include the same information they 1394 would have provided if they had used the Received-SPF field. 1396 The reason SHOULD include a key-value-list with keys provinding 1397 information normally included in a Received-SPF header field that is 1398 not already part of the Authentication-Results header field. That 1399 is, at least "client-ip", "helo", and, if the "MAIL FROM" identity 1400 was checked, "envelope-from". Authentication-Results header fields 1401 can contain results for more than one authentication, so one field 1402 can provide results for both an "MAIL FROM" check and an "HELO" 1403 check. 1405 reasonspec = 1407 A suitably enhanced Authentication-Results header field might look 1408 like (for a "MAIL FROM" check in this example): 1410 Authentication-Results: myhost.example.org; spf=pass 1411 reason="client-ip=192.0.2.1; smtp.helo=foo.example.com" 1412 smtp.mailfrom=user@example.net 1414 8. Macros 1416 8.1. Macro Definitions 1418 Many mechanisms and modifiers perform macro expansion on a term. 1420 domain-spec = macro-string domain-end 1421 domain-end = ( "." toplabel [ "." ] ) / macro-expand 1423 toplabel = ( *alphanum ALPHA *alphanum ) / 1424 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 1425 ; LDH rule plus additional TLD restrictions 1426 ; (see [RFC3696], Section 2 for background) 1427 alphanum = ALPHA / DIGIT 1429 explain-string = *( macro-string / SP ) 1431 macro-string = *( macro-expand / macro-literal ) 1432 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 1433 / "%%" / "%_" / "%-" 1434 macro-literal = %x21-24 / %x26-7E 1435 ; visible characters except "%" 1436 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 1437 "c" / "r" / "t" / "v" 1438 transformers = *DIGIT [ "r" ] 1439 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 1441 A literal "%" is expressed by "%%". 1443 "%_" expands to a single " " space. 1444 "%-" expands to a URL-encoded space, viz., "%20". 1446 The following macro letters are expanded in term arguments: 1448 s = 1449 l = local-part of 1450 o = domain of 1451 d = 1452 i = 1453 p = the validated domain name of (deprecated) 1454 v = the string "in-addr" if is ipv4, or "ip6" if is ipv6 1455 h = HELO/EHLO domain 1457 The following macro letters are allowed only in "exp" text: 1459 c = SMTP client IP (easily readable format) 1460 r = domain name of host performing the check 1461 t = current timestamp 1463 A '%' character not followed by a '{', '%', '-', or '_' character is 1464 a syntax error. So 1465 -exists:%(ir).sbl.spamhaus.example.org 1466 is incorrect and will cause check_host() to yield a "permerror". 1467 Instead, say 1468 -exists:%{ir}.sbl.spamhaus.example.org 1470 Optional transformers are the following: 1472 *DIGIT = zero or more digits 1473 'r' = reverse value, splitting on dots by default 1475 If transformers or delimiters are provided, the replacement value for 1476 a macro letter is split into parts. After performing any reversal 1477 operation and/or removal of left-hand parts, the parts are rejoined 1478 using "." and not the original splitting characters. 1480 By default, strings are split on "." (dots). Note that no special 1481 treatment is given to leading, trailing, or consecutive delimiters in 1482 input strings, and so the list of parts might contain empty strings. 1483 Some older implementations of SPF prohibit trailing dots in domain 1484 names, so trailing dots SHOULD NOT be published by domain owners, 1485 although they MUST be accepted by implementations conforming to this 1486 document. Macros MAY specify delimiter characters that are used 1487 instead of ".". 1489 The 'r' transformer indicates a reversal operation: if the client IP 1490 address were 192.0.2.1, the macro %{i} would expand to "192.0.2.1" 1491 and the macro %{ir} would expand to "1.2.0.192". 1493 The DIGIT transformer indicates the number of right-hand parts to 1494 use, after optional reversal. If a DIGIT is specified, the value 1495 MUST be nonzero. If no DIGITs are specified, or if the value 1496 specifies more parts than are available, all the available parts are 1497 used. If the DIGIT was 5, and only 3 parts were available, the macro 1498 interpreter would pretend the DIGIT was 3. Implementations MUST 1499 support at least a value of 128, as that is the maximum number of 1500 labels in a domain name. 1502 The "s" macro expands to the argument. It is an email 1503 address with a local-part, an "@" character, and a domain. The "l" 1504 macro expands to just the local-part. The "o" macro expands to just 1505 the domain part. Note that these values remain the same during 1506 recursive and chained evaluations due to "include" and/or "redirect". 1507 Note also that if the original had no local-part, the local- 1508 part was set to "postmaster" in initial processing (see Section 4.3). 1510 For IPv4 addresses, both the "i" and "c" macros expand to the 1511 standard dotted-quad format. 1513 For IPv6 addresses, the "i" macro expands to a dot-format address; it 1514 is intended for use in %{ir}. The "c" macro MAY expand to any of the 1515 hexadecimal colon-format addresses specified in [RFC4291], Section 1516 2.2. It is intended for humans to read. 1518 The "p" macro expands to the validated domain name of . The 1519 procedure for finding the validated domain name is defined in 1520 Section 5.5. If the is present in the list of validated 1521 domains, it SHOULD be used. Otherwise, if a subdomain of the 1522 is present, it SHOULD be used. Otherwise, any name from the 1523 list MAY be used. If there are no validated domain names or if a DNS 1524 error occurs, the string "unknown" is used. This macro is deprecated 1525 and SHOULD NOT be used. 1527 The "r" macro expands to the name of the receiving MTA. This SHOULD 1528 be a fully qualified domain name, but if one does not exist (as when 1529 the checking is done by a MUA) or if policy restrictions dictate 1530 otherwise, the word "unknown" SHOULD be substituted. The domain name 1531 can be different from the name found in the MX record that the client 1532 MTA used to locate the receiving MTA. 1534 The "t" macro expands to the decimal representation of the 1535 approximate number of seconds since the Epoch (Midnight, January 1, 1536 1970, UTC) at the time of the evaluation. This is the same value as 1537 is returned by the POSIX time() function in most standards-compliant 1538 libraries. 1540 When the result of macro expansion is used in a domain name query, if 1541 the expanded domain name exceeds 253 characters (the maximum length 1542 of a domain name), the left side is truncated to fit, by removing 1543 successive domain labels (and their following dots) until the total 1544 length does not exceed 253 characters. 1546 Uppercased macros expand exactly as their lowercased equivalents, and 1547 are then URL escaped. URL escaping MUST be performed for characters 1548 not in the "unreserved" set, which is defined in [RFC3986]. 1550 Note: Care MUST be taken so that macro expansion for legitimate email 1551 does not exceed the 63-character limit on DNS labels. The local-part 1552 of email addresses, in particular, can have more than 63 characters 1553 between dots. 1555 Note: Domains SHOULD avoid using the "s", "l", "o", or "h" macros in 1556 conjunction with any mechanism directive. Although these macros are 1557 powerful and allow per-user records to be published, they severely 1558 limit the ability of implementations to cache results of check_host() 1559 and they reduce the effectiveness of DNS caches. 1561 Note: If no directive processed during the evaluation of check_host() 1562 contains an "s", "l", "o", or "h" macro, then the results of the 1563 evaluation can be cached on the basis of and alone for 1564 as long as the shortest Time To Live (TTL) of all the DNS records 1565 involved. 1567 8.2. Expansion Examples 1569 The is strong-bad@email.example.com. 1570 The IPv4 SMTP client IP is 192.0.2.3. 1571 The IPv6 SMTP client IP is 2001:DB8::CB01. 1572 The PTR domain name of the client IP is mx.example.org. 1574 macro expansion 1575 ------- ---------------------------- 1576 %{s} strong-bad@email.example.com 1577 %{o} email.example.com 1578 %{d} email.example.com 1579 %{d4} email.example.com 1580 %{d3} email.example.com 1581 %{d2} example.com 1582 %{d1} com 1583 %{dr} com.example.email 1584 %{d2r} example.email 1585 %{l} strong-bad 1586 %{l-} strong.bad 1587 %{lr} strong-bad 1588 %{lr-} bad.strong 1589 %{l1r-} strong 1591 macro-string expansion 1592 -------------------------------------------------------------------- 1593 %{ir}.%{v}._spf.%{d2} 3.2.0.192.in-addr._spf.example.com 1594 %{lr-}.lp._spf.%{d2} bad.strong.lp._spf.example.com 1596 %{lr-}.lp.%{ir}.%{v}._spf.%{d2} 1597 bad.strong.lp.3.2.0.192.in-addr._spf.example.com 1599 %{ir}.%{v}.%{l1r-}.lp._spf.%{d2} 1600 3.2.0.192.in-addr.strong.lp._spf.example.com 1602 %{d2}.trusted-domains.example.net 1603 example.com.trusted-domains.example.net 1605 IPv6: 1606 %{ir}.%{v}._spf.%{d2} 1.0.B.C.0.0.0.0. 1608 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 1610 9. Implications 1612 This section outlines the major implications that adoption of this 1613 document will have on various entities involved in Internet email. 1614 It is intended to make clear to the reader where this document 1615 knowingly affects the operation of such entities. This section is 1616 not a "how-to" manual, or a "best practices" document, and it is not 1617 a comprehensive list of what such entities should do in light of this 1618 document. 1620 This section is non-normative. [RFC5598] describes the Internet 1621 email architecture. This section is organized based on the different 1622 segments of the architecture. 1624 9.1. Sending Domains 1626 Originating ADMDs (ADministrative Management Domains - [RFC5598] 1627 Section 2.2.1 and Section 2.3) that wish to be compliant with this 1628 specification will need to determine the list of relays ([RFC5598] 1629 Section 2.2.2) that they allow to use their domain name in the "HELO" 1630 and "MAIL FROM" identities when relaying to other ADMDs. It is 1631 recognized that forming such a list is not just a simple technical 1632 exercise, but involves policy decisions with both technical and 1633 administrative considerations. 1635 9.1.1. DNS Resource Considerations 1637 Minimizing the DNS resources required for SPF lookups can be done by 1638 choosing directives that require less DNS information and by placing 1639 lower-cost mechanisms earlier in the SPF record. 1641 +----------+--------+-----------------+ 1642 | term | cost | limit | 1643 +----------+--------+-----------------+ 1644 | ip4/ip6 | 0 | - | 1645 | a | 1 | 10 | 1646 | include | 1 | 10 | 1647 | redirect | 1 | 10 | 1648 | exists | 1 | 10 | 1649 | mx | 1 + N* | 10 and N* <= 10 | 1650 | ptr/%{p} | 1 + N* | 10 and N* <= 10 | 1651 | all | 0 | - | 1652 +----------+--------+-----------------+ 1653 * N is the number of RRs found during each term evaluation 1655 Section 4.6.4 specifies the limits receivers have to use. It is 1656 essential to publish records that do not exceed these requirements. 1657 It is also required to carefully weight the cost and the 1658 maintainability of licit solutions. 1660 For example, consider a domain set up as follows: 1662 example.com. IN MX 10 mx.example.com. 1663 IN MX 20 mx2.example.com. 1664 mx.example.com. IN A 192.0.2.1 1665 mx2.example.com. IN A 192.0.2.129 1667 Assume the administrative point is to authorize (pass) mx and mx2 1668 while failing every other host. Compare the following solutions: 1670 Best record: 1671 example.com. IN TXT "v=spf1 ip4:192.0.2.1 ip4:192.0.2.129 -all" 1673 Good record: 1674 $ORIGIN example.com. 1675 @ IN TXT "v=spf1 a:authorized_spf.example.com -all" 1676 authorized_spf IN A 192.0.2.1 1677 IN A 192.0.2.129 1679 Expensive record: 1680 example.com. IN TXT "v=spf1 mx:example.com -all" 1682 Wasteful, bad record: 1683 example.com. IN TXT "v=spf1 ip4:192.0.2.0/24 mx -all" 1685 9.1.2. Administrator's Considerations 1687 There might be administrative considerations: using "a" over "ip4" or 1688 "ip6" allows hosts to be renumbered easily. Using "mx" over "a" 1689 allows the set of mail hosts to be changed easily. Unless such 1690 changes are common, it is better to use the less resource intensive 1691 mechanisms like "ip4" and "ip6" over "a" or "a" or "mx". 1693 In some specific cases, standard advice on record content is 1694 appropriate. Publishing SPF records for domains that send no mail is 1695 a well established best practice. The record for a domain that sends 1696 no mail is: 1698 www.example.com. IN TXT "v=spf1 -all" 1700 Publishing SPF records for individual hosts is also best practice. 1701 The hostname is generally the identity used in the 5321.HELO/.EHLO 1702 command. In the case of messages with a null 5321.MailFrom, this is 1703 used as the domain for 5321.MailFrom SPF checks, in addition to being 1704 used in 5321.HELO/.EHLO based SPF checks. The standard SPF record 1705 for an individual host that is involved in mail processing is: 1707 relay.example.com. IN TXT "v=spf1 a -all" 1709 Validating correct deployment is difficult. [RFC6652] describes one 1710 mechanism for soliciting feedback on SPF failures. Another approach 1711 that can be helpful to publish records that include a "tracking 1712 exists:" mechanism. By looking at the name server logs, a rough list 1713 can then be generated. For example: 1715 v=spf1 exists:_h.%{h}._l.%{l}._o.%{o}._i.%{i}._spf.%{d} ?all 1717 Regardless of the method used, understanding the ADMD's outbound mail 1718 architecture is essential to effective deployment. 1720 9.1.3. Bounces 1722 As explained in Section 1.3.3, [RFC5321] allows the reverse-path to 1723 be null, which is typical of some Delivery Status Notification 1724 [RFC3464], commonly called email bounces. In this case the only 1725 entity available for performing an SPF check is the "HELO" identity 1726 defined in Section 1.3.4. SPF functionality is enhanced by 1727 administrators ensuring this identity is set correctly and has an 1728 appropriate SPF record. It is normal to have the HELO identity set 1729 to hostname instead of domain. Zone file generation for significant 1730 numbers of hosts can be consolidated using the redirect modifier and 1731 scripted for initial deployment. Specific deployment advice is given 1732 above in Section 9.1.2. 1734 9.2. Mediators 1736 Broadly speaking, there are two types of mediating ADMDs that can 1737 affect SPF deployment of other ADMDs: mailing lists (see [RFC5598] 1738 Section 5.3) and ReSenders ([RFC5598] Section 5.2). 1740 9.2.1. Mailing Lists 1742 Mailing lists have to be aware of how they re-inject mail that is 1743 sent to the list. Mailing lists MUST comply with the requirements in 1744 [RFC5321], Section 3.10, and [RFC1123], Section 5.3.6, that say that 1745 the reverse-path MUST be changed to be the mailbox of a person or 1746 other entity who administers the list. Whereas the reasons for 1747 changing the reverse-path are many and long-standing, SPF adds 1748 enforcement to this requirement. 1750 In practice, almost all mailing list software in use already complies 1751 with this requirement. Mailing lists that do not comply might 1752 encounter problems depending on how access to the list is restricted. 1753 Such lists that are entirely internal to a domain (only people in the 1754 domain can send to or receive from the list) are not affected. 1756 9.2.2. Forwarding Services and Aliases 1758 Forwarding services take mail that is received at a mailbox and 1759 direct it to some external mailbox. At the time of this writing, the 1760 near-universal practice of such services is to use the original "MAIL 1761 FROM" of a message when re-injecting it for delivery to the external 1762 mailbox. [RFC1123] and [RFC5321] describe this action as an "alias" 1763 rather than a "mail list". This means the external mailbox's MTA 1764 sees all such mail in a connection from a host of the forwarding 1765 service, and so the "MAIL FROM" identity will not, in general, pass 1766 authorization. 1768 There are three places that techniques can be used to ameliorate this 1769 problem. 1771 1. The beginning, when email is first sent (Originating ADMDs). 1773 1. "Neutral" results could be given for IP addresses that might 1774 be forwarders, instead of "fail" results. For example: 1776 "v=spf1 mx -exists:%{ir}.sbl.spamhaus.example.org ?all" 1778 This would cause a lookup on an anti-spam DNS blacklist 1779 (DNSBL) and cause a result of "fail" only for email coming 1780 from listed sources. All other email, including email sent 1781 through forwarders, would receive a "neutral" result. By 1782 checking the DNSBL after the known good sources, problems 1783 with incorrect listing on the DNSBL are greatly reduced. 1785 2. The "MAIL FROM" identity could have additional information in 1786 the local-part that cryptographically identifies the mail as 1787 coming from an authorized source. In this case, such an SPF 1788 record could be used: 1790 "v=spf1 mx exists:%{l}._spf_verify.%{d} -all" 1792 Then, a specialized DNS server can be set up to serve the 1793 _spf_verify subdomain that validates the local-part. 1794 Although this requires an extra DNS lookup, this happens only 1795 when the email would otherwise be rejected as not coming from 1796 a known good source. 1797 Note that due to the 63-character limit for domain labels, 1798 this approach only works reliably if the local-part signature 1799 scheme is guaranteed either to only produce local-parts with 1800 a maximum of 63 characters or to gracefully handle truncated 1801 local-parts. 1803 3. Similarly, a specialized DNS server could be set up that will 1804 rate-limit the email coming from unexpected IP addresses. 1806 "v=spf1 mx exists:%{ir}._spf_rate.%{d} -all" 1808 4. SPF allows the creation of per-user policies for special 1809 cases. For example, the following SPF record and appropriate 1810 wildcard DNS records can be used: 1812 "v=spf1 mx redirect=%{l1r+}._at_.%{o}._spf.%{d}" 1814 2. The middle, when email is forwarded (Mediating ADMDs). 1816 1. Forwarding services can solve the problem by rewriting the 1817 "MAIL FROM" to be in their own domain. This means mail 1818 rejected from the external mailbox will have to be forwarded 1819 back to the original sender by the forwarding service. 1820 Various schemes to do this exist though they vary widely in 1821 complexity and resource requirements on the part of the 1822 forwarding service. 1824 2. Several popular MTAs can be forced from "alias" semantics to 1825 "mailing list" semantics by configuring an additional alias 1826 with "owner-" prepended to the original alias name (e.g., an 1827 alias of "friends: george@example.com, fred@example.org" 1828 would need another alias of the form "owner-friends: 1829 localowner"). 1831 3. Forwarding servers could reject mail that would "fail" SPF if 1832 forwarded using an SMTP reply code of 551, User not local, 1833 (see [RFC5321] section 3.4) to communicate the correct target 1834 address to resend the mail to. 1836 3. The end, when email is received (Receiving ADMDs). 1838 1. If the owner of the external mailbox wishes to trust the 1839 forwarding service, he can direct the external mailbox's MTA 1840 to skip SPF tests when the client host belongs to the 1841 forwarding service. 1843 2. Tests against other identities, such as the "HELO" identity, 1844 MAY be used to override a failed test against the "MAIL FROM" 1845 identity. 1847 3. For larger domains, it might not be possible to have a 1848 complete or accurate list of forwarding services used by the 1849 owners of the domain's mailboxes. In such cases, whitelists 1850 of generally-recognized forwarding services could be 1851 employed. 1853 9.2.3. Mail Services 1855 MSPs (Mail Service Providers - [RFC5598] Section 2.3) that offer mail 1856 services to third-party domains, such as sending of bulk mail, might 1857 want to adjust their configurations in light of the authorization 1858 check described in this document. If the domain part of the "MAIL 1859 FROM" identity used for such email uses the domain of one of the MSPs 1860 domain, then the provider needs only to ensure that its sending host 1861 is authorized by its own SPF record, if any. 1863 If the "MAIL FROM" identity does not use the MSP's domain, then extra 1864 care has to be taken. The SPF record format has several options for 1865 the third-party domain to authorize the service provider's MTAs to 1866 send mail on its behalf. For MSPs, such as ISPs, that have a wide 1867 variety of customers using the same MTA, steps should be taken to 1868 prevent cross-customer forgery (see Section 10.4). 1870 9.2.4. MTA Relays 1872 Relays are described in [RFC5598] Section 2.2.2. The authorization 1873 check generally precludes the use of arbitrary MTA relays between 1874 sender and receiver of an email message. 1876 Within an organization, MTA relays can be effectively deployed. 1877 However, for purposes of this document, such relays are effectively 1878 transparent. The SPF authorization check is a check between border 1879 MTAs of different ADMDs. 1881 For mail senders, this means that published SPF records have to 1882 authorize any MTAs that actually send across the Internet. Usually, 1883 these are just the border MTAs as internal MTAs simply forward mail 1884 to these MTAs for relaying. 1886 The receiving ADMD will generally want to perform the authorization 1887 check at the boundary MTAs, including all secondary MXs. Internal 1888 MTAs (including MTAs that might serve both as boundary MTAs and 1889 internal relays from secondary MXs when they are processing the 1890 relayed mail stream) then do not perform the authorization test. To 1891 perform the authorization test other than at the boundary, the host 1892 that first transferred the message to the receiving ADMD have to be 1893 determined, which can be difficult to extract from the message header 1894 because (a) header fields can be forged or malformed, and (b) there's 1895 no standard way to encode that information such that it can be 1896 reliably extracted. Testing other than at the boundary is likely to 1897 produce unreliable results. 1899 9.3. Receivers 1901 SPF results can be used in combination with other methods to 1902 determine the final local disposition (either positive or negative of 1903 a message. It can also be considered dispositive on its own. 1905 9.3.1. Policy For SPF Pass 1907 SPF pass results can be used in combination with "white lists" of 1908 known "good" domains to bypass some or all additional pre-delivery 1909 email checks. Exactly which checks and how to determine appropriate 1910 white list entries has to be based on local conditions and 1911 requirements. 1913 9.3.2. Policy For SPF Fail 1915 SPF fail results can be used to reject messages during the SMTP 1916 transaction based on either "MAIL FROM" or "HELO" identity results. 1917 This reduces resource requirements for various content filtering 1918 methods and conserves bandwidth since rejection can be done before 1919 the SMTP content is transferred. It also gives immediate feedback to 1920 the sender who might then be able to resolve the issue. Due to some 1921 of the issues described above in this section (Section 9), SPF based 1922 rejection does present some risk of rejecting legitimate email when 1923 rejecting based on "MAIL FROM" results. 1925 SPF fail results can alternately be used as one input into a larger 1926 set of evaluations which might, based on the overall evaluation 1927 result in the email being marked negatively in some way (this might 1928 be via delivery to a special spam folder, modifying subject lines, or 1929 other locally determined means). Developing the details of such an 1930 approach have to be based on local conditions and requirements. 1931 Using SPF results in this way does not have the advantages of 1932 resource conservation and immediate feedback to the sender associated 1933 with SMTP rejection, but could produce fewer undesirable rejections 1934 in a well designed system. Such an approach might result in email 1935 that was not authorized by the sending ADMD being unknowingly 1936 delivered to end users. 1938 Either general approach can be used as they both leave a clear 1939 disposition of emails. They are either delivered in some manner or 1940 the sender is notified of the failure. Other dispositions such as 1941 "dropping" or deleting email after acceptance are inappropriate 1942 because they leave uncertainty and reduce the overall reliabilility 1943 and utility of email across the Internet. 1945 9.3.3. Policy For SPF Permerror 1947 The "permerror" result (see Section 2.5.7) indicates the SPF 1948 processing module at the receiver determined that the retrieved SPF 1949 policy record could not be interpreted. This gives no true 1950 indication about the authorized use of the data found in the 1951 envelope. 1953 As with all results, implementers have a choice to make regarding 1954 what to do with a message that yields this result. SMTP allows only 1955 a few basic options. 1957 Rejection of the message is an option, in that it is the one thing a 1958 receiver can do to draw attention to the difficulty encountered while 1959 protecting itself from messages that do not have a definite SPF 1960 result of some kind. However, if the SPF implementation is defective 1961 and returns spurious "permerror" results, only the sender is actively 1962 notified of the defect (in the form of rejected mail), and not the 1963 receiver making use of SPF. 1965 The less intrusive handling choice is to deliver the message, perhaps 1966 with some kind of annotation of the difficulty encountered and/or 1967 logging of a similar nature. However, this will not be desirable to 1968 operators that wish to implement SPF checking as strictly as 1969 possible, nor is this sort of passive problem reporting typically 1970 effective. 1972 There is of course the option placing this choice in the hands of the 1973 operator rather than the implementer since this kind of choice is 1974 often a matter of local policy rather than a condition with a 1975 universal solution, but this adds one more piece of complexity to an 1976 already non-trivial environment. 1978 Both implementers and operators need to be cautious of all choices 1979 and outcomes when handling SPF results. 1981 10. Security Considerations 1983 10.1. Processing Limits 1985 As with most aspects of email, there are a number of ways that 1986 malicious parties could use the protocol as an avenue for a 1987 Denial-of-Service (DoS) attack. The processing limits outlined in 1988 Section 4.6.4 are designed to prevent attacks such as the following: 1990 o A malicious party could create an SPF record with many references 1991 to a victim's domain and send many emails to different SPF 1992 verifiers; those SPF verifiers would then create a DoS attack. In 1993 effect, the SPF verifiers are being used to amplify the attacker's 1994 bandwidth by using fewer bytes in the SMTP session than are used 1995 by the DNS queries. Using SPF clients also allows the attacker to 1996 hide the true source of the attack. 1998 o Whereas implementations of check_host() are supposed to limit the 1999 number of DNS lookups, malicious domains could publish records 2000 that exceed these limits in an attempt to waste computation effort 2001 at their targets when they send them mail. Malicious domains 2002 could also design SPF records that cause particular 2003 implementations to use excessive memory or CPU usage, or to 2004 trigger bugs. 2006 o Malicious parties could send a large volume of mail purporting to 2007 come from the intended target to a wide variety of legitimate mail 2008 hosts. These legitimate machines would then present a DNS load on 2009 the target as they fetched the relevant records. 2011 Of these, the case of a third party referenced in the SPF record is 2012 the easiest for a DoS attack to effectively exploit. As a result, 2013 limits that might seem reasonable for an individual mail server can 2014 still allow an unreasonable amount of bandwidth amplification. 2015 Therefore, the processing limits need to be quite low. 2017 10.2. SPF-Authorized Email May Contain Other False Identities 2019 Do not construe the "MAIL FROM" and "HELO" identity authorizationsto 2020 provide more assurance than they do. It is entirely possible for a 2021 malicious sender to inject a message using his own domain in the 2022 identities used by SPF, to have that domain's SPF record authorize 2023 the sending host, and yet the message can easily list other 2024 identities in its header. Unless the user or the MUA takes care to 2025 note that the authorized identity does not match the other more 2026 commonly-presented identities (such as the From: header field), the 2027 user might be lulled into a false sense of security. 2029 10.3. Spoofed DNS and IP Data 2031 There are two aspects of this protocol that malicious parties could 2032 exploit to undermine the validity of the check_host() function: 2034 o The evaluation of check_host() relies heavily on DNS. A malicious 2035 attacker could attack the DNS infrastructure and cause 2036 check_host() to see spoofed DNS data, and then return incorrect 2037 results. This could include returning "pass" for an value 2038 where the actual domain's record would evaluate to "fail". See 2039 [RFC3833] for a description of DNS weaknesses. 2041 o The client IP address, , is assumed to be correct. In a 2042 modern, correctly configured system the risk of this not being 2043 true is nil. 2045 10.4. Cross-User Forgery 2047 By definition, SPF policies just map domain names to sets of 2048 authorized MTAs, not whole email addresses to sets of authorized 2049 users. Although the "l" macro (Section 8) provides a limited way to 2050 define individual sets of authorized MTAs for specific email 2051 addresses, it is generally impossible to verify, through SPF, the use 2052 of specific email addresses by individual users of the same MTA. 2054 It is up to mail services and their MTAs to directly prevent 2055 cross-user forgery: based on SMTP AUTH ([RFC4954]), users should be 2056 restricted to using only those email addresses that are actually 2057 under their control (see [RFC6409], Section 6.1). Another means to 2058 verify the identity of individual users is message cryptography such 2059 as PGP ([RFC4880]) or S/MIME ([RFC5751]). 2061 10.5. Untrusted Information Sources 2063 An SPF compliant receiver gathers information from the SMTP commands 2064 it receives and from the published DNS records of the sending domain 2065 holder, (e.g., "HELO" domain name, the "MAIL FROM" address from the 2066 envelope, and SPF DNS records published by the domain holder). 2068 10.5.1. Recorded Results 2070 This information, passed to the receiver in the Received-SPF: or 2071 Authentication-Results: trace fields, may be returned to the client 2072 MTA as an SMTP rejection message. If such an SMTP rejection message 2073 is generated, the information from the trace fields has to be checked 2074 for such problems as invalid characters and excessively long lines. 2076 10.5.2. External Explanations 2078 When the authorization check fails, an explanation string could be 2079 included in the reject response. Both the sender and the rejecting 2080 receiver need to be aware that the explanation was determined by the 2081 publisher of the SPF record checked and, in general, not the 2082 receiver. The explanation can contain malicious URLs, or it might be 2083 offensive or misleading. 2085 Explanations returned to sender domains due to "exp" modifiers, 2086 (Section 6.2), were generated by the sender policy published by the 2087 domain holders themselves. As long as messages are only returned 2088 with non-delivery notification ([RFC3464]) to domains publishing the 2089 explanation strings from their own DNS SPF records, the only affected 2090 parties are the original publishers of the domain's SPF records. 2092 In practice, such non-delivery notifications can be misdirected, such 2093 as when an MTA accepts an email and only later generates the 2094 notification to a forged address, or when an email forwarder does not 2095 direct the bounce back to the original sender. 2097 10.5.3. Macro Expansion 2099 Macros (Section 8) allow senders to inject arbitrary text (any non- 2100 null [US-ASCII] character) into receiver DNS queries. It is necesary 2101 to be prepared for hostile or unexpected content. 2103 10.6. Privacy Exposure 2105 Checking SPF records causes DNS queries to be sent to the domain 2106 owner. These DNS queries, especially if they are caused by the 2107 "exists" mechanism, can contain information about who is sending 2108 email and likely to which MTA the email is being sent. This can 2109 introduce some privacy concerns, which are more or less of an issue 2110 depending on local laws and the relationship between the domain owner 2111 and the person sending the email. 2113 11. Contributors and Acknowledgements 2115 This document is largely based on the work of Meng Weng Wong, Mark 2116 Lentczner, and Wayne Schlitt. Although, as this section 2117 acknowledges, many people have contributed to this document, a very 2118 large portion of the writing and editing are due to Meng, Mark, and 2119 Wayne. 2121 This design owes a debt of parentage to [RMX] by Hadmut Danisch and 2122 to [DMP] by Gordon Fecyk. The idea of using a DNS record to check 2123 the legitimacy of an email address traces its ancestry further back 2124 through messages on the namedroppers mailing list by Paul Vixie 2125 [Vixie] (based on suggestion by Jim Miller) and by David Green 2126 [Green]. 2128 Philip Gladstone contributed the concept of macros to the 2129 specification, multiplying the expressiveness of the language and 2130 making per-user and per-IP lookups possible. 2132 The authors of both this document and [RFC4408] would also like to 2133 thank the literally hundreds of individuals who have participated in 2134 the development of this design. They are far too numerous to name, 2135 but they include the following: 2137 The participants in the SPFbis working group. 2138 The folks on the spf-discuss mailing list. 2139 The folks on the SPAM-L mailing list. 2140 The folks on the IRTF ASRG mailing list. 2141 The folks on the IETF MARID mailing list. 2142 The folks on #perl. 2144 12. IANA Considerations 2146 12.1. The SPF DNS Record Type 2148 Per [RFC4408], the IANA assigned the Resource Record Type and Qtype 2149 from the DNS Parameters Registry for the SPF RR type with code 99. 2150 The format of this type is identical to the TXT RR [RFC1035]. The 2151 character content of the record is encoded as [US-ASCII]. Use of 2152 this record type is obsolete for SPF Version 1. 2154 IANA is requested to add an annotation to the SPF RRTYPE saying 2155 "(OBSOLETE - use TXT)" in the DNS Parameters registry. 2157 [NOTE TO RFC EDITOR: (to be changed to " ... has added ..." upon 2158 publication)] 2160 12.2. The Received-SPF Mail Header Field 2162 Per [RFC3864], the "Received-SPF:" header field is added to the IANA 2163 Permanent Message Header Field Registry. The following is the 2164 registration template: 2166 Header field name: Received-SPF 2167 Applicable protocol: mail ([RFC5322]) 2168 Status: Standards Track 2169 Author/Change controller: IETF 2170 Specification document(s): RFC XXXX 2171 [NOTE TO RFC EDITOR: (this document)] 2173 12.3. SPF Modifier Registration 2175 [RFC6652] created a new SPF Modifier Registration. IANA is requested 2176 to change the reference for the exp and redirect modifiers from 2177 [RFC4408] to this document. Their status should not be changed. 2179 13. References 2181 13.1. Normative References 2183 [RFC1035] Mockapetris, P., "Domain names - implementation and 2184 specification", STD 13, RFC 1035, November 1987. 2186 [RFC1123] Braden, R., "Requirements for Internet Hosts - Application 2187 and Support", STD 3, RFC 1123, October 1989. 2189 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2190 Requirement Levels", BCP 14, RFC 2119, March 1997. 2192 [RFC3463] Vaudreuil, G., "Enhanced Mail System Status Codes", 2193 RFC 3463, January 2003. 2195 [RFC3864] Klyne, G., Nottingham, M., and J. Mogul, "Registration 2196 Procedures for Message Header Fields", BCP 90, RFC 3864, 2197 September 2004. 2199 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 2200 Resource Identifier (URI): Generic Syntax", STD 66, 2201 RFC 3986, January 2005. 2203 [RFC4291] Hinden, R. and S. Deering, "IP Version 6 Addressing 2204 Architecture", RFC 4291, February 2006. 2206 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 2207 Specifications: ABNF", STD 68, RFC 5234, January 2008. 2209 [RFC5321] Klensin, J., "Simple Mail Transfer Protocol", RFC 5321, 2210 October 2008. 2212 [RFC5322] Resnick, P., Ed., "Internet Message Format", RFC 5322, 2213 October 2008. 2215 [RFC5451] Kucherawy, M., "Message Header Field for Indicating 2216 Message Authentication Status", RFC 5451, April 2009. 2218 [RFC5598] Crocker, D., "Internet Mail Architecture", RFC 5598, 2219 July 2009. 2221 [RFC5890] Klensin, J., "Internationalized Domain Names for 2222 Applications (IDNA): Definitions and Document Framework", 2223 RFC 5890, August 2010. 2225 [US-ASCII] 2226 American National Standards Institute (formerly United 2227 States of America Standards Institute), "USA Code for 2228 Information Interchange, X3.4", 1968. 2230 ANSI X3.4-1968 has been replaced by newer versions with 2231 slight modifications, but the 1968 version remains 2232 definitive for the Internet. 2234 13.2. Informative References 2236 [DMP] Fecyk, G., "Designated Mailers Protocol". 2238 Work In Progress 2240 [Green] Green, D., "Domain-Authorized SMTP Mail", 2002. 2242 [RFC1034] Mockapetris, P., "Domain names - concepts and facilities", 2243 STD 13, RFC 1034, November 1987. 2245 [RFC1983] Malkin, G., "Internet Users' Glossary", RFC 1983, 2246 August 1996. 2248 [RFC2308] Andrews, M., "Negative Caching of DNS Queries (DNS 2249 NCACHE)", RFC 2308, March 1998. 2251 [RFC2782] Gulbrandsen, A., Vixie, P., and L. Esibov, "A DNS RR for 2252 specifying the location of services (DNS SRV)", RFC 2782, 2253 February 2000. 2255 [RFC3464] Moore, K. and G. Vaudreuil, "An Extensible Message Format 2256 for Delivery Status Notifications", RFC 3464, 2257 January 2003. 2259 [RFC3696] Klensin, J., "Application Techniques for Checking and 2260 Transformation of Names", RFC 3696, February 2004. 2262 [RFC3833] Atkins, D. and R. Austein, "Threat Analysis of the Domain 2263 Name System (DNS)", RFC 3833, August 2004. 2265 [RFC3834] Moore, K., "Recommendations for Automatic Responses to 2266 Electronic Mail", RFC 3834, August 2004. 2268 [RFC4408] Wong, M. and W. Schlitt, "Sender Policy Framework (SPF) 2269 for Authorizing Use of Domains in E-Mail, Version 1", 2270 RFC 4408, April 2006. 2272 [RFC4632] Fuller, V. and T. Li, "Classless Inter-domain Routing 2273 (CIDR): The Internet Address Assignment and Aggregation 2274 Plan", BCP 122, RFC 4632, August 2006. 2276 [RFC4880] Callas, J., Donnerhacke, L., Finney, H., Shaw, D., and R. 2277 Thayer, "OpenPGP Message Format", RFC 4880, November 2007. 2279 [RFC4954] Siemborski, R. and A. Melnikov, "SMTP Service Extension 2280 for Authentication", RFC 4954, July 2007. 2282 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2283 Mail Extensions (S/MIME) Version 3.2 Message 2284 Specification", RFC 5751, January 2010. 2286 [RFC5782] Levine, J., "DNS Blacklists and Whitelists", RFC 5782, 2287 February 2010. 2289 [RFC6409] Gellens, R. and J. Klensin, "Message Submission for Mail", 2290 STD 72, RFC 6409, November 2011. 2292 [RFC6647] Kucherawy, M. and D. Crocker, "Email Greylisting: An 2293 Applicability Statement for SMTP", RFC 6647, June 2012. 2295 [RFC6652] Kitterman, S., "Sender Policy Framework (SPF) 2296 Authentication Failure Reporting Using the Abuse Reporting 2297 Format", RFC 6652, June 2012. 2299 [RFC6686] Kucherawy, M., "Resolution of the Sender Policy Framework 2300 (SPF) and Sender ID Experiments", RFC 6686, July 2012. 2302 [RMX] Danisch, H., "The RMX DNS RR Type for light weight sender 2303 authentication". 2305 Work In Progress 2307 [Vixie] Vixie, P., "Repudiating MAIL FROM", 2002. 2309 Appendix A. Collected ABNF 2311 This section is normative and any discrepancies with the ABNF 2312 fragments in the preceding text are to be resolved in favor of this 2313 grammar. 2315 See [RFC5234] for ABNF notation. Please note that as per this ABNF 2316 definition, literal text strings (those in quotes) are case- 2317 insensitive. Hence, "mx" matches "mx", "MX", "mX", and "Mx". 2319 record = version terms *SP 2320 version = "v=spf1" 2322 terms = *( 1*SP ( directive / modifier ) ) 2324 directive = [ qualifier ] mechanism 2325 qualifier = "+" / "-" / "?" / "~" 2326 mechanism = ( all / include 2327 / A / MX / PTR / IP4 / IP6 / exists ) 2329 all = "all" 2330 include = "include" ":" domain-spec 2331 A = "a" [ ":" domain-spec ] [ dual-cidr-length ] 2332 MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 2333 PTR = "ptr" [ ":" domain-spec ] 2334 IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 2335 IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 2336 exists = "exists" ":" domain-spec 2338 modifier = redirect / explanation / unknown-modifier 2339 redirect = "redirect" "=" domain-spec 2340 explanation = "exp" "=" domain-spec 2341 unknown-modifier = name "=" macro-string 2342 ; where name is not any known modifier 2344 ip4-cidr-length = "/" 1*DIGIT 2345 ip6-cidr-length = "/" 1*DIGIT 2346 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 2348 ip4-network = qnum "." qnum "." qnum "." qnum 2349 qnum = DIGIT ; 0-9 2350 / %x31-39 DIGIT ; 10-99 2351 / "1" 2DIGIT ; 100-199 2352 / "2" %x30-34 DIGIT ; 200-249 2353 / "25" %x30-35 ; 250-255 2354 ; conventional dotted quad notation. e.g., 192.0.2.0 2355 ip6-network = 2356 ; e.g., 2001:DB8::CD30 2358 domain-spec = macro-string domain-end 2359 domain-end = ( "." toplabel [ "." ] ) / macro-expand 2361 toplabel = ( *alphanum ALPHA *alphanum ) / 2362 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 2363 ; LDH rule plus additional TLD restrictions 2364 ; (see [RFC3696], Section 2 for background) 2365 alphanum = ALPHA / DIGIT 2367 explain-string = *( macro-string / SP ) 2369 macro-string = *( macro-expand / macro-literal ) 2370 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 2371 / "%%" / "%_" / "%-" 2372 macro-literal = %x21-24 / %x26-7E 2373 ; visible characters except "%" 2374 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 2375 "c" / "r" / "t" / "v" 2376 transformers = *DIGIT [ "r" ] 2377 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 2379 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 2381 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 2382 [ key-value-list ] CRLF 2384 result = "pass" / "fail" / "softfail" / "neutral" / 2385 "none" / "temperror" / "permerror" 2387 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 2388 [";"] 2390 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 2392 key = "client-ip" / "envelope-from" / "helo" / 2393 "problem" / "receiver" / identity / 2394 mechanism / name 2396 identity = "mailfrom" ; for the "MAIL FROM" identity 2397 / "helo" ; for the "HELO" identity 2398 / name ; other identities 2400 ALPHA = 2401 DIGIT = <0-9 as per [RFC5234]> 2402 SP = 2403 domain = 2404 dot-atom = 2405 quoted-string = 2406 comment = 2407 CFWS = 2408 FWS = 2409 CRLF = 2410 authserv-id = 2411 reasonspec = 2413 Appendix B. Extended Examples 2415 These examples are based on the following DNS setup: 2417 ; A domain with two mail servers, two hosts 2418 ; and two servers at the domain name 2419 $ORIGIN example.com. 2420 @ MX 10 mail-a 2421 MX 20 mail-b 2422 A 192.0.2.10 2423 A 192.0.2.11 2424 amy A 192.0.2.65 2425 bob A 192.0.2.66 2426 mail-a A 192.0.2.129 2427 mail-b A 192.0.2.130 2428 www CNAME example.com. 2430 ; A related domain 2431 $ORIGIN example.org. 2432 @ MX 10 mail-c 2433 mail-c A 192.0.2.140 2435 ; The reverse IP for those addresses 2436 $ORIGIN 2.0.192.in-addr.arpa. 2437 10 PTR example.com. 2438 11 PTR example.com. 2439 65 PTR amy.example.com. 2440 66 PTR bob.example.com. 2441 129 PTR mail-a.example.com. 2442 130 PTR mail-b.example.com. 2443 140 PTR mail-c.example.org. 2445 ; A rogue reverse IP domain that claims to be 2446 ; something it's not 2447 $ORIGIN 0.0.10.in-addr.arpa. 2448 4 PTR bob.example.com. 2450 B.1. Simple Examples 2452 These examples show various possible published records for 2453 example.com and which values if would cause check_host() to 2454 return "pass". Note that is "example.com". 2456 v=spf1 +all 2457 -- any passes 2459 v=spf1 a -all 2460 -- hosts 192.0.2.10 and 192.0.2.11 pass 2462 v=spf1 a:example.org -all 2463 -- no sending hosts pass since example.org has no A records 2465 v=spf1 mx -all 2466 -- sending hosts 192.0.2.129 and 192.0.2.130 pass 2468 v=spf1 mx:example.org -all 2469 -- sending host 192.0.2.140 passes 2471 v=spf1 mx mx:example.org -all 2472 -- sending hosts 192.0.2.129, 192.0.2.130, and 192.0.2.140 pass 2474 v=spf1 mx/30 mx:example.org/30 -all 2475 -- any sending host in 192.0.2.128/30 or 192.0.2.140/30 passes 2477 v=spf1 ptr -all 2478 -- sending host 192.0.2.65 passes (reverse DNS is valid and is in 2479 example.com) 2480 -- sending host 192.0.2.140 fails (reverse DNS is valid, but not 2481 in example.com) 2482 -- sending host 10.0.0.4 fails (reverse IP is not valid) 2484 v=spf1 ip4:192.0.2.128/28 -all 2485 -- sending host 192.0.2.65 fails 2486 -- sending host 192.0.2.129 passes 2488 B.2. Multiple Domain Example 2490 These examples show the effect of related records: 2492 example.org: "v=spf1 include:example.com include:example.net -all" 2494 This record would be used if mail from example.org actually came 2495 through servers at example.com and example.net. Example.org's 2496 designated servers are the union of example.com's and example.net's 2497 designated servers. 2499 la.example.org: "v=spf1 redirect=example.org" 2500 ny.example.org: "v=spf1 redirect=example.org" 2501 sf.example.org: "v=spf1 redirect=example.org" 2503 These records allow a set of domains that all use the same mail 2504 system to make use of that mail system's record. In this way, only 2505 the mail system's record needs to be updated when the mail setup 2506 changes. These domains' records never have to change. 2508 B.3. DNSBL Style Example 2510 Imagine that, in addition to the domain records listed above, there 2511 are these: 2513 $ORIGIN _spf.example.com. 2514 mary.mobile-users A 127.0.0.2 2515 fred.mobile-users A 127.0.0.2 2516 15.15.168.192.joel.remote-users A 127.0.0.2 2517 16.15.168.192.joel.remote-users A 127.0.0.2 2519 The following records describe users at example.com who mail from 2520 arbitrary servers, or who mail from personal servers. 2522 example.com: 2524 v=spf1 mx 2525 include:mobile-users._spf.%{d} 2526 include:remote-users._spf.%{d} 2527 -all 2529 mobile-users._spf.example.com: 2531 v=spf1 exists:%{l1r+}.%{d} 2533 remote-users._spf.example.com: 2535 v=spf1 exists:%{ir}.%{l1r+}.%{d} 2537 B.4. Multiple Requirements Example 2539 Say that your sender policy requires both that the IP address is 2540 within a certain range and that the reverse DNS for the IP matches. 2541 This can be done several ways, including the following: 2543 example.com. SPF ( "v=spf1 " 2544 "-include:ip4._spf.%{d} " 2545 "-include:ptr._spf.%{d} " 2546 "+all" ) 2547 ip4._spf.example.com. SPF "v=spf1 -ip4:192.0.2.0/24 +all" 2548 ptr._spf.example.com. SPF "v=spf1 -ptr +all" 2550 This example shows how the "-include" mechanism can be useful, how an 2551 SPF record that ends in "+all" can be very restrictive, and the use 2552 of De Morgan's Law. 2554 Appendix C. Change History 2556 Changes since RFC 4408 (to be removed prior to publication) 2558 Moved to standards track 2560 Authors updated 2562 IESG Note regarding experimental use replaced with discussion of 2563 results 2565 Process errata: 2567 Add %v macro to ABNF grammar 2569 Replace "uric" by "unreserved" 2571 Recommend an SMTP reply code for optional permerror rejections 2573 Correct syntax in Received-SPF examples 2575 Fix unknown-modifier clause is too greedy in ABNF 2577 Correct use of empty domain-spec on exp modifier 2579 Fix minor typo errata 2581 Convert to spfbis working group draft, 2582 draft-ietf-spfbis-4408bis-00 2584 Addressed Ticket #1, RFC 4408 Section 2.5.6 - Temporary errors by 2585 giving the option to turn repeated SERVFAIL into permerror and 2586 adding RFC 2308 reference. 2588 Clarified text about IPv4 mapped addresses to resolve test suite 2589 ambiguity 2591 Clarified ambiguity about result when more than 10 "mx" or "ptr" 2592 records are returned for lookup to specify permerror. This 2593 resolves one of the test suite ambiguities 2595 Made all references to result codes lower case per issue #7 2597 Adjusted section 2.2 Requirement to check mail from per issue #15 2599 Added missing "v" element in macro-letter in the collected ABNF 2600 per issue #16 - section 8.1 was already fixed in the pre-WG draft 2601 Marked ptr and "p" macro deprecated/SHOULD NOT use per issue #27 2603 Expunged lower case may from the draft per issue #8 2605 Expunged "x-" name as an obsolete concept 2607 Updated obslete references: RFC2821 to RFC5321, RFC2822 to 2608 RFC5322, and RFC4234 to RFC5234 2610 Refer to RFC6647 to describe greylisting instead of trying to 2611 describe it directly. 2613 Updated informative references to the current versions. 2615 Added definition for deprecated since there are questions. 2617 Start to rework section 9 with some RFC5598 terms. 2619 Added mention of RFC 6552 feedback reports in section 9. 2621 Added draft-ietf-spfbis-experiment as an informational reference. 2623 Drop Type SPF. 2625 Try and clarify informational nature of RFC3696 2627 Fix ABNF nits and add missing definitions per Bill's ABNF checker. 2629 Make DNS lookup time limit SHOULD instead of MAY. 2631 Reorganize and clarify processing limits. Move hard limits to new 2632 section 4.6.4, Evaluation Limits. Move advice to non-normative 2633 section 9. 2635 Removed paragraph in section 10.1 about limiting total data 2636 volumes as it is unused (and removable per the charter) and serves 2637 no purpose (it isn't something that actually can be implemented in 2638 any reasonable way). 2640 Added text and figures from Alessandro Vesely in section 9.1 to 2641 better explain DNS resource limits. 2643 Multiple editorial fixes from Murray Kucherawy's review. 2645 Also based on Murray's review, reworked SMTP identity definitions 2646 and made RFC 5598 a normative reference instead of informative. 2647 This is a downref that will have to be mentioned in the last call. 2649 Added RFC 3834 as an informative reference about backscatter. 2651 Added IDN requirements and normative reference to RFC 5890 to deal 2652 with the question "like DKIM did it.: 2654 Added informative reference to RFC 4632 for CIDR and use CIDR 2655 prefix length instead of CIDR-length to match its terminology. 2657 Added RFC 5782 informative reference on DNSxLs to support 2658 improving the exists description. 2660 Added text on creating a Authentication-Results header field that 2661 matches the Received-SPF header field information and added a 2662 normative reference to RFC 5451. 2664 Added informative reference to RFC 2782 due to SRV mention. 2666 Added informative reference to RFC 3464 due to DSN mention. 2668 Added informative reference to RFC 5617 for it's DNS wildcard use. 2670 Added informative reference to RFC 5782 to enhance the explanation 2671 of how the exists mechanism works. Clarified the intended match/ 2672 no-match method. 2674 Added new sections on Receiver policy for SPF pass, fail, and 2675 permerror. 2677 Added new section 9 discussion on treatment of bounces and the 2678 significance of HELO records. 2680 Added request to IANA to update the SPF modifier registry. 2682 Author's Address 2684 Scott Kitterman 2685 Kitterman Technical Services 2686 3611 Scheel Dr 2687 Ellicott City, MD 21042 2688 United States of America 2690 Email: scott@kitterman.com