idnits 2.17.1 draft-ietf-spfbis-4408bis-13.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 1677 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 (March 25, 2013) is 4050 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 2347, 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) March 25, 2013 5 Intended status: Standards Track 6 Expires: September 26, 2013 8 Sender Policy Framework (SPF) for Authorizing Use of Domains in Email, 9 Version 1 10 draft-ietf-spfbis-4408bis-13.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 September 26, 2013. 41 Copyright Notice 43 Copyright (c) 2013 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. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 72 1.1.1. Keywords . . . . . . . . . . . . . . . . . . . . . . . 6 73 1.1.2. Imported Definitions . . . . . . . . . . . . . . . . . 6 74 1.1.3. MAIL FROM Definition . . . . . . . . . . . . . . . . . 7 75 1.1.4. HELO Definition . . . . . . . . . . . . . . . . . . . 7 76 1.2. check_host() . . . . . . . . . . . . . . . . . . . . . . . 7 77 2. Operational Overview . . . . . . . . . . . . . . . . . . . . . 8 78 2.1. The "HELO" Identity . . . . . . . . . . . . . . . . . . . 8 79 2.2. The "MAIL FROM" Identity . . . . . . . . . . . . . . . . . 8 80 2.3. Publishing Authorization . . . . . . . . . . . . . . . . . 8 81 2.4. Checking Authorization . . . . . . . . . . . . . . . . . . 9 82 2.5. Location of Checks . . . . . . . . . . . . . . . . . . . . 10 83 2.6. Results of Evaluation . . . . . . . . . . . . . . . . . . 10 84 2.6.1. None . . . . . . . . . . . . . . . . . . . . . . . . . 11 85 2.6.2. Neutral . . . . . . . . . . . . . . . . . . . . . . . 11 86 2.6.3. Pass . . . . . . . . . . . . . . . . . . . . . . . . . 11 87 2.6.4. Fail . . . . . . . . . . . . . . . . . . . . . . . . . 11 88 2.6.5. Softfail . . . . . . . . . . . . . . . . . . . . . . . 11 89 2.6.6. Temperror . . . . . . . . . . . . . . . . . . . . . . 11 90 2.6.7. Permerror . . . . . . . . . . . . . . . . . . . . . . 11 91 3. SPF Records . . . . . . . . . . . . . . . . . . . . . . . . . 12 92 3.1. DNS Resource Records . . . . . . . . . . . . . . . . . . . 12 93 3.2. Multiple DNS Records . . . . . . . . . . . . . . . . . . . 13 94 3.3. Multiple Strings in a Single DNS record . . . . . . . . . 13 95 3.4. Record Size . . . . . . . . . . . . . . . . . . . . . . . 13 96 3.5. Wildcard Records . . . . . . . . . . . . . . . . . . . . . 13 97 4. The check_host() Function . . . . . . . . . . . . . . . . . . 15 98 4.1. Arguments . . . . . . . . . . . . . . . . . . . . . . . . 15 99 4.2. Results . . . . . . . . . . . . . . . . . . . . . . . . . 15 100 4.3. Initial Processing . . . . . . . . . . . . . . . . . . . . 16 101 4.4. Record Lookup . . . . . . . . . . . . . . . . . . . . . . 16 102 4.5. Selecting Records . . . . . . . . . . . . . . . . . . . . 16 103 4.6. Record Evaluation . . . . . . . . . . . . . . . . . . . . 17 104 4.6.1. Term Evaluation . . . . . . . . . . . . . . . . . . . 17 105 4.6.2. Mechanisms . . . . . . . . . . . . . . . . . . . . . . 17 106 4.6.3. Modifiers . . . . . . . . . . . . . . . . . . . . . . 18 107 4.6.4. DNS Lookup Limits . . . . . . . . . . . . . . . . . . 18 108 4.7. Default Result . . . . . . . . . . . . . . . . . . . . . . 19 109 4.8. Domain Specification . . . . . . . . . . . . . . . . . . . 19 110 5. Mechanism Definitions . . . . . . . . . . . . . . . . . . . . 21 111 5.1. "all" . . . . . . . . . . . . . . . . . . . . . . . . . . 22 112 5.2. "include" . . . . . . . . . . . . . . . . . . . . . . . . 22 113 5.3. "a" . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 114 5.4. "mx" . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 115 5.5. "ptr" (do not use) . . . . . . . . . . . . . . . . . . . . 24 116 5.6. "ip4" and "ip6" . . . . . . . . . . . . . . . . . . . . . 26 117 5.7. "exists" . . . . . . . . . . . . . . . . . . . . . . . . . 26 118 6. Modifier Definitions . . . . . . . . . . . . . . . . . . . . . 28 119 6.1. redirect: Redirected Query . . . . . . . . . . . . . . . . 28 120 6.2. exp: Explanation . . . . . . . . . . . . . . . . . . . . . 29 121 7. Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 122 7.1. Formal Specification . . . . . . . . . . . . . . . . . . . 31 123 7.2. Macro Definitions . . . . . . . . . . . . . . . . . . . . 31 124 7.3. Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 32 125 7.4. Expansion Examples . . . . . . . . . . . . . . . . . . . . 34 126 8. Result Handling . . . . . . . . . . . . . . . . . . . . . . . 36 127 8.1. None . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 128 8.2. Neutral . . . . . . . . . . . . . . . . . . . . . . . . . 36 129 8.3. Pass . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 130 8.4. Fail . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 131 8.5. Softfail . . . . . . . . . . . . . . . . . . . . . . . . . 37 132 8.6. Temperror . . . . . . . . . . . . . . . . . . . . . . . . 38 133 8.7. Permerror . . . . . . . . . . . . . . . . . . . . . . . . 38 134 9. Recording The Result . . . . . . . . . . . . . . . . . . . . . 39 135 9.1. The Received-SPF Header Field . . . . . . . . . . . . . . 39 136 9.2. SPF Results in the Authentication-Results Header Field . . 41 137 10. Effects on Infrastructure . . . . . . . . . . . . . . . . . . 43 138 10.1. Sending Domains . . . . . . . . . . . . . . . . . . . . . 43 139 10.1.1. DNS Resource Considerations . . . . . . . . . . . . . 43 140 10.1.2. Administrator's Considerations . . . . . . . . . . . . 44 141 10.1.3. Bounces . . . . . . . . . . . . . . . . . . . . . . . 45 142 10.2. Receivers . . . . . . . . . . . . . . . . . . . . . . . . 45 143 10.3. Mediators . . . . . . . . . . . . . . . . . . . . . . . . 46 144 11. Security Considerations . . . . . . . . . . . . . . . . . . . 47 145 11.1. Processing Limits . . . . . . . . . . . . . . . . . . . . 47 146 11.2. SPF-Authorized Email May Contain Other False Identities . 48 147 11.3. Spoofed DNS and IP Data . . . . . . . . . . . . . . . . . 48 148 11.4. Cross-User Forgery . . . . . . . . . . . . . . . . . . . . 48 149 11.5. Untrusted Information Sources . . . . . . . . . . . . . . 49 150 11.5.1. Recorded Results . . . . . . . . . . . . . . . . . . . 49 151 11.5.2. External Explanations . . . . . . . . . . . . . . . . 49 152 11.5.3. Macro Expansion . . . . . . . . . . . . . . . . . . . 49 153 11.6. Privacy Exposure . . . . . . . . . . . . . . . . . . . . . 49 154 11.7. Delivering Mail Producing a 'Fail' Result . . . . . . . . 50 155 12. Contributors and Acknowledgements . . . . . . . . . . . . . . 51 156 13. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 52 157 13.1. The SPF DNS Record Type . . . . . . . . . . . . . . . . . 52 158 13.2. The Received-SPF Mail Header Field . . . . . . . . . . . . 52 159 13.3. SPF Modifier Registration . . . . . . . . . . . . . . . . 52 160 14. References . . . . . . . . . . . . . . . . . . . . . . . . . . 53 161 14.1. Normative References . . . . . . . . . . . . . . . . . . . 53 162 14.2. Informative References . . . . . . . . . . . . . . . . . . 54 163 Appendix A. Collected ABNF . . . . . . . . . . . . . . . . . . . 56 164 Appendix B. Extended Examples . . . . . . . . . . . . . . . . . . 59 165 B.1. Simple Examples . . . . . . . . . . . . . . . . . . . . . 59 166 B.2. Multiple Domain Example . . . . . . . . . . . . . . . . . 60 167 B.3. DNSBL Style Example . . . . . . . . . . . . . . . . . . . 61 168 B.4. Multiple Requirements Example . . . . . . . . . . . . . . 61 169 Appendix C. Further Testing Advice . . . . . . . . . . . . . . . 62 170 Appendix D. SPF/Mediator Interactions . . . . . . . . . . . . . . 63 171 D.1. Originating ADMDs . . . . . . . . . . . . . . . . . . . . 63 172 D.2. Mediators . . . . . . . . . . . . . . . . . . . . . . . . 64 173 D.3. Receving ADMDs . . . . . . . . . . . . . . . . . . . . . . 64 174 Appendix E. Mail Services . . . . . . . . . . . . . . . . . . . . 65 175 Appendix F. MTA Relays . . . . . . . . . . . . . . . . . . . . . 66 176 Appendix G. Local Policy Considerations . . . . . . . . . . . . . 67 177 G.1. Policy For SPF Pass . . . . . . . . . . . . . . . . . . . 67 178 G.2. Policy For SPF Fail . . . . . . . . . . . . . . . . . . . 67 179 G.3. Policy For SPF Permerror . . . . . . . . . . . . . . . . . 68 180 Appendix H. Protocol Status . . . . . . . . . . . . . . . . . . . 69 181 Appendix I. Change History . . . . . . . . . . . . . . . . . . . 70 182 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 73 184 1. Introduction 186 The current email infrastructure has the property that any host 187 injecting mail into the system can use any DNS domain name it wants 188 in each of the various identifiers specified by [RFC5321] and 189 [RFC5322]. Although this feature is desirable in some circumstances, 190 it is a major obstacle to reducing Unsolicited Bulk Email (UBE, aka 191 spam). Furthermore, many domain owning ADMDs (ADministrative 192 Management Domains, see [RFC5598]) are understandably concerned about 193 the ease with which other entities can make use of their domain 194 names, often with malicious intent. 196 This document defines a protocol by which ADMDs can authorize hosts 197 to use their domain names in the "MAIL FROM" or "HELO" identities. 198 Compliant ADMDs publish Sender Policy Framework (SPF) records in the 199 DNS specifying which hosts are permitted to use their names, and 200 compliant mail receivers use the published SPF records to test the 201 authorization of sending Mail Transfer Agents (MTAs) using a given 202 "HELO" or "MAIL FROM" identity during a mail transaction. 204 An additional benefit to mail receivers is that after the use of an 205 identity is verified, local policy decisions about the mail can be 206 made based on the sender's domain, rather than the host's IP address. 207 This is advantageous because reputation of domain names is likely to 208 be more accurate than reputation of host IP addresses. Furthermore, 209 if a claimed identity fails verification, local policy can take 210 stronger action against such email, such as rejecting it. 212 1.1. Terminology 214 1.1.1. Keywords 216 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 217 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 218 "OPTIONAL" in this document are to be interpreted as described in 219 [RFC2119]. 221 1.1.2. Imported Definitions 223 The ABNF tokens "ALPHA", "DIGIT", and "SP" are defined in [RFC5234]. 225 The token "local-part" is defined in [RFC5321]. 227 "dot-atom", "quoted-string", "comment", "CFWS", "FWS", and "CRLF" are 228 defined in [RFC5322]. 230 1.1.3. MAIL FROM Definition 232 This document is concerned with the portion of a mail message 233 commonly called "envelope sender", "return path", "reverse path", 234 "bounce address", "5321 FROM", "MAIL FROM", or RFC5321.MailFrom. 235 Since these terms are either not well defined or often used casually, 236 this document uses "MAIL FROM" for consistency. This means the 237 RFC5321.MailFrom as defined in [RFC5598]. Note that other terms that 238 might superficially look like the common terms, such as "reverse- 239 path", are used only with the defined meanings from normative 240 documents. 242 1.1.4. HELO Definition 244 This document also makes use of the HELO/EHLO identity. The "HELO" 245 identity derives from either the SMTP HELO or EHLO command (see 246 [RFC5321]). Since HELO and EHLO can, in many cases, be used 247 interchangeably, they are identified commonly as "HELO" in this 248 document. This means RFC5321.HELO/.EHLO as defined in [RFC5598]. 249 These commands supply the identity of the SMTP client (sending host) 250 for the SMTP session. 252 1.2. check_host() 254 Section 4 introduces an algorithm to evaluate an SPF policy against 255 an arriving email transaction. In an early implementation, this 256 algorithm was encoded in a function called check_host(). That name 257 is used in this document as symbolic of the SPF evaluation algorithm, 258 but of course implementers are not required to use this name. 260 2. Operational Overview 262 2.1. The "HELO" Identity 264 It is RECOMMENDED that SPF verifiers not only check the "MAIL FROM" 265 identity, but also separately check the "HELO" identity by applying 266 the check_host() function (Section 4) to the "HELO" identity as the 267 . Checking "HELO" promotes consistency of results and can 268 reduce DNS resource usage. Additionally, since SPF records published 269 for "HELO" identities refer to a single host, when available, they 270 are a very reliable source of host authorization status. 272 Note that requirements for the domain presented in the EHLO or HELO 273 command are not always clear to the sending party, and SPF verifiers 274 MUST be prepared for the "HELO" identity to be malformed or an IP 275 address literal. This SPF check can only be performed when the 276 "HELO" string is a valid fully qualified domain. 278 2.2. The "MAIL FROM" Identity 280 SPF verifiers MUST check the ""MAIL FROM" identity if a completed 281 "HELO" check has not reached a definitive policy result by applying 282 the check_host() function to the "MAIL FROM" identity as the 283 . 285 [RFC5321] allows the reverse-path to be null (see Section 4.5.5 in 286 [RFC5321]). In this case, there is no explicit sender mailbox, and 287 such a message can be assumed to be a notification message from the 288 mail system itself. When the reverse-path is null, this document 289 defines the "MAIL FROM" identity to be the mailbox composed of the 290 local-part "postmaster" and the "HELO" identity (which might or might 291 not have been checked separately before). 293 2.3. Publishing Authorization 295 An SPF-compliant domain MUST have valid SPF records as described in 296 Section 3. These records authorize the use of the relevant domain 297 names in the "HELO" and "MAIL FROM" identities by the MTAs specified 298 therein. 300 SPF results can be used to make both positive (source is authorized) 301 and negative (source is not authorized) determinations. If domain 302 owners choose to publish SPF records and want to support receivers 303 making negative authorization determinations, then they MUST publish 304 records that end in "-all", or redirect to other records that do, 305 otherwise, no definitive determination of authorization can be made. 306 Potential issues and mitigations associated with negative 307 determinations are discussed in Section 10. 309 ADMDs can publish SPF records that explicitly authorize no hosts for 310 domain names that are neither used in the domain part of email 311 addresses nor expected to originate mail. 313 When changing SPF records, care has to be taken to ensure that there 314 is a transition period so that the old policy remains valid until all 315 legitimate email can reasonably expect to have been checked. 316 [RFC5321] Section 4.5.4.1 discusses how long a message might be in 317 transit. While offline checks are possible, the closer to the 318 original transmission time checks are performed, the more likely they 319 are to get an SPF result that matches the sending ADMD intent at the 320 time the message was sent. 322 2.4. Checking Authorization 324 A mail receiver can perform a set of SPF checks for each mail message 325 it receives. An SPF check tests the authorization of a client host 326 to emit mail with a given identity. Typically, such checks are done 327 by a receiving MTA, but can be performed elsewhere in the mail 328 processing chain so long as the required information is available and 329 reliable. At least the "MAIL FROM" identity MUST be checked, but it 330 is RECOMMENDED that the "HELO" identity also be checked beforehand. 332 Without explicit approval of the domain owner, checking other 333 identities against SPF version 1 records is NOT RECOMMENDED because 334 there are cases that are known to give incorrect results. For 335 example, almost all mailing lists rewrite the "MAIL FROM" identity 336 (see Section 10.3), but some do not change any other identities in 337 the message. Documents that define other identities will have to 338 define the method for explicit approval. 340 It is possible that mail receivers will use the SPF check as part of 341 a larger set of tests on incoming mail. The results of other tests 342 might influence whether or not a particular SPF check is performed. 343 For example, finding the sending host's IP address on a local white 344 list might cause all other tests to be skipped and all mail from that 345 host to be accepted. 347 When a mail receiver decides to perform an SPF check, it MUST use a 348 correctly-implemented check_host() function (Section 4) evaluated 349 with the correct parameters. Although the test as a whole is 350 optional, once it has been decided to perform a test it has to be 351 performed as specified so that the correct semantics are preserved 352 between publisher and receiver. 354 To make the test, the mail receiver MUST evaluate the check_host() 355 function with the arguments set as follows: 357 - the IP address of the SMTP client that is emitting the 358 mail, either IPv4 or IPv6. 360 - the domain portion of the "MAIL FROM" or "HELO" identity. 362 - the "MAIL FROM" or "HELO" identity. 364 Although invalid, malformed, or non-existent domains cause SPF checks 365 to return "none" because no SPF record can be found, it has long been 366 the policy of many MTAs to reject email from such domains, especially 367 in the case of invalid "MAIL FROM". Rejecting email will prevent one 368 method of circumventing of SPF records. 370 Implementations have to take care to correctly extract the 371 from the data given with the SMTP MAIL FROM command as many MTAs will 372 still accept such things as source routes (see [RFC5321], Appendix 373 C), the %-hack (see [RFC1123]), and bang paths (see [RFC1983]). 374 These archaic features have been maliciously used to bypass security 375 systems. 377 2.5. Location of Checks 379 The authorization check SHOULD be performed during the processing of 380 the SMTP transaction that sends the mail. This reduces the 381 complexity of determining the correct IP address to use as an input 382 to check_host() and allows errors to be returned directly to the 383 sending MTA by way of SMTP replies. 385 Performing the authorization other than using the return-path and 386 client address at the time of the MAIL command during the SMTP 387 transaction can cause problems, such as the following: (1) It might 388 be difficult to accurately extract the required information from 389 potentially deceptive headers; (2) legitimate email might fail 390 because the sender's policy had since changed. 392 Generating non-delivery notifications to forged identities that have 393 failed the authorization check is a source of backscatter and SHOULD 394 be avoided. Section 2 of [RFC3834] describes backscatter and the 395 problems it causes. 397 2.6. Results of Evaluation 399 Section 4 defines check_host(), a model function definition that uses 400 the inputs defined above and the sender's policy published in the DNS 401 to reach a conclusion about client authorization. An SPF verifier 402 implements something semantically identical to the function defined 403 there. 405 This section enumerates and briefly defines the possible outputs of 406 that function. Information about how to handle these outputs is in 407 Section 8. 409 2.6.1. None 411 A result of "none" means either (a) no syntactically valid DNS domain 412 name was extracted from the SMTP session that could be used as the 413 one to be authorized, or (b) no TXT records were retrieved from the 414 DNS that appeared to be intended for use by SPF verifiers. 416 2.6.2. Neutral 418 The domain owner has explicitly stated that it is not asserting 419 whether the IP address is authorized. This result MUST be treated 420 exactly like the "none" result; the distinction exists only for 421 informational purposes. 423 2.6.3. Pass 425 A "pass" result means that the client is authorized to inject mail 426 with the given identity. The domain can now, in the sense of 427 reputation, be considered responsible for sending the message. 428 Further policy checks can now proceed with confidence in the 429 legitimate use of the identity. This is further discussed in 430 Appendix G.1. 432 2.6.4. Fail 434 A "fail" result is an explicit statement that the client is not 435 authorized to use the domain in the given identity. 437 2.6.5. Softfail 439 The domain owner has published a weak statement that the host is 440 probably not authorized. It has not published a stronger, more 441 definitive policy that results in a "fail" 443 2.6.6. Temperror 445 A "temperror" result means the SPF verifier encountered a transient 446 (generally DNS) error while performing the check. 448 2.6.7. Permerror 450 A "permerror" result means the domain's published records could not 451 be correctly interpreted. This signals an error condition that 452 definitely requires manual intervention to be resolved. 454 3. SPF Records 456 An SPF record is a DNS record that declares which hosts are, and are 457 not, authorized to use a domain name for the "HELO" and "MAIL FROM" 458 identities. Loosely, the record partitions all hosts into permitted 459 and not-permitted sets (though some hosts might fall into neither 460 category). 462 The SPF record is a single string of text. The record format is 463 described below in Section 4. An example record is the following: 465 v=spf1 +mx a:colo.example.com/28 -all 467 This record has a version of "spf1" and three directives: "+mx", 468 "a:colo.example.com/28" (the + is implied), and "-all". 470 Each SPF record is placed in the DNS tree at the host name it 471 pertains to, not a subdomain under it, such as is done with SRV 472 records [RFC2782]. 474 The example in this section might be published via these lines in a 475 domain zone file: 477 example.com. TXT "v=spf1 +mx a:colo.example.com/28 -all" 478 smtp-out.example.com. TXT "v=spf1 a -all" 480 Since TXT records have multiple uses, beware of other TXT records 481 published there for other purposes. They might cause problems with 482 size limits (see Section 3.4) and care has to be taken to ensure only 483 SPF records are used for SPF processing. 485 ADMDs publishing SPF records SHOULD try to keep the number of 486 "include" mechanisms and chained "redirect" modifiers to a minimum. 487 ADMDs SHOULD also try to minimize the amount of other DNS information 488 needed to evaluate a record. Section 4.6.4 and Section 10.1.1 489 provide some suggestions on how to achieve this. 491 3.1. DNS Resource Records 493 SPF records MUST be published as a DNS TXT (type 16) Resource Record 494 (RR) [RFC1035] only. The character content of the record is encoded 495 as [US-ASCII]. Use of alternate DNS RR types was supported in SPF's 496 experimental phase, but has been discontinued. See Appendix A of 497 [RFC6686] for further information. 499 3.2. Multiple DNS Records 501 A domain name MUST NOT have multiple records that would cause an 502 authorization check to select more than one record. See Section 4.5 503 for the selection rules. 505 3.3. Multiple Strings in a Single DNS record 507 As defined in [RFC1035] sections 3.3.14 and 3.3, a single text DNS 508 record can be composed of more than one string. If a published 509 record contains multiple character-strings, then the record MUST be 510 treated as if those strings are concatenated together without adding 511 spaces. For example: 513 IN TXT "v=spf1 .... first" "second string..." 515 MUST be treated as equivalent to: 517 IN TXT "v=spf1 .... firstsecond string..." 519 TXT records containing multiple strings are useful in constructing 520 records that would exceed the 255-byte maximum length of a character- 521 string within a single TXT record. 523 3.4. Record Size 525 The published SPF record for a given domain name SHOULD remain small 526 enough that the results of a query for it will fit within 512 octets. 527 This UDP limit is defined in [RFC1035] section 2.3.4. This will keep 528 even older DNS implementations from falling over to TCP. Since the 529 answer size is dependent on many things outside the scope of this 530 document, it is only possible to give this guideline: If the combined 531 length of the DNS name and the text of all the records of a given 532 type is under 450 octets, then DNS answers ought to fit in UDP 533 packets. Records that are too long to fit in a single UDP packet 534 could be silently ignored by SPF verifiers due to firewall and other 535 issues that cause DNS over TCP to be less reliable than DNS over UDP. 537 Note that when computing the sizes for replies to queries of the TXT 538 format, one has to take into account any other TXT records published 539 at the domain name. Similarly, the sizes for replies to all queries 540 related to SPF have to be evaluated to fit in a single UDP packet. 542 3.5. Wildcard Records 544 Use of wildcard records for publishing is discouraged and care has to 545 be taken if they are used. If a zone includes wildcard MX records, 546 it might want to publish wildcard declarations, subject to the same 547 requirements and problems. In particular, the declaration MUST be 548 repeated for any host that has any RR records at all, and for 549 subdomains thereof. Consider the example in [RFC1034], Section 550 4.3.3. Based on that, we can do the following: 552 EXAMPLE.COM. MX 10 A.EXAMPLE.COM 553 EXAMPLE.COM. TXT "v=spf1 a:A.EXAMPLE.COM -all" 555 *.EXAMPLE.COM. MX 10 A.EXAMPLE.COM 556 *.EXAMPLE.COM. TXT "v=spf1 a:A.EXAMPLE.COM -all" 558 A.EXAMPLE.COM. A 203.0.113.1 559 A.EXAMPLE.COM. MX 10 A.EXAMPLE.COM 560 A.EXAMPLE.COM. TXT "v=spf1 a:A.EXAMPLE.COM -all" 562 *.A.EXAMPLE.COM. MX 10 A.EXAMPLE.COM 563 *.A.EXAMPLE.COM. TXT "v=spf1 a:A.EXAMPLE.COM -all" 565 SPF records have to be listed twice for every name within the zone: 566 once for the name, and once with a wildcard to cover the tree under 567 the name, in order to cover all domains in use in outgoing mail. 569 4. The check_host() Function 571 This description is not an API (Application Program Interface) 572 definition, but rather a function description used to illustrate the 573 algorithm. A compliant SPF implementation MUST do something 574 semantically equivalent to this description. 576 The check_host() function fetches SPF records, parses them, and 577 evaluates them to determine whether a particular host is or is not 578 permitted to send mail with a given identity. Mail receivers that 579 perform this check MUST correctly evaluate the check_host() function 580 as described here. 582 Implementations MAY use a different algorithm than the canonical 583 algorithm defined here, so long as the results are the same in all 584 cases. 586 4.1. Arguments 588 The check_host() function takes these arguments: 590 - the IP address of the SMTP client that is emitting the 591 mail, either IPv4 or IPv6. 593 - the domain that provides the sought-after authorization 594 information; initially, the domain portion of the "MAIL 595 FROM" or "HELO" identity. 597 - the "MAIL FROM" or "HELO" identity. 599 For recursive evaluations, the domain portion of might not 600 be the same as the argument when check_host() is initially 601 evaluated. In most other cases it will be the same. (See 602 Section 5.2 below). 604 Note that the argument might not be a well-formed domain 605 name. For example, if the reverse-path was null, then the EHLO/HELO 606 domain is used, with its associated problems (see Section 2.1). In 607 these cases, check_host() is defined in Section 4.3 to return a 608 "none" result. 610 4.2. Results 612 The function check_host() can return one of several results described 613 in Section 2.6. Based on the result, the action to be taken is 614 determined by the local policies of the receiver. This is discussed 615 in Section 8. 617 4.3. Initial Processing 619 If the is malformed (e.g. label longer than 63 characters, 620 zero-length label not at the end, etc.) or is not a fully qualified 621 domain name, or if the DNS lookup returns "domain does not exist" 622 (RCODE 3), check_host() immediately returns the result "none". 623 Properly formed domains are fully qualified email domains as 624 described in [RFC5321] Section 2.3.5. Internationalized domain names 625 MUST be encoded as A-labels, as described in Section 2.3 of 626 [RFC5890].on 2.3 of [RFC5890]. 628 If the has no local-part, substitute the string "postmaster" 629 for the local-part. 631 4.4. Record Lookup 633 In accordance with how the records are published (see Section 3 634 above), a DNS query needs to be made for the name, querying 635 for type TXT only. 637 If all DNS lookups that are made return a server failure (RCODE 2), 638 or other error (RCODE other than 0 or 3), or time out, then 639 check_host() terminates immediately with the result "temperror". 640 Alternatively, for a server failure (RCODE 2) result, check_host() 641 MAY track failures and treat multiple failures within 24 hours for 642 the same domain as "permerror". 644 This alternative is intended to shorten the queue time of messages 645 that cannot be accepted, by returning a permanent negative completion 646 reply code to the client, instead of a transient one. [RFC2308] 647 suggests on an algorithm for doing such tracking and handling of 648 server failure codes. 650 4.5. Selecting Records 652 Records begin with a version section: 654 record = version terms *SP 655 version = "v=spf1" 657 Starting with the set of records that were returned by the lookup, 658 discard records that do not begin with a version section of exactly 659 "v=spf1". Note that the version section is terminated either by an 660 SP character or the end of the record. A record with a version 661 section of "v=spf10" does not match and is discarded. 663 If the resultant record set includes no records, check_host() 664 produces the "none" result. If the resultant record set includes 665 more than one record, check_host() produces the "permerror" result. 667 4.6. Record Evaluation 669 The check_host() function parses and interprets the SPF record to 670 find a result for the current test. If there are any syntax errors 671 anywhere in the record, check_host() returns immediately with the 672 result "permerror", without further interpretation. 674 4.6.1. Term Evaluation 676 There are two types of terms: mechanisms and modifiers. A record 677 contains an ordered list of these as specified in the following 678 Augmented Backus-Naur Form (ABNF). 680 terms = *( 1*SP ( directive / modifier ) ) 682 directive = [ qualifier ] mechanism 683 qualifier = "+" / "-" / "?" / "~" 684 mechanism = ( all / include 685 / A / MX / PTR / IP4 / IP6 / exists ) 686 modifier = redirect / explanation / unknown-modifier 687 unknown-modifier = name "=" macro-string 688 ; where name is not any known modifier 690 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 692 Most mechanisms allow a ":" or "/" character after the name. 694 Modifiers always contain an equals ('=') character immediately after 695 the name, and before any ":" or "/" characters that might be part of 696 the macro-string. 698 Terms that do not contain any of "=", ":", or "/" are mechanisms, as 699 defined in Section 5. 701 As per the definition of the ABNF notation in [RFC5234], mechanism 702 and modifier names are case-insensitive. 704 4.6.2. Mechanisms 706 Each mechanism is considered in turn from left to right. If there 707 are no more mechanisms, the result is specified in Section 4.7. 709 When a mechanism is evaluated, one of three things can happen: it can 710 match, not match, or return an exception. 712 If it matches, processing ends and the qualifier value is returned as 713 the result of that record. If it does not match, processing 714 continues with the next mechanism. If it returns an exception, 715 mechanism processing ends and the exception value is returned. 717 The possible qualifiers, and the results they cause check_host() to 718 return are as follows: 720 "+" pass 721 "-" fail 722 "~" softfail 723 "?" neutral 725 The qualifier is optional and defaults to "+". 727 When a mechanism matches and the qualifier is "-", then a "fail" 728 result is returned and the explanation string is computed as 729 described in Section 6.2. 731 The specific mechanisms are described in Section 5. 733 4.6.3. Modifiers 735 Modifiers are not mechanisms. They do not return match or not-match. 736 Instead, they provide additional information. Although modifiers do 737 not directly affect the evaluation of the record, the "redirect" 738 modifier has an effect after all the mechanisms have been evaluated. 740 4.6.4. DNS Lookup Limits 742 SPF implementations MUST limit the total number of mechanisms and 743 modifiers ("terms") that cause any DNS query to at most 10 during SPF 744 evaluation. Specifically, the "include", "a", "mx", "ptr", and 745 "exists" mechanisms as well as the "redirect" modifier count against 746 this collective limit. The "all", "ip4", and "ip6" mechanisms do not 747 count against this limit. If this number is exceeded during a check, 748 a permerror MUST be returned. The "exp" modifier does not count 749 against this limit because the DNS lookup to fetch the explanation 750 string occurs after the SPF record evaluation has been completed. 752 When evaluating the "mx" mechanism, the number of "MX" resource 753 records queried is included in the overall limit of 10 mechanisms/ 754 modifiers that cause DNS look ups described above. The evaluation of 755 each "MX" record MUST NOT result in querying more than 10 "A" 756 resource records. If this limit is exceeded, the "mx" mechanism MUST 757 produce a "permerror" result. 759 When evaluating the "ptr" mechanism or the %{p} macro, the number of 760 "PTR" resource records queried is included in the overall limit of 10 761 mechanisms/modifiers that cause DNS look ups described above. The 762 evaluation of each "PTR" record MUST NOT result in querying more than 763 10 "A" resource records. If this limit is exceeded, all records 764 other than the first 10 MUST be ignored. 766 The reason for the disparity is that the set of and contents of the 767 MX record are under control of the domain owner, while the set of and 768 contents of PTR records are under control of the owner of the IP 769 address actually making the connection. 771 These limits are per mechanism or macro in the record, and are in 772 addition to the lookup limits specified above. 774 MTAs or other processors SHOULD impose a limit on the maximum amount 775 of elapsed time to evaluate check_host(). Such a limit SHOULD allow 776 at least 20 seconds. If such a limit is exceeded, the result of 777 authorization SHOULD be "temperror". 779 As described at the end of Section 11.1, there may be cases where it 780 is useful to limit the number of "terms" for which DNS queries return 781 either a positive answer (RCODE 0) with an answer count of 0, or a no 782 such record (RCODE 3) answer. These are sometimes collectively 783 referred to as "void lookups". SPF implementations SHOULD limit 784 "void lookups" to two. An implementation MAY choose to make such a 785 limit configurable. In this case, a default of two is RECOMMENDED. 787 4.7. Default Result 789 If none of the mechanisms match and there is no "redirect" modifier, 790 then the check_host() returns a result of "neutral", just as if 791 "?all" were specified as the last directive. If there is a 792 "redirect" modifier, check_host() proceeds as defined in Section 6.1. 794 Note that records SHOULD always use either a "redirect" modifier or 795 an "all" mechanism to explicitly terminate processing. Although the 796 latter has default (specifically "?all"), it aids debugging efforts 797 if it is explicitly included. 799 For example: 801 v=spf1 +mx -all 802 or 803 v=spf1 +mx redirect=_spf.example.com 805 4.8. Domain Specification 807 Several of these mechanisms and modifiers have a domain-spec section. 808 The domain-spec string is subject to macro expansion (see Section 7). 810 The resulting string is the common presentation form of a fully- 811 qualified DNS name: a series of labels separated by periods. This 812 domain is called the in the rest of this document. 814 Note: The result of the macro expansion is not subject to any further 815 escaping. Hence, this facility cannot produce all characters that 816 are legal in a DNS label (e.g., the control characters). However, 817 this facility is powerful enough to express legal host names and 818 common utility labels (such as "_spf") that are used in DNS. 820 For several mechanisms, the domain-spec is optional. If it is not 821 provided, the from the check_host() arguments (see 822 Section 4.1) is used as the . Domain and domain-spec 823 are syntactically identical after macro expansion. Domain is an 824 input value for check_host() while domain-spec is computed by 825 check_host(). 827 Note: Historically, this document has made no provisions for how to 828 handle domain-specs, or macro-expansions thereof, that are 829 syntactically invalid per [RFC1035], such as names with empty labels 830 (e.g., "foo..example.com") or overlong labels (more than 63 831 characters). Some implementations choose to treat as a no-match 832 mechanisms, and ignore modifiers with such names, whereas others 833 return a "permerror" exception. The outcome for an unexpected 834 domain-spec without macros might even differ from that for an 835 unexpected after macro expansion. 837 5. Mechanism Definitions 839 This section defines two types of mechanisms. 841 Basic mechanisms contribute to the language framework. They do not 842 specify a particular type of authorization scheme. 844 all 845 include 847 Designated sender mechanisms are used to designate a set of 848 addresses as being permitted or not permitted to use the for 849 sending mail. 851 a 852 mx 853 ptr (do not use) 854 ip4 855 ip6 856 exists 858 The following conventions apply to all mechanisms that perform a 859 comparison between and an IP address at any point: 861 If no CIDR prefix length is given in the directive, then and the 862 IP address are compared for equality. (Here, CIDR is Classless 863 Inter-Domain Routing, described in [RFC4632].) 865 If a CIDR prefix length is specified, then only the specified number 866 of high-order bits of and the IP address are compared for 867 equality. 869 When any mechanism fetches host addresses to compare with , when 870 is an IPv4, "A" records are fetched; when is an IPv6 871 address, "AAAA" records are fetched. SPF implementations on IPv6 872 servers need to handle both "AAAA" and "A" secords, for clients on 873 IPv4 mapped IPv6 addresses [RFC4291]. IPv4 addresses are only 874 listed in an SPF record using the "ip4" mechanism. 876 Several mechanisms rely on information fetched from the DNS. For 877 these DNS queries, except where noted, if the DNS server returns an 878 error (RCODE other than 0 or 3) or the query times out, the mechanism 879 stops and the topmost check_host() returns "temperror". If the 880 server returns "domain does not exist" (RCODE 3), then evaluation of 881 the mechanism continues as if the server returned no error (RCODE 0) 882 and zero answer records. 884 5.1. "all" 886 all = "all" 888 The "all" mechanism is a test that always matches. It is used as the 889 rightmost mechanism in a record to provide an explicit default. 891 For example: 893 v=spf1 a mx -all 895 Mechanisms after "all" will never be tested. Mechanisms listed after 896 "all" MUST be ignored. Any "redirect" modifier (Section 6.1) MUST be 897 ignored when there is an "all" mechanism in the record. 899 5.2. "include" 901 include = "include" ":" domain-spec 903 The "include" mechanism triggers a recursive evaluation of 904 check_host(). 906 1. The domain-spec is expanded as per Section 7. 908 2. Check_host() is evaluated with the resulting string as the 909 . The and arguments remain the same as in 910 the current evaluation of check_host(). 912 3. The recursive evaluation returns either match, not match, or an 913 error. If it matches, then the appropriate result for the 914 include: mechanism is used (e.g. include or +include gives a 915 "pass" result and -include gives "fail). 917 4. If there is no match, the parent check_host() resumes processing 918 as per the table below, with the previous value of 919 restored. 921 In hindsight, the name "include" was poorly chosen. Only the 922 evaluated result of the referenced SPF record is used, rather than 923 acting as if the referenced SPF record was literally included in the 924 first. For example, evaluating a "-all" directive in the referenced 925 record does not terminate the overall processing and does not 926 necessarily result in an overall "fail". (Better names for this 927 mechanism would have been "if-match", "on-match", etc.) 929 The "include" mechanism makes it possible for one domain to designate 930 multiple administratively-independent domains. For example, a vanity 931 domain "example.net" might send mail using the servers of 932 administratively-independent domains example.com and example.org. 934 Example.net could say 936 IN TXT "v=spf1 include:example.com include:example.org -all" 938 This would direct check_host() to, in effect, check the records of 939 example.com and example.org for a "pass" result. Only if the host 940 were not permitted for either of those domains would the result be 941 "fail". 943 Whether this mechanism matches, does not match, or returns an 944 exception depends on the result of the recursive evaluation of 945 check_host(): 947 +---------------------------------+---------------------------------+ 948 | A recursive check_host() result | Causes the "include" mechanism | 949 | of: | to: | 950 +---------------------------------+---------------------------------+ 951 | pass | match | 952 | | | 953 | fail | not match | 954 | | | 955 | softfail | not match | 956 | | | 957 | neutral | not match | 958 | | | 959 | temperror | return temperror | 960 | | | 961 | permerror | return permerror | 962 | | | 963 | none | return permerror | 964 +---------------------------------+---------------------------------+ 966 The "include" mechanism is intended for crossing administrative 967 boundaries. For example, if example.com and example.org were managed 968 by the same entity, and if the permitted set of hosts for both 969 domains was 970 "mx:example.com", it would be possible for example.org to specify 971 "include:example.com", but it would be preferable to specify 972 "redirect=example.com" or even "mx:example.com". 974 With the "include" mechanism an administratively external set of 975 hosts can be authorized, but determination of sender policy is still 976 a function of the original domain's SPF record (as determined by the 977 "all" mechanism in that record). The redirect modifier is more 978 suitable for consolidating both authorizations and policy into a 979 common set to be shared within an ADMD. Redirect is much more like a 980 common code element to be shared among records in a single ADMD. It 981 is possible to control both authorized hosts and policy for an 982 arbitrary number of domains from a single record. 984 5.3. "a" 986 This mechanism matches if is one of the 's IP 987 addresses. 989 a = "a" [ ":" domain-spec ] [ dual-cidr-length ] 991 An address lookup is done on the . The is compared 992 to the returned address(es). If any address matches, the mechanism 993 matches. 995 5.4. "mx" 997 This mechanism matches if is one of the MX hosts for a domain 998 name. 1000 mx = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 1002 check_host() first performs an MX lookup on the . Then 1003 it performs an address lookup on each MX name returned. The is 1004 compared to each returned IP address. To prevent Denial of Service 1005 (DoS) attacks, more than 10 MX names MUST NOT be looked up during the 1006 evaluation of an "mx" mechanism. If there are more than 10 MX names 1007 then permerror is returned and the evaluation terminated (see 1008 Section 4.6.4). If any address matches, the mechanism matches. 1010 Note regarding implicit MXs: If the has no MX records, 1011 check_host() MUST NOT pretend the target is its single MX, and MUST 1012 NOT default to an A or AAAA lookup on the directly. 1013 This behavior diverges from the legacy "implicit MX" rule, (See 1014 [RFC5321], Section 5. If such behavior is desired, the publisher 1015 will have to specify an "a" directive). 1017 5.5. "ptr" (do not use) 1019 This mechanism tests whether the DNS reverse-mapping for exists 1020 and correctly points to a domain name within a particular domain. 1021 This mechanism SHOULD NOT be used. See below for discussion. 1023 ptr = "ptr" [ ":" domain-spec ] 1025 The 's name is looked up using this procedure: 1027 o Perform a DNS reverse-mapping for : Look up the corresponding 1028 PTR record in "in-addr.arpa." if the address is an IPv4 one and in 1029 "ip6.arpa." if it is an IPv6 address. 1031 o For each record returned, validate the domain name by looking up 1032 its IP addresses. To prevent DoS attacks, more than 10 PTR names 1033 MUST NOT be looked up during the evaluation of a "ptr" mechanism 1034 (see Section 4.6.4). 1036 o If is among the returned IP addresses, then that domain name 1037 is validated. 1039 Check all validated domain names to see if they either match the 1040 domain or are a subdomain of the domain. 1041 If any do, this mechanism matches. If no validated domain name can 1042 be found, or if none of the validated domain names match or are a 1043 subdomain of the , this mechanism fails to match. If a 1044 DNS error occurs while doing the PTR RR lookup, then this mechanism 1045 fails to match. If a DNS error occurs while doing an A RR lookup, 1046 then that domain name is skipped and the search continues. 1048 Pseudocode: 1050 sending-domain_names := ptr_lookup(sending-host_IP); 1051 if more than 10 sending-domain_names are found, use at most 10. 1052 for each name in (sending-domain_names) { 1053 IP_addresses := a_lookup(name); 1054 if the sending-domain_IP is one of the IP_addresses { 1055 validated-sending-domain_names += name; 1056 } 1057 } 1059 for each name in (validated-sending-domain_names) { 1060 if name ends in , return match. 1061 if name is , return match. 1062 } 1063 return no-match. 1065 This mechanism matches if the is either a subdomain of 1066 a validated domain name or if the and a validated 1067 domain name are the same. For example: "mail.example.com" is within 1068 the domain "example.com", but "mail.bad-example.com" is not. 1070 Note: This mechanism is slow, it is not as reliable as other 1071 mechanisms in cases of DNS errors, and it places a large burden on 1072 the .arpa name servers. If used, proper PTR records MUST be in place 1073 for the domain's hosts and the "ptr" mechanism SHOULD be one of the 1074 last mechanisms checked. After many years of SPF deployment 1075 experience it has been concluded it is unnecessary and more reliable 1076 alternatives used instead. It is, however, still in use and part of 1077 the SPF protocol, so compliant check_host() implementations MUST 1078 support it. 1080 5.6. "ip4" and "ip6" 1082 These mechanisms test whether is contained within a given IP 1083 network. 1085 ip4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 1086 ip6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 1088 ip4-cidr-length = "/" 1*DIGIT 1089 ip6-cidr-length = "/" 1*DIGIT 1090 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 1092 ip4-network = qnum "." qnum "." qnum "." qnum 1093 qnum = DIGIT ; 0-9 1094 / %x31-39 DIGIT ; 10-99 1095 / "1" 2DIGIT ; 100-199 1096 / "2" %x30-34 DIGIT ; 200-249 1097 / "25" %x30-35 ; 250-255 1098 ; as per conventional dotted quad notation. e.g., 192.0.2.0 1099 ip6-network = 1100 ; e.g., 2001:DB8::CD30 1102 The is compared to the given network. If CIDR prefix length 1103 high-order bits match, the mechanism matches. 1105 If ip4-cidr-length is omitted, it is taken to be "/32". If 1106 ip6-cidr-length is omitted, it is taken to be "/128". It is not 1107 permitted to omit parts of the IP address instead of using CIDR 1108 notations. That is, use 192.0.2.0/24 instead of 192.0.2. 1110 5.7. "exists" 1112 This mechanism is used to construct an arbitrary domain name that is 1113 used for a DNS A record query. It allows for complicated schemes 1114 involving arbitrary parts of the mail envelope to determine what is 1115 permitted. 1117 exists = "exists" ":" domain-spec 1119 The domain-spec is expanded as per Section 7. The resulting domain 1120 name is used for a DNS A RR lookup (even when the connection type is 1121 IPv6). If any A record is returned, this mechanism matches. 1123 Domains can use this mechanism to specify arbitrarily complex 1124 queries. For example, suppose example.com publishes the record: 1126 v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all 1128 The might expand to 1129 "1.2.0.192.someuser._spf.example.com". This makes fine-grained 1130 decisions possible at the level of the user and client IP address. 1132 6. Modifier Definitions 1134 Modifiers are name/value pairs that provide additional information. 1135 Modifiers always have an "=" separating the name and the value. 1137 The modifiers defined in this document ("redirect" and "exp") MAY 1138 appear anywhere in the record, but SHOULD appear at the end, after 1139 all mechanisms. Ordering of these two modifiers does not matter. 1140 These two modifiers MUST NOT appear in a record more than once each. 1141 If they do, then check_host() exits with a result of "permerror". 1143 Unrecognized modifiers MUST be ignored no matter where in a record, 1144 or how often. This allows implementations of this document to 1145 gracefully handle records with modifiers that are defined in other 1146 specifications. 1148 6.1. redirect: Redirected Query 1150 The redirect modifier is intended for consolidating both 1151 authorizations and policy into a common set to be shared within a 1152 single ADMD. Redirect is like a common code element to be shared 1153 among records in a single ADMD. It is possible to control both 1154 authorized hosts and policy for an arbitrary number of domains from a 1155 single record. 1157 redirect = "redirect" "=" domain-spec 1159 If all mechanisms fail to match, and a "redirect" modifier is 1160 present, then processing proceeds as follows: 1162 The domain-spec portion of the redirect section is expanded as per 1163 the macro rules in Section 7. Then check_host() is evaluated with 1164 the resulting string as the . The and 1165 arguments remain the same as in the current evaluation of 1166 check_host(). 1168 The result of this new evaluation of check_host() is then considered 1169 the result of the current evaluation with the exception that if no 1170 SPF record is found, or if the is malformed, the result 1171 is a "permerror" rather than "none". 1173 Note that the newly-queried domain can itself specify redirect 1174 processing. 1176 This facility is intended for use by organizations that wish to apply 1177 the same record to multiple domains. For example: 1179 la.example.com. TXT "v=spf1 redirect=_spf.example.com" 1180 ny.example.com. TXT "v=spf1 redirect=_spf.example.com" 1181 sf.example.com. TXT "v=spf1 redirect=_spf.example.com" 1182 _spf.example.com. TXT "v=spf1 mx:example.com -all" 1184 In this example, mail from any of the three domains is described by 1185 the same record. This can be an administrative advantage. 1187 Note: In general, the domain "A" cannot reliably use a redirect to 1188 another domain "B" not under the same administrative control. Since 1189 the stays the same, there is no guarantee that the record at 1190 domain "B" will correctly work for mailboxes in domain "A", 1191 especially if domain "B" uses mechanisms involving local-parts. An 1192 "include" directive is generally be more appropriate. 1194 For clarity, it is RECOMMENDED that any "redirect" modifier appear as 1195 the very last term in a record. 1197 6.2. exp: Explanation 1199 explanation = "exp" "=" domain-spec 1201 If check_host() results in a "fail" due to a mechanism match (such as 1202 "-all"), and the "exp" modifier is present, then the explanation 1203 string returned is computed as described below. If no "exp" modifier 1204 is present, then either a default explanation string or an empty 1205 explanation string MUST be returned. 1207 The domain-spec is macro expanded (see Section 7) and becomes the 1208 . The DNS TXT record for the is fetched. 1210 If there are any DNS processing errors (any RCODE other than 0), or 1211 if no records are returned, or if more than one record is returned, 1212 or if there are syntax errors in the explanation string, then proceed 1213 as if no exp modifier was given. 1215 The fetched TXT record's strings are concatenated with no spaces, and 1216 then treated as an explain-string, which is macro-expanded. This 1217 final result is the explanation string. Implementations MAY limit 1218 the length of the resulting explanation string to allow for other 1219 protocol constraints and/or reasonable processing limits. Since the 1220 explanation string is intended for an SMTP response and [RFC5321] 1221 Section 2.4 says that responses are in [US-ASCII], the explanation 1222 string MUST be limited to US-ASCII. 1224 Software evaluating check_host() can use this string to communicate 1225 information from the publishing domain in the form of a short message 1226 or URL. Software SHOULD make it clear that the explanation string 1227 comes from a third party. For example, it can prepend the macro 1228 string "%{o} explains: " to the explanation, such as shown in 1229 Section 2.6.4. 1231 Suppose example.com has this record: 1233 v=spf1 mx -all exp=explain._spf.%{d} 1235 Here are some examples of possible explanation TXT records at 1236 explain._spf.example.com: 1238 "Mail from example.com should only be sent by its own servers." 1239 -- a simple, constant message 1241 "%{i} is not one of %{d}'s designated mail servers." 1242 -- a message with a little more information, including the IP 1243 address that failed the check 1245 "See http://%{d}/why.html?s=%{S}&i=%{I}" 1246 -- a complicated example that constructs a URL with the 1247 arguments to check_host() so that a web page can be 1248 generated with detailed, custom instructions 1250 Note: During recursion into an "include" mechanism, an exp= modifier 1251 from the MUST NOT be used. In contrast, when executing 1252 a "redirect" modifier, an exp= modifier from the original domain MUST 1253 NOT be used. 1255 7. Macros 1257 When evaluating an SPF policy record, certain character sequences are 1258 intended to be replaced by parameters of the message or of the 1259 connection. These character sequences are referred to as "macros". 1261 7.1. Formal Specification 1263 The ABNF description for a macro is as follows: 1265 domain-spec = macro-string domain-end 1266 domain-end = ( "." toplabel [ "." ] ) / macro-expand 1268 toplabel = ( *alphanum ALPHA *alphanum ) / 1269 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 1270 alphanum = ALPHA / DIGIT 1272 explain-string = *( macro-string / SP ) 1274 macro-string = *( macro-expand / macro-literal ) 1275 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 1276 / "%%" / "%_" / "%-" 1277 macro-literal = %x21-24 / %x26-7E 1278 ; visible characters except "%" 1279 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 1280 "c" / "r" / "t" / "v" 1281 transformers = *DIGIT [ "r" ] 1282 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 1284 The "toplabel" construction is subject to the LDH rule plus 1285 additional top-level domain (TLD) restrictions. See Section 2 of 1286 [RFC3696] for background. 1288 Some special cases: 1290 o A literal "%" is expressed by "%%". 1292 o "%_" expands to a single " " space. 1294 o "%-" expands to a URL-encoded space, viz., "%20". 1296 7.2. Macro Definitions 1298 The following macro letters are expanded in term arguments: 1300 s = 1301 l = local-part of 1302 o = domain of 1303 d = 1304 i = 1305 p = the validated domain name of (do not use) 1306 v = the string "in-addr" if is ipv4, or "ip6" if is ipv6 1307 h = HELO/EHLO domain 1309 , , and are defined in Section 2.4. 1311 The following macro letters are allowed only in "exp" text: 1313 c = SMTP client IP (easily readable format) 1314 r = domain name of host performing the check 1315 t = current timestamp 1317 7.3. Notes 1319 A '%' character not followed by a '{', '%', '-', or '_' character is 1320 a syntax error. So: 1322 -exists:%(ir).sbl.spamhaus.example.org 1324 is incorrect and will cause check_host() to yield a "permerror". 1325 Instead, the following is legal: 1327 -exists:%{ir}.sbl.spamhaus.example.org 1329 Optional transformers are the following: 1331 *DIGIT = zero or more digits 1332 r = reverse value, splitting on dots by default 1334 If transformers or delimiters are provided, the replacement value for 1335 a macro letter is split into parts separated by one or more of the 1336 specified delimiter characters. After performing any reversal 1337 operation and/or removal of left-hand parts, the parts are rejoined 1338 using "." and not the original splitting characters. 1340 By default, strings are split on "." (dots). Note that no special 1341 treatment is given to leading, trailing, or consecutive delimiters in 1342 input strings, and so the list of parts might contain empty strings. 1343 Some older implementations of SPF prohibit trailing dots in domain 1344 names, so trailing dots SHOULD NOT be published by domain owners, 1345 although they MUST be accepted by implementations conforming to this 1346 document. Macros can specify delimiter characters that are used 1347 instead of ".". 1349 The "r" transformer indicates a reversal operation: if the client IP 1350 address were 192.0.2.1, the macro %{i} would expand to "192.0.2.1" 1351 and the macro %{ir} would expand to "1.2.0.192". 1353 The DIGIT transformer indicates the number of right-hand parts to 1354 use, after optional reversal. If a DIGIT is specified, the value 1355 MUST be nonzero. If no DIGITs are specified, or if the value 1356 specifies more parts than are available, all the available parts are 1357 used. If the DIGIT was 5, and only 3 parts were available, the macro 1358 interpreter would pretend the DIGIT was 3. Implementations MUST 1359 support at least a value of 128, as that is the maximum number of 1360 labels in a domain name. 1362 The "s" macro expands to the argument. It is an email 1363 address with a local-part, an "@" character, and a domain. The "l" 1364 macro expands to just the local-part. The "o" macro expands to just 1365 the domain part. Note that these values remain the same during 1366 recursive and chained evaluations due to "include" and/or "redirect". 1367 Note also that if the original had no local-part, the local- 1368 part was set to "postmaster" in initial processing (see Section 4.3). 1370 For IPv4 addresses, both the "i" and "c" macros expand to the 1371 standard dotted-quad format. 1373 For IPv6 addresses, the "i" macro expands to a dot-format address; it 1374 is intended for use in %{ir}. The "c" macro can expand to any of the 1375 hexadecimal colon-format addresses specified in [RFC4291], Section 1376 2.2. It is intended for humans to read. 1378 The "p" macro expands to the validated domain name of . The 1379 procedure for finding the validated domain name is defined in 1380 Section 5.5. If the is present in the list of validated 1381 domains, it SHOULD be used. Otherwise, if a subdomain of the 1382 is present, it SHOULD be used. Otherwise, any name from the 1383 list can be used. If there are no validated domain names or if a DNS 1384 error occurs, the string "unknown" is used. This macro SHOULD NOT be 1385 used. See Section 5.5 for the discussion about why not. 1387 The "h" macro expands to the parameter that was provided to the SMTP 1388 server via the HELO or EHLO SMTP verb. For sessions where that verb 1389 was provide more than once, the most recent instance is used. 1391 The "r" macro expands to the name of the receiving MTA. This SHOULD 1392 be a fully qualified domain name, but if one does not exist (as when 1393 the checking is done by a MUA) or if policy restrictions dictate 1394 otherwise, the word "unknown" SHOULD be substituted. The domain name 1395 can be different from the name found in the MX record that the client 1396 MTA used to locate the receiving MTA. 1398 The "t" macro expands to the decimal representation of the 1399 approximate number of seconds since the Epoch (Midnight, January 1, 1400 1970, UTC) at the time of the evaluation. This is the same value as 1401 is returned by the POSIX time() function in most standards-compliant 1402 libraries. 1404 When the result of macro expansion is used in a domain name query, if 1405 the expanded domain name exceeds 253 characters (the maximum length 1406 of a domain name), the left side is truncated to fit, by removing 1407 successive domain labels (and their following dots) until the total 1408 length does not exceed 253 characters. 1410 Uppercased macros expand exactly as their lowercased equivalents, and 1411 are then URL escaped. URL escaping MUST be performed for characters 1412 not in the "unreserved" set, which is defined in [RFC3986]. 1414 Note: Care has to be taken by the sending ADMD so that macro 1415 expansion for legitimate email does not exceed the 63-character limit 1416 on DNS labels. The local-part of email addresses, in particular, can 1417 have more than 63 characters between dots. 1419 Note: To minimize DNS lookup resource requirements, it is better if 1420 sending ADMDs avoid using the "s", "l", "o", or "h" macros in 1421 conjunction with any mechanism directive. Although these macros are 1422 powerful and allow per-user records to be published, they severely 1423 limit the ability of implementations to cache results of check_host() 1424 and they reduce the effectiveness of DNS caches. 1426 Note: If no directive processed during the evaluation of check_host() 1427 contains an "s", "l", "o", or "h" macro, then the results of the 1428 evaluation can be cached on the basis of and alone for 1429 as long as the shortest Time To Live (TTL) of all the DNS records 1430 involved. 1432 7.4. Expansion Examples 1434 The is strong-bad@email.example.com. 1435 The IPv4 SMTP client IP is 192.0.2.3. 1436 The IPv6 SMTP client IP is 2001:DB8::CB01. 1437 The PTR domain name of the client IP is mx.example.org. 1439 macro expansion 1440 ------- ---------------------------- 1441 %{s} strong-bad@email.example.com 1442 %{o} email.example.com 1443 %{d} email.example.com 1444 %{d4} email.example.com 1445 %{d3} email.example.com 1446 %{d2} example.com 1447 %{d1} com 1448 %{dr} com.example.email 1449 %{d2r} example.email 1450 %{l} strong-bad 1451 %{l-} strong.bad 1452 %{lr} strong-bad 1453 %{lr-} bad.strong 1454 %{l1r-} strong 1456 macro-string expansion 1457 -------------------------------------------------------------------- 1458 %{ir}.%{v}._spf.%{d2} 3.2.0.192.in-addr._spf.example.com 1459 %{lr-}.lp._spf.%{d2} bad.strong.lp._spf.example.com 1461 %{lr-}.lp.%{ir}.%{v}._spf.%{d2} 1462 bad.strong.lp.3.2.0.192.in-addr._spf.example.com 1464 %{ir}.%{v}.%{l1r-}.lp._spf.%{d2} 1465 3.2.0.192.in-addr.strong.lp._spf.example.com 1467 %{d2}.trusted-domains.example.net 1468 example.com.trusted-domains.example.net 1470 IPv6: 1471 %{ir}.%{v}._spf.%{d2} 1.0.B.C.0.0.0.0. 1472 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 1474 8. Result Handling 1476 This section provides guidance for operators in response to the 1477 various possible outputs of check_host() on a message. Terse 1478 definitions of SPF results are presented in Section 2.6; this section 1479 provides more detail on each for use in developing local policy for 1480 message handling. 1482 Every operating environment is different. There are some receivers 1483 for whom strict adherence to SPF is appropriate, and definitive 1484 treatment of messages that are evaluated to be explicity unauthorized 1485 ("fail" and sometimes "softfail") is the norm. There are others for 1486 which the "false negative" cases are more of a concern. This concern 1487 is typically handled by merely recording the result in the header and 1488 allowing the message to pass on for additional processing. There are 1489 still others where SPF is one of several inputs to the message 1490 handling decision. As such, there is no normative requirement for 1491 message handling in response to any particular result. This section 1492 is provided to present a complete picture of the likely cause of each 1493 result, and where available, the experience gained during 1494 experimental deployment. 1496 There are essentially two classes of handling choices: 1498 o Handling within the SMTP session that attempted to deliver the 1499 message, such as by returning a permanent SMTP error (rejection) 1500 or temporary SMTP error ("try again later"); 1502 o Permitting the message to pass (a successful SMTP reply code) and 1503 adding an additional header field that indicates the result 1504 returned by check_host() and other salient details; this is 1505 discussed in more detail in Section 9. 1507 8.1. None 1509 With a "none" result, the SPF verifier has no information at all 1510 about the authorization or lack thereof of the client to use the 1511 checked idenity or identities. The check_host() function completed 1512 without errors but was not able to reach any conclusion. 1514 8.2. Neutral 1516 A "neutral" result indicates that although a policy for the identity 1517 was discovered, there is no definite assertion about the (positive or 1518 negative) about the client. 1520 A "neutral" result MUST be treated exactly like the "none" result; 1521 the distinction exists only for informational purposes. Treating 1522 "neutral" more harshly than "none" would discourage domain owners 1523 from testing the use of SPF records (see Section 10.1). 1525 8.3. Pass 1527 A "pass" result means that the client is authorized to inject mail 1528 with the given identity. The domain can now, in the sense of 1529 reputation, be considered responsible for sending the message. 1530 Further policy checks can now proceed with confidence in the 1531 legitimate use of the identity. This is further discussed in 1532 Appendix G.1. 1534 8.4. Fail 1536 A "fail" result is an explicit statement that the client is not 1537 authorized to use the domain in the given identity. Disposition of 1538 SPF fail messages is a matter of local policy. See Appendix G.2 for 1539 considerations on developing local policy. 1541 If the checking software chooses to reject the mail during the SMTP 1542 transaction, then it SHOULD use an SMTP reply code of 550 (see 1543 [RFC5321]) and, if supported, the 5.7.1 enhanced status code (see 1544 [RFC3463]), in addition to an appropriate reply text. The 1545 check_host() function will return either a default explanation string 1546 or one from the domain that published the SPF records (see 1547 Section 6.2). If the information does not originate with the 1548 checking software, it is good to make it clear that the text is 1549 provided by the sender's domain. For example: 1551 550-5.7.1 SPF MAIL FROM check failed: 1552 550-5.7.1 The domain example.com explains: 1553 550 5.7.1 Please see http://www.example.com/mailpolicy.html 1555 If the checking software chooses not to reject the mail during the 1556 SMTP transaction, then it SHOULD add a Received-SPF or 1557 Authentication-Results header field (see Section 9) to communicate 1558 this result to downstream message processors. While this is true for 1559 all SPF results, it is of particular importance for "fail" results 1560 since the message is explicitly not authorized by the domain owner. 1562 8.5. Softfail 1564 A "softfail" result ought to be treated as somewhere between "fail" 1565 and "neutral"/"none". The domain owner believes the host is not 1566 authorized but is not willing to make a strong policy statement. 1567 Receiving software SHOULD NOT reject the message based solely on this 1568 result, but MAY subject the message to closer scrutiny than normal. 1570 The domain owner wants to discourage the use of this host and thus 1571 desires limited feedback when a "softfail" result occurs. For 1572 example, the recipient's Mail User Agent (MUA) could highlight the 1573 "softfail" status, or the receiving MTA could give the sender a 1574 message using greylisting, [RFC6647], with a note the first time the 1575 message is received, but accept it on a later attempt based on 1576 receiver policy. 1578 8.6. Temperror 1580 A "temperror" result means the SPF verifier encountered a transient 1581 (generally DNS) error while performing the check. Checking software 1582 can choose to accept or temporarily reject the message. If the 1583 message is rejected during the SMTP transaction for this reason, the 1584 software SHOULD use an SMTP reply code of 451 and, if supported, the 1585 4.4.3 enhanced status code. These errors can be caused by problems 1586 in either the sender's or receiver's DNS software. 1588 8.7. Permerror 1590 A "permerror" result means the domain's published records could not 1591 be correctly interpreted. This signals an error condition that 1592 definitely requires manual intervention to be resolved. If the 1593 message is rejected during the SMTP transaction for this reason, the 1594 software SHOULD use an SMTP reply code of 550 and, if supported, the 1595 5.5.2 enhanced status code. Be aware that if the domain owner uses 1596 macros (Section 7), it is possible that this result is due to the 1597 checked identities having an unexpected format. It is also possible 1598 that this result is generated by certain SPF clients due to the input 1599 arguments having an unexpected format; see Section 4.8. 1601 9. Recording The Result 1603 To provide downstream agents, such as MUAs, with the information they 1604 might need in terms of evaluating or representing the apparent safety 1605 of the message content, it is RECOMMENDED that SMTP receivers record 1606 the result of SPF processing in the message header. For operators 1607 that choose to record SPF results in the header of the message for 1608 processing by internal filters or MUAs, two methods are presented. 1609 Section 9.1 defines the Received-SPF field, which is the results 1610 field originally defined for SPF use. Section 9.2 discusses 1611 Authentication-Results [RFC5451] which was specified more recently 1612 and is designed for use by SPF and other authentication methods. 1614 Both are in common use, and hence both are included here. However, 1615 it is important to note that they were designed to serve slightly 1616 different purposes. Received-SPF is intended to include enough 1617 forensic information to enable reconstruction of the SPF evaluation 1618 of the message, while Authentication-Results is designed only to 1619 relay the result itself and related output details of likely use to 1620 end users (e.g., what property of the message was actually 1621 authenticated and what it contained), leaving forensic work to the 1622 purview of system logs and the Received field contents. Also, 1623 Received-SPF relies on compliance of agents within the receiving ADMD 1624 to adhere to the header field ordering rules of [RFC5321] and 1625 [RFC5322], while Authentication-Results includes some provisions to 1626 protect against non-compliant implementations. 1628 An operator could choose to use both to serve different downstream 1629 agents. In such cases, care needs to be taken to ensure both fields 1630 are conveying the same details, or unexpected results can occur. 1632 9.1. The Received-SPF Header Field 1634 The Received-SPF header field is a trace field (see [RFC5322] Section 1635 3.6.7) and SHOULD be prepended to the existing header, above the 1636 Received: field that is generated by the SMTP receiver. It MUST 1637 appear above all other Received-SPF fields in the message. The 1638 header field has the following format: 1640 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 1641 [ key-value-list ] CRLF 1643 result = "pass" / "fail" / "softfail" / "neutral" / 1644 "none" / "temperror" / "permerror" 1646 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 1647 [";"] 1649 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 1651 key = "client-ip" / "envelope-from" / "helo" / 1652 "problem" / "receiver" / "identity" / 1653 "mechanism" / name 1655 identity = "mailfrom" ; for the "MAIL FROM" identity 1656 / "helo" ; for the "HELO" identity 1657 / name ; other identities 1659 dot-atom = 1660 quoted-string = 1661 comment = 1662 CFWS = 1663 FWS = 1664 CRLF = 1666 The header field SHOULD include a "(...)" style comment after the 1667 result, conveying supporting information for the result, such as 1668 , , and . 1670 The following key-value pairs are designed for later machine parsing. 1671 SPF verifiers SHOULD give enough information so that the SPF results 1672 can be verified. That is, at least "client-ip", "helo", and, if the 1673 "MAIL FROM" identity was checked, "envelope-from". 1675 client-ip the IP address of the SMTP client 1677 envelope-from the envelope sender mailbox 1679 helo the host name given in the HELO or EHLO command 1681 mechanism the mechanism that matched (if no mechanisms matched, 1682 substitute the word "default") 1684 problem if an error was returned, details about the error 1685 receiver the host name of the SPF verifier 1687 identity the identity that was checked; see the ABNF 1688 rule 1690 Other keys MAY be defined by SPF verifiers. 1692 SPF verifiers MUST make sure that the Received-SPF header field does 1693 not contain invalid characters, is not excessively long (See 1694 [RFC5322] Section 2.1.1), and does not contain malicious data that 1695 has been provided by the sender. 1697 Examples of various header field styles that could be generated are 1698 the following: 1700 Received-SPF: pass (mybox.example.org: domain of 1701 myname@example.com designates 192.0.2.1 as permitted sender) 1702 receiver=mybox.example.org; client-ip=192.0.2.1; 1703 envelope-from="myname@example.com"; helo=foo.example.com; 1705 Received-SPF: fail (mybox.example.org: domain of 1706 myname@example.com does not designate 1707 192.0.2.1 as permitted sender) 1708 identity=mailfrom; client-ip=192.0.2.1; 1709 envelope-from="myname@example.com"; 1711 Received-SPF: pass (mybox.example.org: domain of 1712 myname@example.com designates 192.0.2.1 as permitted sender) 1713 receiver=mybox.example.org; client-ip=192.0.2.1; 1714 mechanism=ip4:192.0.2.1; envelope-from="myname@example.com"; 1715 helo=foo.example.com; 1717 9.2. SPF Results in the Authentication-Results Header Field 1719 As mentioned in Section 9, the Authentication-Results header field is 1720 designed to communicate lists of tests a border MTA did and their 1721 results. The specified elements of the field provide less 1722 information than the Received-SPF field: 1724 Authentication-Results: myhost.example.org; spf=pass 1725 smtp.mailfrom=example.net 1727 Received-SPF: pass (myhost.example.org: domain of 1728 myname@example.com designates 192.0.2.1 as permitted sender) 1729 receiver=mybox.example.org; client-ip=192.0.2.1; 1730 envelope-from="myname@example.com"; helo=foo.example.com; 1732 It is, however, possible to add CFWS in the "reason" part of an 1733 Authentication-Results header field and provide the equivalent 1734 information, if desired. 1736 As an example, an expanded Authentication-Results header field might 1737 look like (for a "MAIL FROM" check in this example): 1739 Authentication-Results: myhost.example.org; spf=pass 1740 reason="client-ip=192.0.2.1; smtp.helo=foo.example.com" 1741 smtp.mailfrom=user@example.net 1743 10. Effects on Infrastructure 1745 This section outlines the major implications that adoption of this 1746 document will have on various entities involved in Internet email. 1747 It is intended to make clear to the reader where this document 1748 knowingly affects the operation of such entities. This section is 1749 not a "how-to" manual, or a "best practices" document, and it is not 1750 a comprehensive list of what such entities SHOULD do in light of this 1751 document. 1753 This section provides operational advice and instruction only. It is 1754 non-normative. 1756 [RFC5598] describes the Internet email architecture. This section is 1757 organized based on the different segments of the architecture. 1759 10.1. Sending Domains 1761 Originating ADMDs (ADministrative Management Domains - [RFC5598] 1762 Section 2.2.1 and Section 2.3) that wish to be compliant with this 1763 specification will need to determine the list of relays ([RFC5598] 1764 Section 2.2.2) that they allow to use their domain name in the "HELO" 1765 and "MAIL FROM" identities when relaying to other ADMDs. It is 1766 recognized that forming such a list is not just a simple technical 1767 exercise, but involves policy decisions with both technical and 1768 administrative considerations. 1770 10.1.1. DNS Resource Considerations 1772 Minimizing the DNS resources required for SPF lookups can be done by 1773 choosing directives that require less DNS information and by placing 1774 lower-cost mechanisms earlier in the SPF record. 1776 +----------+--------+-----------------+ 1777 | term | cost | limit | 1778 +----------+--------+-----------------+ 1779 | ip4/ip6 | 0 | - | 1780 | a | 1 | 10 | 1781 | include | 1 | 10 | 1782 | redirect | 1 | 10 | 1783 | exists | 1 | 10 | 1784 | mx | 1 + N* | 10 and N* <= 10 | 1785 | ptr/%{p} | 1 + N* | 10 and N* <= 10 | 1786 | all | 0 | - | 1787 +----------+--------+-----------------+ 1788 * N is the number of RRs found during each term evaluation 1790 Section 4.6.4 specifies the limits receivers have to use. It is 1791 essential to publish records that do not exceed these requirements. 1792 It is also required to carefully weight the cost and the 1793 maintainability of licit solutions. 1795 For example, consider a domain set up as follows: 1797 example.com. IN MX 10 mx.example.com. 1798 IN MX 20 mx2.example.com. 1799 mx.example.com. IN A 192.0.2.1 1800 mx2.example.com. IN A 192.0.2.129 1802 Assume the administrative point is to authorize (pass) mx and mx2 1803 while failing every other host. Compare the following solutions: 1805 Best record: 1806 example.com. IN TXT "v=spf1 ip4:192.0.2.1 ip4:192.0.2.129 -all" 1808 Good record: 1809 $ORIGIN example.com. 1810 @ IN TXT "v=spf1 a:authorized-spf.example.com -all" 1811 authorized-spf IN A 192.0.2.1 1812 IN A 192.0.2.129 1814 Expensive record: 1815 example.com. IN TXT "v=spf1 mx:example.com -all" 1817 Wasteful, bad record: 1818 example.com. IN TXT "v=spf1 ip4:192.0.2.0/24 mx -all" 1820 10.1.2. Administrator's Considerations 1822 There might be administrative considerations: using "a" over "ip4" or 1823 "ip6" allows hosts to be renumbered easily. Using "mx" over "a" 1824 allows the set of mail hosts to be changed easily. Unless such 1825 changes are common, it is better to use the less resource intensive 1826 mechanisms like "ip4" and "ip6" over "a" or "a" or "mx". 1828 In some specific cases, standard advice on record content is 1829 appropriate. Publishing SPF records for domains that send no mail is 1830 a well established best practice. The record for a domain that sends 1831 no mail is: 1833 www.example.com. IN TXT "v=spf1 -all" 1835 Publishing SPF records for individual hosts is also best practice. 1837 The hostname is generally the identity used in the 5321.HELO/.EHLO 1838 command. In the case of messages with a null 5321.MailFrom, this is 1839 used as the domain for 5321.MailFrom SPF checks, in addition to being 1840 used in 5321.HELO/.EHLO based SPF checks. The standard SPF record 1841 for an individual host that is involved in mail processing is: 1843 relay.example.com. IN TXT "v=spf1 a -all" 1845 Validating correct deployment is difficult. [RFC6652] describes one 1846 mechanism for soliciting feedback on SPF failures. Another 1847 suggestion can be found in Appendix C. 1849 Regardless of the method used, understanding the ADMD's outbound mail 1850 architecture is essential to effective deployment. 1852 10.1.3. Bounces 1854 As explained in Section 1.1.3, [RFC5321] allows the reverse-path to 1855 be null, which is typical of some Delivery Status Notification 1856 [RFC3464], commonly called email bounces. In this case the only 1857 entity available for performing an SPF check is the "HELO" identity 1858 defined in Section 1.1.4. SPF functionality is enhanced by 1859 administrators ensuring this identity is set correctly and has an 1860 appropriate SPF record. It is normal to have the HELO identity set 1861 to hostname instead of domain. Zone file generation for significant 1862 numbers of hosts can be consolidated using the redirect modifier and 1863 scripted for initial deployment. Specific deployment advice is given 1864 above in Section 10.1.2. 1866 10.2. Receivers 1868 SPF results can be used in combination with other methods to 1869 determine the final local disposition (either positive or negative of 1870 a message. It can also be considered dispositive on its own. 1872 An attempt to have one organization (sender) direct the email 1873 handling policies of another (receiver) is inherently challenging and 1874 often controversial. As stated elsewhere in this document, there is 1875 no normative requirement for specific handling of a message based on 1876 any SPF result. The information presented in Section 8 and in 1877 Appendix G is offered for receiver consideration when forming local 1878 handling policies. 1880 The primary considerations are that SPF might return "pass" for mail 1881 that is ultimately harmful (e.g., spammers that arrange for SPF to 1882 pass using nonsense domain names, or virus or spam outbreaks from 1883 within trusted sources), and might also return "fail" for mail that 1884 is ultimately legitimate (e.g., legitimate mail that has traversed a 1885 mail alias). It is important take both of these cases under 1886 consideration when establishing local handling policy. 1888 10.3. Mediators 1890 Mediators are a type of User actor.[RFC5598]. That is, a mediator 1891 takes 'delivery' of a message and posts a 'submission' of a new 1892 message. The mediator can make the newly-posted message be as 1893 similar or as different from the original message as they wish. 1894 Examples include mailing lists (see [RFC5598] Section 5.3) and 1895 ReSenders ([RFC5598] Section 5.2). This is discussed in [RFC5321], 1896 Section 3.9. For the operation of SPF, the essential concern is the 1897 email address in the 5321.MailFrom command for the new message. 1899 Because SPF evaluation is based on the IP Address of the "last" 1900 sending SMTP server, the address of the mediator will be used, rather 1901 than the address of the SMTP server that sent the message to the 1902 mediator. Some mediators retain the email address from the original 1903 message, while some use a new address. 1905 If the address is the same as for the original message, and the 1906 original message had an associated SPF record, then the SPF 1907 evaluation will fail unless mitigations such as those described in 1908 Appendix D are used. 1910 11. Security Considerations 1912 11.1. Processing Limits 1914 As with most aspects of email, there are a number of ways that 1915 malicious parties could use the protocol as an avenue for a 1916 Denial-of-Service (DoS) attack. The processing limits outlined in 1917 Section 4.6.4 are designed to prevent attacks such as the following: 1919 o A malicious party could create an SPF record with many references 1920 to a victim's domain and send many emails to different SPF 1921 verifiers; those SPF verifiers would then create a DoS attack. In 1922 effect, the SPF verifiers are being used to amplify the attacker's 1923 bandwidth by using fewer bytes in the SMTP session than are used 1924 by the DNS queries. Using SPF clients also allows the attacker to 1925 hide the true source of the attack. 1927 o Whereas implementations of check_host() are supposed to limit the 1928 number of DNS lookups, malicious domains could publish records 1929 that exceed these limits in an attempt to waste computation effort 1930 at their targets when they send them mail. Malicious domains 1931 could also design SPF records that cause particular 1932 implementations to use excessive memory or CPU usage, or to 1933 trigger bugs. 1935 o Malicious parties could send a large volume of mail purporting to 1936 come from the intended target to a wide variety of legitimate mail 1937 hosts. These legitimate machines would then present a DNS load on 1938 the target as they fetched the relevant records. 1940 o Malicious parties could, in theory, use SPF records as a vehicle 1941 for DNS lookup amplification for a denial-of-service-attack. In 1942 this scenario, the attacker publishes an SPF record in its own DNS 1943 that uses "a" and "mx" mechanisms directed toward the intended 1944 victim, e.g. "a:example.com a:foo.example.com a:bar.example.com 1945 ..." and then distributes mail with a MAIL FROM value including 1946 its own domain in large volume to a wide variety of destinations. 1947 Any such destination operating an SPF verifier will begin querying 1948 all of the names associated with the "a" mechanisms in that 1949 record. The names used in the record needn't exist for the attack 1950 to be effective. Operational experience since publication of 1951 [RFC4408] suggests that mitigation of this class of attack can be 1952 accomplished with minimal impact on the deployed base by having 1953 the verifier abort processing and return "permerror" 1954 (Section 2.6.7) once two lookups of non-existent domains have been 1955 encountered. 1957 Of these, the case of a third party referenced in the SPF record is 1958 the easiest for a DoS attack to effectively exploit. As a result, 1959 limits that might seem reasonable for an individual mail server can 1960 still allow an unreasonable amount of bandwidth amplification. 1961 Therefore, the processing limits need to be quite low. 1963 11.2. SPF-Authorized Email May Contain Other False Identities 1965 Do not construe the "MAIL FROM" and "HELO" identity authorizations to 1966 provide more assurance than they do. It is entirely possible for a 1967 malicious sender to inject a message using his own domain in the 1968 identities used by SPF, to have that domain's SPF record authorize 1969 the sending host, and yet the message can easily list other 1970 identities in its header. Unless the user or the MUA takes care to 1971 note that the authorized identity does not match the other more 1972 commonly-presented identities (such as the From: header field), the 1973 user might be lulled into a false sense of security. 1975 11.3. Spoofed DNS and IP Data 1977 There are two aspects of this protocol that malicious parties could 1978 exploit to undermine the validity of the check_host() function: 1980 o The evaluation of check_host() relies heavily on DNS. A malicious 1981 attacker could attack the DNS infrastructure and cause 1982 check_host() to see spoofed DNS data, and then return incorrect 1983 results. This could include returning "pass" for an value 1984 where the actual domain's record would evaluate to "fail". See 1985 [RFC3833] for a description of DNS weaknesses. 1987 o The client IP address, , is assumed to be correct. In a 1988 modern, correctly configured system the risk of this not being 1989 true is nil. 1991 11.4. Cross-User Forgery 1993 By definition, SPF policies just map domain names to sets of 1994 authorized MTAs, not whole email addresses to sets of authorized 1995 users. Although the "l" macro (Section 7) provides a limited way to 1996 define individual sets of authorized MTAs for specific email 1997 addresses, it is generally impossible to verify, through SPF, the use 1998 of specific email addresses by individual users of the same MTA. 2000 It is up to mail services and their MTAs to directly prevent 2001 cross-user forgery: based on SMTP AUTH ([RFC4954]), users have to be 2002 restricted to using only those email addresses that are actually 2003 under their control (see [RFC6409], Section 6.1). Another means to 2004 verify the identity of individual users is message cryptography such 2005 as PGP ([RFC4880]) or S/MIME ([RFC5751]). 2007 11.5. Untrusted Information Sources 2009 An SPF compliant receiver gathers information from the SMTP commands 2010 it receives and from the published DNS records of the sending domain 2011 holder, (e.g., "HELO" domain name, the "MAIL FROM" address from the 2012 envelope, and SPF DNS records published by the domain holder). 2014 11.5.1. Recorded Results 2016 This information, passed to the receiver in the Received-SPF: or 2017 Authentication-Results: trace fields, may be returned to the client 2018 MTA as an SMTP rejection message. If such an SMTP rejection message 2019 is generated, the information from the trace fields has to be checked 2020 for such problems as invalid characters and excessively long lines. 2022 11.5.2. External Explanations 2024 When the authorization check fails, an explanation string could be 2025 included in the reject response. Both the sender and the rejecting 2026 receiver need to be aware that the explanation was determined by the 2027 publisher of the SPF record checked and, in general, not the 2028 receiver. The explanation can contain malicious URLs, or it might be 2029 offensive or misleading. 2031 Explanations returned to sender domains due to "exp" modifiers, 2032 (Section 6.2), were generated by the sender policy published by the 2033 domain holders themselves. As long as messages are only returned 2034 with non-delivery notification ([RFC3464]) to domains publishing the 2035 explanation strings from their own DNS SPF records, the only affected 2036 parties are the original publishers of the domain's SPF records. 2038 In practice, such non-delivery notifications can be misdirected, such 2039 as when an MTA accepts an email and only later generates the 2040 notification to a forged address, or when an email forwarder does not 2041 direct the bounce back to the original sender. 2043 11.5.3. Macro Expansion 2045 Macros (Section 7) allow senders to inject arbitrary text (any non- 2046 null [US-ASCII] character) into receiver DNS queries. It is necesary 2047 to be prepared for hostile or unexpected content. 2049 11.6. Privacy Exposure 2051 Checking SPF records causes DNS queries to be sent to the domain 2052 owner. These DNS queries, especially if they are caused by the 2053 "exists" mechanism, can contain information about who is sending 2054 email and likely to which MTA the email is being sent. This can 2055 introduce some privacy concerns, which are more or less of an issue 2056 depending on local laws and the relationship between the domain owner 2057 and the person sending the email. 2059 11.7. Delivering Mail Producing a 'Fail' Result 2061 Operators that choose to deliver mail for which SPF produces a "fail" 2062 result need to understand that they are admitting content that is 2063 explicitly not authorized by the purported sender. While there are 2064 known failure modes that can be considered "false negatives", the 2065 distinct choice to admit those messages increases end-user exposure 2066 to likely harm. This is especially true for domains belonging to 2067 known good actors that are typically well-behaved; unauthorized mail 2068 from those sources might well be subjected to much higher skepticism 2069 and content analysis. 2071 SPF does not, however, include the capacity for identifying good 2072 actors from bad ones, nor does it handle the concept of known actors 2073 versus unknown ones. Those notions are out of scope for this 2074 specification. 2076 12. Contributors and Acknowledgements 2078 This document is largely based on the work of Meng Weng Wong, Mark 2079 Lentczner, and Wayne Schlitt. Although, as this section 2080 acknowledges, many people have contributed to this document, a very 2081 large portion of the writing and editing are due to Meng, Mark, and 2082 Wayne. 2084 This design owes a debt of parentage to [RMX] by Hadmut Danisch and 2085 to [DMP] by Gordon Fecyk. The idea of using a DNS record to check 2086 the legitimacy of an email address traces its ancestry further back 2087 through messages on the namedroppers mailing list by Paul Vixie 2088 [Vixie] (based on suggestion by Jim Miller) and by David Green 2089 [Green]. 2091 Philip Gladstone contributed the concept of macros to the 2092 specification, multiplying the expressiveness of the language and 2093 making per-user and per-IP lookups possible. 2095 The authors of both this document and [RFC4408] would also like to 2096 thank the literally hundreds of individuals who have participated in 2097 the development of this design. They are far too numerous to name, 2098 but they include the following: 2100 The participants in the SPFbis working group. 2101 The folks on the spf-discuss mailing list. 2102 The folks on the SPAM-L mailing list. 2103 The folks on the IRTF ASRG mailing list. 2104 The folks on the IETF MARID mailing list. 2105 The folks on #perl. 2107 13. IANA Considerations 2109 13.1. The SPF DNS Record Type 2111 Per [RFC4408], the IANA assigned the Resource Record Type and Qtype 2112 from the DNS Parameters Registry for the SPF RR type with code 99. 2113 The format of this type is identical to the TXT RR [RFC1035]. The 2114 character content of the record is encoded as [US-ASCII]. Use of 2115 this record type is obsolete for SPF Version 1. 2117 IANA is requested to add an annotation to the SPF RRTYPE saying 2118 "(OBSOLETE - use TXT)" in the DNS Parameters registry. 2120 [NOTE TO RFC EDITOR: (to be changed to " ... has added ..." upon 2121 publication)] 2123 13.2. The Received-SPF Mail Header Field 2125 Per [RFC3864], the "Received-SPF:" header field is added to the IANA 2126 Permanent Message Header Field Registry. The following is the 2127 registration template: 2129 Header field name: Received-SPF 2130 Applicable protocol: mail ([RFC5322]) 2131 Status: Standards Track 2132 Author/Change controller: IETF 2133 Specification document(s): RFC XXXX 2134 [NOTE TO RFC EDITOR: (this document)] 2136 13.3. SPF Modifier Registration 2138 [RFC6652] created a new SPF Modifier Registration. IANA is requested 2139 to change the reference for the exp and redirect modifiers from 2140 [RFC4408] to this document. Their status should not be changed. 2142 14. References 2144 14.1. Normative References 2146 [RFC1035] Mockapetris, P., "Domain names - implementation and 2147 specification", STD 13, RFC 1035, November 1987. 2149 [RFC1123] Braden, R., "Requirements for Internet Hosts - Application 2150 and Support", STD 3, RFC 1123, October 1989. 2152 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2153 Requirement Levels", BCP 14, RFC 2119, March 1997. 2155 [RFC3463] Vaudreuil, G., "Enhanced Mail System Status Codes", 2156 RFC 3463, January 2003. 2158 [RFC3864] Klyne, G., Nottingham, M., and J. Mogul, "Registration 2159 Procedures for Message Header Fields", BCP 90, RFC 3864, 2160 September 2004. 2162 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 2163 Resource Identifier (URI): Generic Syntax", STD 66, 2164 RFC 3986, January 2005. 2166 [RFC4291] Hinden, R. and S. Deering, "IP Version 6 Addressing 2167 Architecture", RFC 4291, February 2006. 2169 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 2170 Specifications: ABNF", STD 68, RFC 5234, January 2008. 2172 [RFC5321] Klensin, J., "Simple Mail Transfer Protocol", RFC 5321, 2173 October 2008. 2175 [RFC5322] Resnick, P., Ed., "Internet Message Format", RFC 5322, 2176 October 2008. 2178 [RFC5451] Kucherawy, M., "Message Header Field for Indicating 2179 Message Authentication Status", RFC 5451, April 2009. 2181 [RFC5598] Crocker, D., "Internet Mail Architecture", RFC 5598, 2182 July 2009. 2184 [RFC5890] Klensin, J., "Internationalized Domain Names for 2185 Applications (IDNA): Definitions and Document Framework", 2186 RFC 5890, August 2010. 2188 [US-ASCII] 2189 American National Standards Institute (formerly United 2190 States of America Standards Institute), "USA Code for 2191 Information Interchange, X3.4", 1968. 2193 ANSI X3.4-1968 has been replaced by newer versions with 2194 slight modifications, but the 1968 version remains 2195 definitive for the Internet. 2197 14.2. Informative References 2199 [DMP] Fecyk, G., "Designated Mailers Protocol". 2201 Work In Progress 2203 [Green] Green, D., "Domain-Authorized SMTP Mail", 2002. 2205 [RFC1034] Mockapetris, P., "Domain names - concepts and facilities", 2206 STD 13, RFC 1034, November 1987. 2208 [RFC1983] Malkin, G., "Internet Users' Glossary", RFC 1983, 2209 August 1996. 2211 [RFC2308] Andrews, M., "Negative Caching of DNS Queries (DNS 2212 NCACHE)", RFC 2308, March 1998. 2214 [RFC2782] Gulbrandsen, A., Vixie, P., and L. Esibov, "A DNS RR for 2215 specifying the location of services (DNS SRV)", RFC 2782, 2216 February 2000. 2218 [RFC3464] Moore, K. and G. Vaudreuil, "An Extensible Message Format 2219 for Delivery Status Notifications", RFC 3464, 2220 January 2003. 2222 [RFC3696] Klensin, J., "Application Techniques for Checking and 2223 Transformation of Names", RFC 3696, February 2004. 2225 [RFC3833] Atkins, D. and R. Austein, "Threat Analysis of the Domain 2226 Name System (DNS)", RFC 3833, August 2004. 2228 [RFC3834] Moore, K., "Recommendations for Automatic Responses to 2229 Electronic Mail", RFC 3834, August 2004. 2231 [RFC4408] Wong, M. and W. Schlitt, "Sender Policy Framework (SPF) 2232 for Authorizing Use of Domains in E-Mail, Version 1", 2233 RFC 4408, April 2006. 2235 [RFC4632] Fuller, V. and T. Li, "Classless Inter-domain Routing 2236 (CIDR): The Internet Address Assignment and Aggregation 2237 Plan", BCP 122, RFC 4632, August 2006. 2239 [RFC4880] Callas, J., Donnerhacke, L., Finney, H., Shaw, D., and R. 2240 Thayer, "OpenPGP Message Format", RFC 4880, November 2007. 2242 [RFC4954] Siemborski, R. and A. Melnikov, "SMTP Service Extension 2243 for Authentication", RFC 4954, July 2007. 2245 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2246 Mail Extensions (S/MIME) Version 3.2 Message 2247 Specification", RFC 5751, January 2010. 2249 [RFC6409] Gellens, R. and J. Klensin, "Message Submission for Mail", 2250 STD 72, RFC 6409, November 2011. 2252 [RFC6647] Kucherawy, M. and D. Crocker, "Email Greylisting: An 2253 Applicability Statement for SMTP", RFC 6647, June 2012. 2255 [RFC6652] Kitterman, S., "Sender Policy Framework (SPF) 2256 Authentication Failure Reporting Using the Abuse Reporting 2257 Format", RFC 6652, June 2012. 2259 [RFC6686] Kucherawy, M., "Resolution of the Sender Policy Framework 2260 (SPF) and Sender ID Experiments", RFC 6686, July 2012. 2262 [RMX] Danisch, H., "The RMX DNS RR Type for light weight sender 2263 authentication". 2265 Work In Progress 2267 [Vixie] Vixie, P., "Repudiating MAIL FROM", 2002. 2269 Appendix A. Collected ABNF 2271 This section is normative and any discrepancies with the ABNF 2272 fragments in the preceding text are to be resolved in favor of this 2273 grammar. 2275 See [RFC5234] for ABNF notation. Please note that as per this ABNF 2276 definition, literal text strings (those in quotes) are case- 2277 insensitive. Hence, "mx" matches "mx", "MX", "mX", and "Mx". 2279 record = version terms *SP 2280 version = "v=spf1" 2282 terms = *( 1*SP ( directive / modifier ) ) 2284 directive = [ qualifier ] mechanism 2285 qualifier = "+" / "-" / "?" / "~" 2286 mechanism = ( all / include 2287 / A / MX / PTR / IP4 / IP6 / exists ) 2289 all = "all" 2290 include = "include" ":" domain-spec 2291 A = "a" [ ":" domain-spec ] [ dual-cidr-length ] 2292 MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 2293 PTR = "ptr" [ ":" domain-spec ] 2294 IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 2295 IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 2296 exists = "exists" ":" domain-spec 2298 modifier = redirect / explanation / unknown-modifier 2299 redirect = "redirect" "=" domain-spec 2300 explanation = "exp" "=" domain-spec 2301 unknown-modifier = name "=" macro-string 2302 ; where name is not any known modifier 2304 ip4-cidr-length = "/" 1*DIGIT 2305 ip6-cidr-length = "/" 1*DIGIT 2306 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 2308 ip4-network = qnum "." qnum "." qnum "." qnum 2309 qnum = DIGIT ; 0-9 2310 / %x31-39 DIGIT ; 10-99 2311 / "1" 2DIGIT ; 100-199 2312 / "2" %x30-34 DIGIT ; 200-249 2313 / "25" %x30-35 ; 250-255 2314 ; conventional dotted quad notation. e.g., 192.0.2.0 2315 ip6-network = 2316 ; e.g., 2001:DB8::CD30 2318 domain-spec = macro-string domain-end 2319 domain-end = ( "." toplabel [ "." ] ) / macro-expand 2321 toplabel = ( *alphanum ALPHA *alphanum ) / 2322 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 2323 ; LDH rule plus additional TLD restrictions 2324 ; (see [RFC3696], Section 2 for background) 2325 alphanum = ALPHA / DIGIT 2327 explain-string = *( macro-string / SP ) 2329 macro-string = *( macro-expand / macro-literal ) 2330 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 2331 / "%%" / "%_" / "%-" 2332 macro-literal = %x21-24 / %x26-7E 2333 ; visible characters except "%" 2334 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 2335 "c" / "r" / "t" / "v" 2336 transformers = *DIGIT [ "r" ] 2337 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 2339 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 2341 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 2342 [ key-value-list ] CRLF 2344 result = "pass" / "fail" / "softfail" / "neutral" / 2345 "none" / "temperror" / "permerror" 2347 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 2348 [";"] 2350 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 2352 key = "client-ip" / "envelope-from" / "helo" / 2353 "problem" / "receiver" / "identity" / 2354 "mechanism" / name 2356 identity = "mailfrom" ; for the "MAIL FROM" identity 2357 / "helo" ; for the "HELO" identity 2358 / name ; other identities 2360 ALPHA = 2361 DIGIT = <0-9 as per [RFC5234]> 2362 SP = 2363 domain = 2364 dot-atom = 2365 quoted-string = 2366 comment = 2367 CFWS = 2368 FWS = 2369 CRLF = 2370 authserv-id = 2371 reasonspec = 2373 Appendix B. Extended Examples 2375 These examples are based on the following DNS setup: 2377 ; A domain with two mail servers, two hosts 2378 ; and two servers at the domain name 2379 $ORIGIN example.com. 2380 @ MX 10 mail-a 2381 MX 20 mail-b 2382 A 192.0.2.10 2383 A 192.0.2.11 2384 amy A 192.0.2.65 2385 bob A 192.0.2.66 2386 mail-a A 192.0.2.129 2387 mail-b A 192.0.2.130 2388 www CNAME example.com. 2390 ; A related domain 2391 $ORIGIN example.org. 2392 @ MX 10 mail-c 2393 mail-c A 192.0.2.140 2395 ; The reverse IP for those addresses 2396 $ORIGIN 2.0.192.in-addr.arpa. 2397 10 PTR example.com. 2398 11 PTR example.com. 2399 65 PTR amy.example.com. 2400 66 PTR bob.example.com. 2401 129 PTR mail-a.example.com. 2402 130 PTR mail-b.example.com. 2403 140 PTR mail-c.example.org. 2405 ; A rogue reverse IP domain that claims to be 2406 ; something it's not 2407 $ORIGIN 0.0.10.in-addr.arpa. 2408 4 PTR bob.example.com. 2410 B.1. Simple Examples 2412 These examples show various possible published records for 2413 example.com and which values if would cause check_host() to 2414 return "pass". Note that is "example.com". 2416 v=spf1 +all 2417 -- any passes 2419 v=spf1 a -all 2420 -- hosts 192.0.2.10 and 192.0.2.11 pass 2422 v=spf1 a:example.org -all 2423 -- no sending hosts pass since example.org has no A records 2425 v=spf1 mx -all 2426 -- sending hosts 192.0.2.129 and 192.0.2.130 pass 2428 v=spf1 mx:example.org -all 2429 -- sending host 192.0.2.140 passes 2431 v=spf1 mx mx:example.org -all 2432 -- sending hosts 192.0.2.129, 192.0.2.130, and 192.0.2.140 pass 2434 v=spf1 mx/30 mx:example.org/30 -all 2435 -- any sending host in 192.0.2.128/30 or 192.0.2.140/30 passes 2437 v=spf1 ptr -all 2438 -- sending host 192.0.2.65 passes (reverse DNS is valid and is in 2439 example.com) 2440 -- sending host 192.0.2.140 fails (reverse DNS is valid, but not 2441 in example.com) 2442 -- sending host 10.0.0.4 fails (reverse IP is not valid) 2444 v=spf1 ip4:192.0.2.128/28 -all 2445 -- sending host 192.0.2.65 fails 2446 -- sending host 192.0.2.129 passes 2448 B.2. Multiple Domain Example 2450 These examples show the effect of related records: 2452 example.org: "v=spf1 include:example.com include:example.net -all" 2454 This record would be used if mail from example.org actually came 2455 through servers at example.com and example.net. Example.org's 2456 designated servers are the union of example.com's and example.net's 2457 designated servers. 2459 la.example.org: "v=spf1 redirect=example.org" 2460 ny.example.org: "v=spf1 redirect=example.org" 2461 sf.example.org: "v=spf1 redirect=example.org" 2463 These records allow a set of domains that all use the same mail 2464 system to make use of that mail system's record. In this way, only 2465 the mail system's record needs to be updated when the mail setup 2466 changes. These domains' records never have to change. 2468 B.3. DNSBL Style Example 2470 Imagine that, in addition to the domain records listed above, there 2471 are these: 2473 $ORIGIN _spf.example.com. 2474 mary.mobile-users A 127.0.0.2 2475 fred.mobile-users A 127.0.0.2 2476 15.15.168.192.joel.remote-users A 127.0.0.2 2477 16.15.168.192.joel.remote-users A 127.0.0.2 2479 The following records describe users at example.com who mail from 2480 arbitrary servers, or who mail from personal servers. 2482 example.com: 2484 v=spf1 mx 2485 include:mobile-users._spf.%{d} 2486 include:remote-users._spf.%{d} 2487 -all 2489 mobile-users._spf.example.com: 2491 v=spf1 exists:%{l1r+}.%{d} 2493 remote-users._spf.example.com: 2495 v=spf1 exists:%{ir}.%{l1r+}.%{d} 2497 B.4. Multiple Requirements Example 2499 Say that your sender policy requires both that the IP address is 2500 within a certain range and that the reverse DNS for the IP matches. 2501 This can be done several ways, including the following: 2503 example.com. SPF ( "v=spf1 " 2504 "-include:ip4._spf.%{d} " 2505 "-include:ptr._spf.%{d} " 2506 "+all" ) 2507 ip4._spf.example.com. SPF "v=spf1 -ip4:192.0.2.0/24 +all" 2508 ptr._spf.example.com. SPF "v=spf1 -ptr +all" 2510 This example shows how the "-include" mechanism can be useful, how an 2511 SPF record that ends in "+all" can be very restrictive, and the use 2512 of De Morgan's Law. 2514 Appendix C. Further Testing Advice 2516 Another approach that can be helpful to publish records that include 2517 a "tracking exists:" mechanism. By looking at the name server logs, 2518 a rough list can then be generated. For example: 2520 v=spf1 exists:_h.%{h}._l.%{l}._o.%{o}._i.%{i}._spf.%{d} ?all 2522 Appendix D. SPF/Mediator Interactions 2524 There are three places that techniques can be used to ameliorate 2525 unintended SPF failures with mediators. 2527 D.1. Originating ADMDs 2529 The beginning, when email is first sent: 2531 o "Neutral" results could be given for IP addresses that might be 2532 forwarders, instead of "fail" results based on a list of known 2533 reliable forwarders. For example: 2535 "v=spf1 mx ?exists:%{ir}.whitlist.example.org -all" 2537 This would cause a lookup on an DNS white list (DNSWL) and cause a 2538 result of "fail" only for email not either coming from the 2539 domain's mx host(s) (SPF pass) or white listed sources (SPF 2540 neutral). This, in effect, outsources an element of sender policy 2541 to the maintainer of the whitelist. 2543 o The "MAIL FROM" identity could have additional information in the 2544 local-part that cryptographically identifies the mail as coming 2545 from an authorized source. In this case, such an SPF record could 2546 be used: 2548 "v=spf1 mx exists:%{l}._spf_verify.%{d} -all" 2550 Then, a specialized DNS server can be set up to serve the 2551 _spf_verify subdomain that validates the local-part. Although 2552 this requires an extra DNS lookup, this happens only when the 2553 email would otherwise be rejected as not coming from a known good 2554 source. 2555 Note that due to the 63-character limit for domain labels, this 2556 approach only works reliably if the local-part signature scheme is 2557 guaranteed either to only produce local-parts with a maximum of 63 2558 characters or to gracefully handle truncated local-parts. 2560 o Similarly, a specialized DNS server could be set up that will 2561 rate-limit the email coming from unexpected IP addresses. 2563 "v=spf1 mx exists:%{ir}._spf_rate.%{d} -all" 2565 o SPF allows the creation of per-user policies for special cases. 2566 For example, the following SPF record and appropriate wildcard DNS 2567 records can be used: 2569 "v=spf1 mx redirect=%{l1r+}._at_.%{o}._spf.%{d}" 2571 D.2. Mediators 2573 The middle, when email is forwarded:. 2575 o Mediators can solve the problem by rewriting the "MAIL FROM" to be 2576 in their own domain. This means mail rejected from the external 2577 mailbox will have to be forwarded back to the original sender by 2578 the forwarding service. Various schemes to do this exist though 2579 they vary widely in complexity and resource requirements on the 2580 part of the mediator. 2582 o Several popular MTAs can be forced from "alias" semantics to 2583 "mailing list" semantics by configuring an additional alias with 2584 "owner-" prepended to the original alias name (e.g., an alias of 2585 "friends: george@example.com, fred@example.org" would need another 2586 alias of the form "owner-friends: localowner"). 2588 o Mediators could reject mail that would "fail" SPF if forwarded 2589 using an SMTP reply code of 551, User not local, (see [RFC5321] 2590 section 3.4) to communicate the correct target address to resend 2591 the mail to. 2593 D.3. Receving ADMDs 2595 The end, when email is received: 2597 o If the owner of the external mailbox wishes to trust the mediator, 2598 he can direct the external mailbox's MTA to skip SPF tests when 2599 the client host belongs to the mediator. 2601 o Tests against other identities, such as the "HELO" identity, MAY 2602 be used to override a failed test against the "MAIL FROM" 2603 identity. 2605 o For larger domains, it might not be possible to have a complete or 2606 accurate list of forwarding services used by the owners of the 2607 domain's mailboxes. In such cases, whitelists of generally- 2608 recognized forwarding services could be employed. 2610 Appendix E. Mail Services 2612 MSPs (Mail Service Providers - [RFC5598] Section 2.3) that offer mail 2613 services to third-party domains, such as sending of bulk mail, might 2614 want to adjust their configurations in light of the authorization 2615 check described in this document. If the domain part of the "MAIL 2616 FROM" identity used for such email uses the domain of one of the MSPs 2617 domain, then the provider needs only to ensure that its sending host 2618 is authorized by its own SPF record, if any. 2620 If the "MAIL FROM" identity does not use the MSP's domain, then extra 2621 care has to be taken. The SPF record format has several options for 2622 the third-party domain to authorize the service provider's MTAs to 2623 send mail on its behalf. For MSPs, such as ISPs, that have a wide 2624 variety of customers using the same MTA, steps are required to 2625 mitiate the risk of cross-customer forgery (see Section 11.4). 2627 Appendix F. MTA Relays 2629 Relays are described in [RFC5598] Section 2.2.2. The authorization 2630 check generally precludes the use of arbitrary MTA relays between 2631 sender and receiver of an email message. 2633 Within an organization, MTA relays can be effectively deployed. 2634 However, for purposes of this document, such relays are effectively 2635 transparent. The SPF authorization check is a check between border 2636 MTAs of different ADMDs. 2638 For mail senders, this means that published SPF records have to 2639 authorize any MTAs that actually send across the Internet. Usually, 2640 these are just the border MTAs as internal MTAs simply forward mail 2641 to these MTAs for relaying. 2643 The receiving ADMD will generally want to perform the authorization 2644 check at the boundary MTAs, including all secondary MXs. Internal 2645 MTAs (including MTAs that might serve both as boundary MTAs and 2646 internal relays from secondary MXs when they are processing the 2647 relayed mail stream) then do not perform the authorization test. To 2648 perform the authorization test other than at the boundary, the host 2649 that first transferred the message to the receiving ADMD have to be 2650 determined, which can be difficult to extract from the message header 2651 because (a) header fields can be forged or malformed, and (b) there's 2652 no standard way to encode that information such that it can be 2653 reliably extracted. Testing other than at the boundary is likely to 2654 produce unreliable results. 2656 Appendix G. Local Policy Considerations 2658 SPF results can be used in combination with other methods to 2659 determine the final local disposition (either positive or negative of 2660 a message. It can also be considered dispositive on its own. 2662 G.1. Policy For SPF Pass 2664 SPF pass results can be used in combination with "white lists" of 2665 known "good" domains to bypass some or all additional pre-delivery 2666 email checks. Exactly which checks and how to determine appropriate 2667 white list entries has to be based on local conditions and 2668 requirements. 2670 G.2. Policy For SPF Fail 2672 SPF fail results can be used to reject messages during the SMTP 2673 transaction based on either "MAIL FROM" or "HELO" identity results. 2674 This reduces resource requirements for various content filtering 2675 methods and conserves bandwidth since rejection can be done before 2676 the SMTP content is transferred. It also gives immediate feedback to 2677 the sender who might then be able to resolve the issue. Due to some 2678 of the issues described above in this section (Section 10), SPF based 2679 rejection does present some risk of rejecting legitimate email when 2680 rejecting based on "MAIL FROM" results. 2682 SPF fail results can alternately be used as one input into a larger 2683 set of evaluations which might, based on a combination with other 2684 evaluation techniques, result in the email being marked negatively in 2685 some way (this might be via delivery to a special spam folder, 2686 modifying subject lines, or other locally determined means). 2687 Developing the details of such an approach have to be based on local 2688 conditions and requirements. Using SPF results in this way does not 2689 have the advantages of resource conservation and immediate feedback 2690 to the sender associated with SMTP rejection, but could produce fewer 2691 undesirable rejections in a well designed system. Such an approach 2692 might result in email that was not authorized by the sending ADMD 2693 being unknowingly delivered to end users. 2695 Either general approach can be used as they both leave a clear 2696 disposition of emails. They are either delivered in some manner or 2697 the sender is notified of the failure. Other dispositions such as 2698 "dropping" or deleting email after acceptance are inappropriate 2699 because they leave uncertainty and reduce the overall reliabilility 2700 and utility of email across the Internet. 2702 G.3. Policy For SPF Permerror 2704 The "permerror" result (see Section 2.6.7) indicates the SPF 2705 processing module at the receiver determined that the retrieved SPF 2706 policy record could not be interpreted. This gives no true 2707 indication about the authorized use of the data found in the 2708 envelope. 2710 As with all results, implementers have a choice to make regarding 2711 what to do with a message that yields this result. SMTP allows only 2712 a few basic options. 2714 Rejection of the message is an option, in that it is the one thing a 2715 receiver can do to draw attention to the difficulty encountered while 2716 protecting itself from messages that do not have a definite SPF 2717 result of some kind. However, if the SPF implementation is defective 2718 and returns spurious "permerror" results, only the sender is actively 2719 notified of the defect (in the form of rejected mail), and not the 2720 receiver making use of SPF. 2722 The less intrusive handling choice is to deliver the message, perhaps 2723 with some kind of annotation of the difficulty encountered and/or 2724 logging of a similar nature. However, this will not be desirable to 2725 operators that wish to implement SPF checking as strictly as 2726 possible, nor is this sort of passive problem reporting typically 2727 effective. 2729 There is of course the option placing this choice in the hands of the 2730 operator rather than the implementer since this kind of choice is 2731 often a matter of local policy rather than a condition with a 2732 universal solution, but this adds one more piece of complexity to an 2733 already non-trivial environment. 2735 Both implementers and operators need to be cautious of all choices 2736 and outcomes when handling SPF results. 2738 Appendix H. Protocol Status 2740 SPF has been in development since the summer of 2003 and has seen 2741 deployment beyond the developers beginning in December 2003. The 2742 design of SPF slowly evolved until the spring of 2004 and has since 2743 stabilized. There have been quite a number of forms of SPF, some 2744 written up as documents, some submitted as Internet Drafts, and many 2745 discussed and debated in development forums. The protocol was 2746 originally defined in [RFC4408], which this document replaces. 2748 [RFC4408] was designed to clearly document the protocol defined by 2749 earlier draft specifications of SPF as used in existing 2750 implementations. This updated specification is intended to clarify 2751 identified ambiguities in [RFC4408], resolve techincal issues 2752 identified in post-RFC 4408 deplyment experience, and document widely 2753 deployed extensions to SPF that have been developed since [RFC4408] 2754 was published. 2756 This document updates and replaces RFC 4408 that was part of a group 2757 of simultaneously published Experimental RFCs (RFC 4405, RFC 4406, 2758 RFC 4407, and RFC 4408) in 2006. At that time the IESG requested the 2759 community observe the success or failure of the two approaches 2760 documented in these RFCs during the two years following publication, 2761 in order that a community consensus could be reached in the future. 2763 SPF is widely deployed by large and small email providers alike. 2764 There are multiple, interoperable implementations. 2766 For SPF (as documented in RFC 4408) a careful effort was made to 2767 collect and document lessons learned and errata during the two year 2768 period. The errata list has been stable (no new submissions) and 2769 only minor protocol lessons learned were identified. Resolution of 2770 the IESG's experiment is documented in [RFC6686]. 2772 Appendix I. Change History 2774 Changes since RFC 4408 (to be removed prior to publication) 2776 Moved to standards track 2778 Authors updated 2780 IESG Note regarding experimental use replaced with discussion of 2781 results 2783 Process errata: 2785 Resolved Section 2.5.7 PermError on invalid domains after macro 2786 expansion errata in favor of documenting that different clients 2787 produce different results. 2789 Add %v macro to ABNF grammar 2791 Replace "uric" by "unreserved" 2793 Recommend an SMTP reply code for optional permerror rejections 2795 Correct syntax in Received-SPF examples 2797 Fix unknown-modifier clause is too greedy in ABNF 2799 Correct use of empty domain-spec on exp modifier 2801 Fix minor typo errata 2803 Convert to spfbis working group draft, 2804 draft-ietf-spfbis-4408bis-00 2806 Addressed Ticket #1, RFC 4408 Section 2.5.6 - Temporary errors by 2807 giving the option to turn repeated SERVFAIL into permerror and 2808 adding RFC 2308 reference. 2810 Clarified text about IPv4 mapped addresses to resolve test suite 2811 ambiguity 2813 Clarified ambiguity about result when more than 10 "mx" or "ptr" 2814 records are returned for lookup to specify permerror. This 2815 resolves one of the test suite ambiguities 2817 Made all references to result codes lower case per issue #7 2818 Adjusted section 2.2 Requirement to check mail from per issue #15 2820 Added missing "v" element in macro-letter in the collected ABNF 2821 per issue #16 - section 8.1 was already fixed in the pre-WG draft 2823 Marked ptr and "p" macro SHOULD NOT use per issue #27 2825 Expunged lower case may from the draft per issue #8 2827 Expunged "x-" name as an obsolete concept 2829 Updated obslete references: RFC2821 to RFC5321, RFC2822 to 2830 RFC5322, and RFC4234 to RFC5234 2832 Refer to RFC6647 to describe greylisting instead of trying to 2833 describe it directly. 2835 Updated informative references to the current versions. 2837 Start to rework section 9 with some RFC5598 terms. 2839 Added mention of RFC 6552 feedback reports in section 9. 2841 Added draft-ietf-spfbis-experiment as an informational reference. 2843 Drop Type SPF. 2845 Try and clarify informational nature of RFC3696 2847 Fix ABNF nits and add missing definitions per Bill's ABNF checker. 2849 Make DNS lookup time limit SHOULD instead of MAY. 2851 Reorganize and clarify processing limits. Move hard limits to new 2852 section 4.6.4, Evaluation Limits. Move advice to non-normative 2853 section 9. 2855 Removed paragraph in section 10.1 about limiting total data 2856 volumes as it is unused (and removable per the charter) and serves 2857 no purpose (it isn't something that actually can be implemented in 2858 any reasonable way). 2860 Added text and figures from Alessandro Vesely in section 9.1 to 2861 better explain DNS resource limits. 2863 Multiple editorial fixes from Murray Kucherawy's review. 2865 Also based on Murray's review, reworked SMTP identity definitions 2866 and made RFC 5598 a normative reference instead of informative. 2867 This is a downref that will have to be mentioned in the last call. 2869 Added RFC 3834 as an informative reference about backscatter. 2871 Added IDN requirements and normative reference to RFC 5890 to deal 2872 with the question "like DKIM did it.: 2874 Added informative reference to RFC 4632 for CIDR and use CIDR 2875 prefix length instead of CIDR-length to match its terminology. 2877 Simplified the exists description. 2879 Added text on creating a Authentication-Results header field that 2880 matches the Received-SPF header field information and added a 2881 normative reference to RFC 5451. 2883 Added informative reference to RFC 2782 due to SRV mention. 2885 Added informative reference to RFC 3464 due to DSN mention. 2887 Added informative reference to RFC 5617 for its DNS wildcard use. 2889 Clarified the intended match/no-match method for exists. 2891 Added new sections on Receiver policy for SPF pass, fail, and 2892 permerror. 2894 Added new section 9 discussion on treatment of bounces and the 2895 significance of HELO records. 2897 Added request to IANA to update the SPF modifier registry. 2899 Substantially reorganized the document for improved readability 2900 for new users based on WG consensus. 2902 Added new DNS "void lookup" processing limit to mitigate potental 2903 future risk of SPF being used as a DDoS vector. 2905 Author's Address 2907 Scott Kitterman 2908 Kitterman Technical Services 2909 3611 Scheel Dr 2910 Ellicott City, MD 21042 2911 United States of America 2913 Email: scott@kitterman.com