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