idnits 2.17.1 draft-ietf-spfbis-4408bis-01.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 7 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 1217 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 (June 27, 2012) is 4320 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 2017, but not defined == Unused Reference: 'RFC5598' is defined on line 1929, but no explicit reference was found in the text ** Obsolete normative reference: RFC 3513 (Obsoleted by RFC 4291) -- Possible downref: Non-RFC (?) normative reference: ref. 'US-ASCII' -- Obsolete informational reference (is this intentional?): RFC 2440 (Obsoleted by RFC 4880) -- Obsolete informational reference (is this intentional?): RFC 2554 (Obsoleted by RFC 4954) -- Obsolete informational reference (is this intentional?): RFC 3851 (Obsoleted by RFC 5751) -- Obsolete informational reference (is this intentional?): RFC 4408 (Obsoleted by RFC 7208) -- Obsolete informational reference (is this intentional?): RFC 4409 (Obsoleted by RFC 6409) Summary: 1 error (**), 0 flaws (~~), 8 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group S. Kitterman 3 Internet-Draft Agari 4 Obsoletes: 4408 (if approved) June 27, 2012 5 Intended status: Standards Track 6 Expires: December 29, 2012 8 Sender Policy Framework (SPF) for Authorizing Use of Domains in Email, 9 Version 1 10 draft-ietf-spfbis-4408bis-01.txt 12 Abstract 14 E-mail 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 reverse-path 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 a domain can 19 explicitly authorize the hosts that are allowed to use its domain 20 name, and a receiving host can check such authorization. This 21 document obsoletes RFC4408. 23 Status of this Memo 25 This Internet-Draft is submitted in full conformance with the 26 provisions of BCP 78 and BCP 79. 28 Internet-Drafts are working documents of the Internet Engineering 29 Task Force (IETF). Note that other groups may also distribute 30 working documents as Internet-Drafts. The list of current Internet- 31 Drafts is at http://datatracker.ietf.org/drafts/current/. 33 Internet-Drafts are draft documents valid for a maximum of six months 34 and may be updated, replaced, or obsoleted by other documents at any 35 time. It is inappropriate to use Internet-Drafts as reference 36 material or to cite them other than as "work in progress." 38 This Internet-Draft will expire on December 29, 2012. 40 Copyright Notice 42 Copyright (c) 2012 IETF Trust and the persons identified as the 43 document authors. All rights reserved. 45 This document is subject to BCP 78 and the IETF Trust's Legal 46 Provisions Relating to IETF Documents 47 (http://trustee.ietf.org/license-info) in effect on the date of 48 publication of this document. Please review these documents 49 carefully, as they describe your rights and restrictions with respect 50 to this document. Code Components extracted from this document must 51 include Simplified BSD License text as described in Section 4.e of 52 the Trust Legal Provisions and are provided without warranty as 53 described in the Simplified BSD License. 55 This document may contain material from IETF Documents or IETF 56 Contributions published or made publicly available before November 57 10, 2008. The person(s) controlling the copyright in some of this 58 material may not have granted the IETF Trust the right to allow 59 modifications of such material outside the IETF Standards Process. 60 Without obtaining an adequate license from the person(s) controlling 61 the copyright in such materials, this document may not be modified 62 outside the IETF Standards Process, and derivative works of it may 63 not be created outside the IETF Standards Process, except to format 64 it for publication as an RFC or to translate it into languages other 65 than English. 67 Table of Contents 69 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5 70 1.1. Protocol Status . . . . . . . . . . . . . . . . . . . . . 5 71 1.2. Experimental History . . . . . . . . . . . . . . . . . . . 6 72 1.3. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 73 2. Operation . . . . . . . . . . . . . . . . . . . . . . . . . . 7 74 2.1. The HELO Identity . . . . . . . . . . . . . . . . . . . . 7 75 2.2. The MAIL FROM Identity . . . . . . . . . . . . . . . . . . 7 76 2.3. Publishing Authorization . . . . . . . . . . . . . . . . . 7 77 2.4. Checking Authorization . . . . . . . . . . . . . . . . . . 8 78 2.5. Interpreting the Result . . . . . . . . . . . . . . . . . 9 79 2.5.1. None . . . . . . . . . . . . . . . . . . . . . . . . . 9 80 2.5.2. Neutral . . . . . . . . . . . . . . . . . . . . . . . 10 81 2.5.3. Pass . . . . . . . . . . . . . . . . . . . . . . . . . 10 82 2.5.4. Fail . . . . . . . . . . . . . . . . . . . . . . . . . 10 83 2.5.5. Softfail . . . . . . . . . . . . . . . . . . . . . . . 10 84 2.5.6. TempError . . . . . . . . . . . . . . . . . . . . . . 11 85 2.5.7. PermError . . . . . . . . . . . . . . . . . . . . . . 11 86 3. SPF Records . . . . . . . . . . . . . . . . . . . . . . . . . 12 87 3.1. Publishing . . . . . . . . . . . . . . . . . . . . . . . . 12 88 3.1.1. DNS Resource Record Types . . . . . . . . . . . . . . 12 89 3.1.2. Multiple DNS Records . . . . . . . . . . . . . . . . . 13 90 3.1.3. Multiple Strings in a Single DNS record . . . . . . . 13 91 3.1.4. Record Size . . . . . . . . . . . . . . . . . . . . . 13 92 3.1.5. Wildcard Records . . . . . . . . . . . . . . . . . . . 14 93 4. The check_host() Function . . . . . . . . . . . . . . . . . . 15 94 4.1. Arguments . . . . . . . . . . . . . . . . . . . . . . . . 15 95 4.2. Results . . . . . . . . . . . . . . . . . . . . . . . . . 15 96 4.3. Initial Processing . . . . . . . . . . . . . . . . . . . . 15 97 4.4. Record Lookup . . . . . . . . . . . . . . . . . . . . . . 16 98 4.5. Selecting Records . . . . . . . . . . . . . . . . . . . . 16 99 4.6. Record Evaluation . . . . . . . . . . . . . . . . . . . . 17 100 4.6.1. Term Evaluation . . . . . . . . . . . . . . . . . . . 17 101 4.6.2. Mechanisms . . . . . . . . . . . . . . . . . . . . . . 17 102 4.6.3. Modifiers . . . . . . . . . . . . . . . . . . . . . . 18 103 4.7. Default Result . . . . . . . . . . . . . . . . . . . . . . 18 104 4.8. Domain Specification . . . . . . . . . . . . . . . . . . . 19 105 5. Mechanism Definitions . . . . . . . . . . . . . . . . . . . . 20 106 5.1. "all" . . . . . . . . . . . . . . . . . . . . . . . . . . 20 107 5.2. "include" . . . . . . . . . . . . . . . . . . . . . . . . 21 108 5.3. "a" . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 109 5.4. "mx" . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 110 5.5. "ptr" (deprecated) . . . . . . . . . . . . . . . . . . . . 23 111 5.6. "ip4" and "ip6" . . . . . . . . . . . . . . . . . . . . . 24 112 5.7. "exists" . . . . . . . . . . . . . . . . . . . . . . . . . 25 113 6. Modifier Definitions . . . . . . . . . . . . . . . . . . . . . 26 114 6.1. redirect: Redirected Query . . . . . . . . . . . . . . . . 26 115 6.2. exp: Explanation . . . . . . . . . . . . . . . . . . . . . 27 116 7. The Received-SPF Header Field . . . . . . . . . . . . . . . . 29 117 8. Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 118 8.1. Macro Definitions . . . . . . . . . . . . . . . . . . . . 31 119 8.2. Expansion Examples . . . . . . . . . . . . . . . . . . . . 34 120 9. Implications . . . . . . . . . . . . . . . . . . . . . . . . . 35 121 9.1. Sending Domains . . . . . . . . . . . . . . . . . . . . . 35 122 9.2. Mailing Lists . . . . . . . . . . . . . . . . . . . . . . 35 123 9.3. Forwarding Services and Aliases . . . . . . . . . . . . . 35 124 9.4. Mail Services . . . . . . . . . . . . . . . . . . . . . . 37 125 9.5. MTA Relays . . . . . . . . . . . . . . . . . . . . . . . . 38 126 10. Security Considerations . . . . . . . . . . . . . . . . . . . 39 127 10.1. Processing Limits . . . . . . . . . . . . . . . . . . . . 39 128 10.2. SPF-Authorized Email May Contain Other False Identities . 40 129 10.3. Spoofed DNS and IP Data . . . . . . . . . . . . . . . . . 41 130 10.4. Cross-User Forgery . . . . . . . . . . . . . . . . . . . . 41 131 10.5. Untrusted Information Sources . . . . . . . . . . . . . . 41 132 10.6. Privacy Exposure . . . . . . . . . . . . . . . . . . . . . 42 133 11. Contributors and Acknowledgements . . . . . . . . . . . . . . 43 134 12. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 44 135 12.1. The SPF DNS Record Type . . . . . . . . . . . . . . . . . 44 136 12.2. The Received-SPF Mail Header Field . . . . . . . . . . . . 44 137 13. References . . . . . . . . . . . . . . . . . . . . . . . . . . 45 138 13.1. Normative References . . . . . . . . . . . . . . . . . . . 45 139 13.2. Informative References . . . . . . . . . . . . . . . . . . 46 140 Appendix A. Collected ABNF . . . . . . . . . . . . . . . . . . . 47 141 Appendix B. Extended Examples . . . . . . . . . . . . . . . . . . 49 142 B.1. Simple Examples . . . . . . . . . . . . . . . . . . . . . 49 143 B.2. Multiple Domain Example . . . . . . . . . . . . . . . . . 50 144 B.3. DNSBL Style Example . . . . . . . . . . . . . . . . . . . 51 145 B.4. Multiple Requirements Example . . . . . . . . . . . . . . 51 146 Appendix C. Change History . . . . . . . . . . . . . . . . . . . 52 147 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 54 149 1. Introduction 151 The current email infrastructure has the property that any host 152 injecting mail into the mail system can identify itself as any domain 153 name it wants. Hosts can do this at a variety of levels: in 154 particular, the session, the envelope, and the mail headers. 155 Although this feature is desirable in some circumstances, it is a 156 major obstacle to reducing Unsolicited Bulk email (UBE, aka spam). 157 Furthermore, many domain name holders are understandably concerned 158 about the ease with which other entities can make use of their domain 159 names, often with malicious intent. 161 This document defines a protocol by which domain owners can authorize 162 hosts to use their domain name in the "MAIL FROM" or "HELO" identity. 163 Compliant domain holders publish Sender Policy Framework (SPF) 164 records specifying which hosts are permitted to use their names, and 165 compliant mail receivers use the published SPF records to test the 166 authorization of sending Mail Transfer Agents (MTAs) using a given 167 "HELO" or "MAIL FROM" identity during a mail transaction. 169 An additional benefit to mail receivers is that after the use of an 170 identity is verified, local policy decisions about the mail can be 171 made based on the sender's domain, rather than the host's IP address. 172 This is advantageous because reputation of domain names is likely to 173 be more accurate than reputation of host IP addresses. Furthermore, 174 if a claimed identity fails verification, local policy can take 175 stronger action against such email, such as rejecting it. 177 1.1. Protocol Status 179 SPF has been in development since the summer of 2003 and has seen 180 deployment beyond the developers beginning in December 2003. The 181 design of SPF slowly evolved until the spring of 2004 and has since 182 stabilized. There have been quite a number of forms of SPF, some 183 written up as documents, some submitted as Internet Drafts, and many 184 discussed and debated in development forums. The protocol was 185 originally documented in [RFC4408], which this memo replaces. 187 The goal of this document is to clearly document the protocol defined 188 by earlier draft specifications of SPF as used in existing 189 implementations. This conception of SPF is sometimes called "SPF 190 Classic". It is understood that particular implementations and 191 deployments will differ from, and build upon, this work. It is hoped 192 that we have nonetheless captured the common understanding of SPF 193 version 1. 195 1.2. Experimental History 197 This document updates and replaces RFC 4408 that was part of a group 198 of simultaneously published Experimental RFCs (RFC 4405, RFC 4406, 199 RFC 4407, and RFC 4408) in 2006. At that time the IESG requested the 200 community observe the success or failure of the two approaches 201 documented in these RFCs during the two years following publication, 202 in order that a community consensus can be reached in the future. 204 SPF is widely deployed by large and small email providers alike. 205 There are multiple, interoperable implementations. 207 For SPF (as documented in RFC 4408) a careful effort was made to 208 collect and document lessons learned and errata during the two year 209 period. The errata list has been stable (no new submissions) and 210 only minor protocol lessons learned were identified. 212 1.3. Terminology 214 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 215 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 216 "OPTIONAL" in this document are to be interpreted as described in 217 [RFC2119]. 219 This document is concerned with the portion of a mail message 220 commonly called "envelope sender", "return path", "reverse path", 221 "bounce address", "5321 FROM", or "MAIL FROM". Since these terms are 222 either not well defined or often used casually, this document defines 223 the "MAIL FROM" identity in Section 2.2. Note that other terms that 224 might superficially look like the common terms, such as "reverse- 225 path", are used only with the defined meanings from normative 226 documents. 228 2. Operation 230 2.1. The HELO Identity 232 The "HELO" identity derives from either the SMTP HELO or EHLO command 233 (see [RFC5321]). These commands supply the SMTP client (sending 234 host) for the SMTP session. Note that requirements for the domain 235 presented in the EHLO or HELO command are not always clear to the 236 sending party, and SPF clients must be prepared for the "HELO" 237 identity to be malformed or an IP address literal. At the time of 238 this writing, many legitimate emails are delivered with invalid HELO 239 domains. 241 It is RECOMMENDED that SPF clients not only check the "MAIL FROM" 242 identity, but also separately check the "HELO" identity by applying 243 the check_host() function (Section 4) to the "HELO" identity as the 244 . 246 2.2. The MAIL FROM Identity 248 The "MAIL FROM" identity derives from the SMTP MAIL command (see 249 [RFC5321]). This command supplies the "reverse-path" for a message, 250 which generally consists of the sender mailbox, and is the mailbox to 251 which notification messages are to be sent if there are problems 252 delivering the message. 254 [RFC5321] allows the reverse-path to be null (see Section 4.5.5 in 255 RFC 5321). In this case, there is no explicit sender mailbox, and 256 such a message can be assumed to be a notification message from the 257 mail system itself. When the reverse-path is null, this document 258 defines the "MAIL FROM" identity to be the mailbox composed of the 259 localpart "postmaster" and the "HELO" identity (which might or might 260 not have been checked separately before). 262 SPF clients MUST check the "MAIL FROM" identity if a completed "HELO" 263 check has not reached a definitive policy result by applying the 264 check_host() function to the "MAIL FROM" identity as the . 266 2.3. Publishing Authorization 268 An SPF-compliant domain MUST publish a valid SPF record as described 269 in Section 3. This record authorizes the use of the domain name in 270 the "HELO" and "MAIL FROM" identities by the MTAs it specifies. 272 If domain owners choose to publish SPF records, it is RECOMMENDED 273 that they end in "-all", or redirect to other records that do, so 274 that a definitive determination of authorization can be made. 276 Domain holders can publish SPF records that explicitly authorize no 277 hosts if mail should never originate using that domain. 279 When changing SPF records, care must be taken to ensure that there is 280 a transition period so that the old policy remains valid until all 281 legitimate email has been checked. 283 2.4. Checking Authorization 285 A mail receiver can perform a set of SPF checks for each mail message 286 it receives. An SPF check tests the authorization of a client host 287 to emit mail with a given identity. Typically, such checks are done 288 by a receiving MTA, but can be performed elsewhere in the mail 289 processing chain so long as the required information is available and 290 reliable. At least the "MAIL FROM" identity MUST be checked, but it 291 is RECOMMENDED that the "HELO" identity also be checked beforehand. 293 Without explicit approval of the domain owner, checking other 294 identities against SPF version 1 records is NOT RECOMMENDED because 295 there are cases that are known to give incorrect results. For 296 example, almost all mailing lists rewrite the "MAIL FROM" identity 297 (see Section 9.2), but some do not change any other identities in the 298 message. The scenario described in Section 9.3, sub-section 1.2, is 299 another example. Documents that define other identities should 300 define the method for explicit approval. 302 It is possible that mail receivers will use the SPF check as part of 303 a larger set of tests on incoming mail. The results of other tests 304 might influence whether or not a particular SPF check is performed. 305 For example, finding the sending host's IP address on a local white 306 list might cause all other tests to be skipped and all mail from that 307 host to be accepted. 309 When a mail receiver decides to perform an SPF check, it MUST use a 310 correctly-implemented check_host() function (Section 4) evaluated 311 with the correct parameters. Although the test as a whole is 312 optional, once it has been decided to perform a test it must be 313 performed as specified so that the correct semantics are preserved 314 between publisher and receiver. 316 To make the test, the mail receiver MUST evaluate the check_host() 317 function with the arguments set as follows: 319 - the IP address of the SMTP client that is emitting the 320 mail, either IPv4 or IPv6. 322 - the domain portion of the "MAIL FROM" or "HELO" identity. 324 - the "MAIL FROM" or "HELO" identity. 326 Note that the argument might not be a well-formed domain 327 name. For example, if the reverse-path was null, then the EHLO/HELO 328 domain is used, with its associated problems (see Section 2.1). In 329 these cases, check_host() is defined in Section 4.3 to return a 330 "none" result. 332 Although invalid, malformed, or non-existent domains cause SPF checks 333 to return "none" because no SPF record can be found, it has long been 334 the policy of many MTAs to reject email from such domains, especially 335 in the case of invalid "MAIL FROM". Rejecting email will prevent one 336 method of circumventing of SPF records. 338 Implementations must take care to correctly extract the from 339 the data given with the SMTP MAIL FROM command as many MTAs will 340 still accept such things as source routes (see [RFC5321], Appendix 341 C), the %-hack (see [RFC1123]), and bang paths (see [RFC1983]). 342 These archaic features have been maliciously used to bypass security 343 systems. 345 2.5. Interpreting the Result 347 This section describes how software that performs the authorization 348 should interpret the results of the check_host() function. The 349 authorization check SHOULD be performed during the processing of the 350 SMTP transaction that sends the mail. This allows errors to be 351 returned directly to the sending MTA by way of SMTP replies. 353 Performing the authorization after the SMTP transaction has finished 354 can cause problems, such as the following: (1) It might be difficult 355 to accurately extract the required information from potentially 356 deceptive headers; (2) legitimate email might fail because the 357 sender's policy had since changed. 359 Generating non-delivery notifications to forged identities that have 360 failed the authorization check is generally abusive and against the 361 explicit wishes of the identity owner. 363 2.5.1. None 365 A result of "none" means that no records were published by the domain 366 or that no checkable sender domain could be determined from the given 367 identity. The checking software cannot ascertain whether or not the 368 client host is authorized. 370 2.5.2. Neutral 372 The domain owner has explicitly stated that he cannot or does not 373 want to assert whether or not the IP address is authorized. A 374 "neutral" result MUST be treated exactly like the "none" result; the 375 distinction exists only for informational purposes. Treating 376 "neutral" more harshly than "none" would discourage domain owners 377 from testing the use of SPF records (see Section 9.1). 379 2.5.3. Pass 381 A "pass" result means that the client is authorized to inject mail 382 with the given identity. The domain can now, in the sense of 383 reputation, be considered responsible for sending the message. 384 Further policy checks can now proceed with confidence in the 385 legitimate use of the identity. 387 2.5.4. Fail 389 A "fail" result is an explicit statement that the client is not 390 authorized to use the domain in the given identity. The checking 391 software can choose to mark the mail based on this or to reject the 392 mail outright. 394 If the checking software chooses to reject the mail during the SMTP 395 transaction, then it SHOULD use an SMTP reply code of 550 (see 396 [RFC5321]) and, if supported, the 5.7.1 enhanced status code (see 397 [RFC3463]), in addition to an appropriate reply text. The 398 check_host() function will return either a default explanation string 399 or one from the domain that published the SPF records (see 400 Section 6.2). If the information does not originate with the 401 checking software, it should be made clear that the text is provided 402 by the sender's domain. For example: 404 550-5.7.1 SPF MAIL FROM check failed: 405 550-5.7.1 The domain example.com explains: 406 550 5.7.1 Please see http://www.example.com/mailpolicy.html 408 2.5.5. Softfail 410 A "softfail" result should be treated as somewhere between a "fail" 411 and a "neutral". The domain believes the host is not authorized but 412 is not willing to make that strong of a statement. Receiving 413 software SHOULD NOT reject the message based solely on this result, 414 but MAY subject the message to closer scrutiny than normal. 416 The domain owner wants to discourage the use of this host and thus 417 desires limited feedback when a "softfail" result occurs. For 418 example, the recipient's Mail User Agent (MUA) could highlight the 419 "softfail" status, or the receiving MTA could give the sender a 420 message using a technique called "greylisting" whereby the MTA can 421 issue an SMTP reply code of 451 (4.3.0 enhanced status code) with a 422 note the first time the message is received, but accept it the second 423 time. 425 2.5.6. TempError 427 A "temperror" result means that the SPF client encountered a 428 transient error while performing the check. Checking software can 429 choose to accept or temporarily reject the message. If the message 430 is rejected during the SMTP transaction for this reason, the software 431 SHOULD use an SMTP reply code of 451 and, if supported, the 4.4.3 432 enhanced status code. 434 2.5.7. PermError 436 A "permerror" result means that the domain's published records could 437 not be correctly interpreted. This signals an error condition that 438 requires manual intervention to be resolved, as opposed to the 439 temperror result. If the message is rejected during the SMTP 440 transaction for this reason, the software SHOULD use an SMTP reply 441 code of 550 and, if supported, the 5.5.2 enhanced status code. Be 442 aware that if the domain owner uses macros (Section 8), it is 443 possible that this result is due to the checked identities having an 444 unexpected format. 446 3. SPF Records 448 An SPF record is a DNS Resource Record (RR) that declares which hosts 449 are, and are not, authorized to use a domain name for the "HELO" and 450 "MAIL FROM" identities. Loosely, the record partitions all hosts 451 into permitted and not-permitted sets (though some hosts might fall 452 into neither category). 454 The SPF record is a single string of text. An example record is the 455 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 3.1. Publishing 464 Domain owners wishing to be SPF compliant must publish SPF records 465 for the hosts that are used in the "MAIL FROM" and "HELO" identities. 466 The SPF records are placed in the DNS tree at the host name it 467 pertains to, not a subdomain under it, such as is done with SRV 468 records. This is the same whether the TXT or SPF RR type (see 469 Section 3.1.1) is used. 471 The example above in Section 3 might be published via these lines in 472 a domain zone file: 474 example.com. TXT "v=spf1 +mx a:colo.example.com/28 -all" 475 smtp-out.example.com. TXT "v=spf1 a -all" 477 When publishing via TXT records, beware of other TXT records 478 published there for other purposes. They might cause problems with 479 size limits (see Section 3.1.4). 481 3.1.1. DNS Resource Record Types 483 This document defines a new DNS RR of type SPF, code 99. The format 484 of this type is identical to the TXT RR [RFC1035]. For either type, 485 the character content of the record is encoded as [US-ASCII]. 487 It is recognized that the current practice (using a TXT record) is 488 not optimal, but it is necessary because there are a number of DNS 489 server and resolver implementations in common use that cannot handle 490 the new RR type. The two-record-type scheme provides a forward path 491 to the better solution of using an RR type reserved for this purpose. 493 An SPF-compliant domain name SHOULD have SPF records of both RR 494 types. A compliant domain name MUST have a record of at least one 495 type. If a domain has records of both types, they MUST have 496 identical content. For example, instead of publishing just one 497 record as in Section 3.1 above, it is better to publish: 499 example.com. IN TXT "v=spf1 +mx a:colo.example.com/28 -all" 500 example.com. IN SPF "v=spf1 +mx a:colo.example.com/28 -all" 502 Example RRs in this document are shown with the TXT record type; 503 however, they could be published with the SPF type or with both 504 types. 506 3.1.2. Multiple DNS Records 508 A domain name MUST NOT have multiple records that would cause an 509 authorization check to select more than one record. See Section 4.5 510 for the selection rules. 512 3.1.3. Multiple Strings in a Single DNS record 514 As defined in [RFC1035] sections 3.3.14 and 3.3, a single text DNS 515 record (either TXT or SPF RR types) can be composed of more than one 516 string. If a published record contains multiple strings, then the 517 record MUST be treated as if those strings are concatenated together 518 without adding spaces. For example: 520 IN TXT "v=spf1 .... first" "second string..." 522 MUST be treated as equivalent to 524 IN TXT "v=spf1 .... firstsecond string..." 526 SPF or TXT records containing multiple strings are useful in 527 constructing records that would exceed the 255-byte maximum length of 528 a string within a single TXT or SPF RR record. 530 3.1.4. Record Size 532 The published SPF record for a given domain name SHOULD remain small 533 enough that the results of a query for it will fit within 512 octets. 534 This will keep even older DNS implementations from falling over to 535 TCP. Since the answer size is dependent on many things outside the 536 scope of this document, it is only possible to give this guideline: 537 If the combined length of the DNS name and the text of all the 538 records of a given type (TXT or SPF) is under 450 characters, then 539 DNS answers should fit in UDP packets. Note that when computing the 540 sizes for queries of the TXT format, one must take into account any 541 other TXT records published at the domain name. Records that are too 542 long to fit in a single UDP packet MAY be silently ignored by SPF 543 clients. 545 3.1.5. Wildcard Records 547 Use of wildcard records for publishing is not recommended. Care must 548 be taken if wildcard records are used. If a domain publishes 549 wildcard MX records, it might want to publish wildcard declarations, 550 subject to the same requirements and problems. In particular, the 551 declaration must be repeated for any host that has any RR records at 552 all, and for subdomains thereof. For example, the example given in 553 [RFC1034], Section 4.3.3, could be extended with the following: 555 X.COM. MX 10 A.X.COM 556 X.COM. TXT "v=spf1 a:A.X.COM -all" 558 *.X.COM. MX 10 A.X.COM 559 *.X.COM. TXT "v=spf1 a:A.X.COM -all" 561 A.X.COM. A 1.2.3.4 562 A.X.COM. MX 10 A.X.COM 563 A.X.COM. TXT "v=spf1 a:A.X.COM -all" 565 *.A.X.COM. MX 10 A.X.COM 566 *.A.X.COM. TXT "v=spf1 a:A.X.COM -all" 568 Notice that SPF records must be repeated twice for every name within 569 the domain: once for the name, and once with a wildcard to cover the 570 tree under the name. 572 Use of wildcards is discouraged in general as they cause every name 573 under the domain to exist and queries against arbitrary names will 574 never return RCODE 3 (Name Error). 576 4. The check_host() Function 578 The check_host() function fetches SPF records, parses them, and 579 interprets them to determine whether a particular host is or is not 580 permitted to send mail with a given identity. Mail receivers that 581 perform this check MUST correctly evaluate the check_host() function 582 as described here. 584 Implementations MAY use a different algorithm than the canonical 585 algorithm defined here, so long as the results are the same in all 586 cases. 588 4.1. Arguments 590 The check_host() function takes these arguments: 592 - the IP address of the SMTP client that is emitting the 593 mail, either IPv4 or IPv6. 595 - the domain that provides the sought-after authorization 596 information; initially, the domain portion of the "MAIL 597 FROM" or "HELO" identity. 599 - the "MAIL FROM" or "HELO" identity. 601 The domain portion of will usually be the same as the 602 argument when check_host() is initially evaluated. However, 603 this will generally not be true for recursive evaluations (see 604 Section 5.2 below). 606 Actual implementations of the check_host() function might need 607 additional arguments. 609 4.2. Results 611 The function check_host() can return one of several results described 612 in Section 2.5. Based on the result, the action to be taken is 613 determined by the local policies of the receiver. 615 4.3. Initial Processing 617 If the is malformed (label longer than 63 characters, zero- 618 length label not at the end, etc.) or is not a fully qualified domain 619 name, or if the DNS lookup returns "domain does not exist" (RCODE 3), 620 check_host() immediately returns the result "none". 622 If the has no localpart, substitute the string "postmaster" 623 for the localpart. 625 4.4. Record Lookup 627 In accordance with how the records are published (see Section 3.1 628 above), a DNS query needs to be made for the name, querying 629 for either RR type TXT, SPF, or both. If both SPF and TXT RRs are 630 looked up, the queries MAY be done in parallel. 632 If all DNS lookups that are made return a server failure (RCODE 2), 633 or other error (RCODE other than 0 or 3), or time out, then 634 check_host() exits immediately with the result "temperror". 635 Alternatively, for a server failure (RCODE 2) result, check_host() 636 MAY track failures and treat multiple failures within 24 hours for 637 the same domain as "permerror". 639 This alternate, is not intended to save further queries, which MUST 640 be done according to RFC 2308, but to return a permanent negative 641 completion reply code to the client, instead of a transient one, 642 thereby shortening the queue time of messages that cannot be 643 accepted. 645 4.5. Selecting Records 647 Records begin with a version section: 649 record = version terms *SP 650 version = "v=spf1" 652 Starting with the set of records that were returned by the lookup, 653 record selection proceeds in two steps: 655 1. Records that do not begin with a version section of exactly 656 "v=spf1" are discarded. Note that the version section is 657 terminated either by an SP character or the end of the record. A 658 record with a version section of "v=spf10" does not match and 659 must be discarded. 661 2. If any records of type SPF are in the set, then all records of 662 type TXT are discarded. 664 After the above steps, there should be exactly one record remaining 665 and evaluation can proceed. If there are two or more records 666 remaining, then check_host() exits immediately with the result of 667 "permerror". 669 If no matching records are returned, an SPF client MUST assume that 670 the domain makes no SPF declarations. SPF processing MUST stop and 671 return "none". 673 4.6. Record Evaluation 675 After one SPF record has been selected, the check_host() function 676 parses and interprets it to find a result for the current test. If 677 there are any syntax errors, check_host() returns immediately with 678 the result "permerror". 680 Implementations MAY choose to parse the entire record first and 681 return "permerror" if the record is not syntactically well formed. 682 However, in all cases, any syntax errors anywhere in the record MUST 683 be detected. 685 4.6.1. Term Evaluation 687 There are two types of terms: mechanisms and modifiers. A record 688 contains an ordered list of these as specified in the following 689 Augmented Backus-Naur Form (ABNF). 691 terms = *( 1*SP ( directive / modifier ) ) 693 directive = [ qualifier ] mechanism 694 qualifier = "+" / "-" / "?" / "~" 695 mechanism = ( all / include 696 / A / MX / PTR / IP4 / IP6 / exists ) 697 modifier = redirect / explanation / unknown-modifier 698 unknown-modifier = name "=" macro-string 699 ; where name is not any known modifier 701 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 703 Most mechanisms allow a ":" or "/" character after the name. 705 Modifiers always contain an equals ('=') character immediately after 706 the name, and before any ":" or "/" characters that might be part of 707 the macro-string. 709 Terms that do not contain any of "=", ":", or "/" are mechanisms, as 710 defined in Section 5. 712 As per the definition of the ABNF notation in [RFC5234], mechanism 713 and modifier names are case-insensitive. 715 4.6.2. Mechanisms 717 Each mechanism is considered in turn from left to right. If there 718 are no more mechanisms, the result is specified in Section 4.7. 720 When a mechanism is evaluated, one of three things can happen: it can 721 match, not match, or throw an exception. 723 If it matches, processing ends and the qualifier value is returned as 724 the result of that record. If it does not match, processing 725 continues with the next mechanism. If it throws an exception, 726 mechanism processing ends and the exception value is returned. 728 The possible qualifiers, and the results they return are as follows: 730 "+" pass 731 "-" fail 732 "~" softfail 733 "?" neutral 735 The qualifier is optional and defaults to "+". 737 When a mechanism matches and the qualifier is "-", then a "fail" 738 result is returned and the explanation string is computed as 739 described in Section 6.2. 741 The specific mechanisms are described in Section 5. 743 4.6.3. Modifiers 745 Modifiers are not mechanisms: they do not return match or not-match. 746 Instead they provide additional information. Although modifiers do 747 not directly affect the evaluation of the record, the "redirect" 748 modifier has an effect after all the mechanisms have been evaluated. 750 4.7. Default Result 752 If none of the mechanisms match and there is no "redirect" modifier, 753 then the check_host() returns a result of "neutral", just as if 754 "?all" were specified as the last directive. If there is a 755 "redirect" modifier, check_host() proceeds as defined in Section 6.1. 757 Note that records SHOULD always use either a "redirect" modifier or 758 an "all" mechanism to explicitly terminate processing. 760 For example: 762 v=spf1 +mx -all 763 or 764 v=spf1 +mx redirect=_spf.example.com 766 4.8. Domain Specification 768 Several of these mechanisms and modifiers have a domain-spec section. 769 The domain-spec string is macro expanded (see Section 8). The 770 resulting string is the common presentation form of a fully-qualified 771 DNS name: a series of labels separated by periods. This domain is 772 called the in the rest of this document. 774 Note: The result of the macro expansion is not subject to any further 775 escaping. Hence, this facility cannot produce all characters that 776 are legal in a DNS label (e.g., the control characters). However, 777 this facility is powerful enough to express legal host names and 778 common utility labels (such as "_spf") that are used in DNS. 780 For several mechanisms, the is optional. If it is not 781 provided, the is used as the . 783 5. Mechanism Definitions 785 This section defines two types of mechanisms. 787 Basic mechanisms contribute to the language framework. They do not 788 specify a particular type of authorization scheme. 790 all 791 include 793 Designated sender mechanisms are used to designate a set of 794 addresses as being permitted or not permitted to use the for 795 sending mail. 797 a 798 mx 799 ptr (deprecated) 800 ip4 801 ip6 802 exists 804 The following conventions apply to all mechanisms that perform a 805 comparison between and an IP address at any point: 807 If no CIDR-length is given in the directive, then and the IP 808 address are compared for equality. (Here, CIDR is Classless Inter- 809 Domain Routing.) 811 If a CIDR-length is specified, then only the specified number of 812 high-order bits of and the IP address are compared for equality. 814 When any mechanism fetches host addresses to compare with , when 815 is an IPv4 address, A records are fetched, when is an IPv6 816 address, AAAA records are fetched. Even if the SMTP connection is 817 via IPv6, an IPv4-mapped IPv6 IP address (see [RFC3513], Section 818 2.5.5) MUST still be considered an IPv4 address and MUST be evaluated 819 using IPv4 mechanisms (i.e. "ip4" and "a"). 821 Several mechanisms rely on information fetched from DNS. For these 822 DNS queries, except where noted, if the DNS server returns an error 823 (RCODE other than 0 or 3) or the query times out, the mechanism 824 throws the exception "temperror". If the server returns "domain does 825 not exist" (RCODE 3), then evaluation of the mechanism continues as 826 if the server returned no error (RCODE 0) and zero answer records. 828 5.1. "all" 830 all = "all" 831 The "all" mechanism is a test that always matches. It is used as the 832 rightmost mechanism in a record to provide an explicit default. 834 For example: 836 v=spf1 a mx -all 838 Mechanisms after "all" will never be tested. Any "redirect" modifier 839 (Section 6.1) has no effect when there is an "all" mechanism. 841 5.2. "include" 843 include = "include" ":" domain-spec 845 The "include" mechanism triggers a recursive evaluation of 846 check_host(). The domain-spec is expanded as per Section 8. Then 847 check_host() is evaluated with the resulting string as the . 848 The and arguments remain the same as in the current 849 evaluation of check_host(). 851 In hindsight, the name "include" was poorly chosen. Only the 852 evaluated result of the referenced SPF record is used, rather than 853 acting as if the referenced SPF record was literally included in the 854 first. For example, evaluating a "-all" directive in the referenced 855 record does not terminate the overall processing and does not 856 necessarily result in an overall "fail". (Better names for this 857 mechanism would have been "if-pass", "on-pass", etc.) 859 The "include" mechanism makes it possible for one domain to designate 860 multiple administratively-independent domains. For example, a vanity 861 domain "example.net" might send mail using the servers of 862 administratively-independent domains example.com and example.org. 864 Example.net could say 866 IN TXT "v=spf1 include:example.com include:example.org -all" 868 This would direct check_host() to, in effect, check the records of 869 example.com and example.org for a "pass" result. Only if the host 870 were not permitted for either of those domains would the result be 871 "fail". 873 Whether this mechanism matches, does not match, or throws an 874 exception depends on the result of the recursive evaluation of 875 check_host(): 877 +---------------------------------+---------------------------------+ 878 | A recursive check_host() result | Causes the "include" mechanism | 879 | of: | to: | 880 +---------------------------------+---------------------------------+ 881 | pass | match | 882 | | | 883 | fail | not match | 884 | | | 885 | softfail | not match | 886 | | | 887 | neutral | not match | 888 | | | 889 | temperror | throw temperror | 890 | | | 891 | permerror | throw permerror | 892 | | | 893 | none | throw permerror | 894 +---------------------------------+---------------------------------+ 896 The "include" mechanism is intended for crossing administrative 897 boundaries. Although it is possible to use includes to consolidate 898 multiple domains that share the same set of designated hosts, domains 899 are encouraged to use redirects where possible, and to minimize the 900 number of includes within a single administrative domain. For 901 example, if example.com and example.org were managed by the same 902 entity, and if the permitted set of hosts for both domains was 903 "mx:example.com", it would be possible for example.org to specify 904 "include:example.com", but it would be preferable to specify 905 "redirect=example.com" or even "mx:example.com". 907 5.3. "a" 909 This mechanism matches if is one of the 's IP 910 addresses. 912 A = "a" [ ":" domain-spec ] [ dual-cidr-length ] 914 An address lookup is done on the . The is compared 915 to the returned address(es). If any address matches, the mechanism 916 matches. 918 5.4. "mx" 920 This mechanism matches if is one of the MX hosts for a domain 921 name. 923 MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 924 check_host() first performs an MX lookup on the . Then 925 it performs an address lookup on each MX name returned. The is 926 compared to each returned IP address. To prevent Denial of Service 927 (DoS) attacks, more than 10 MX names MUST NOT be looked up during the 928 evaluation of an "mx" mechanism (see Section 10). If any address 929 matches, the mechanism matches. 931 Note regarding implicit MXs: If the has no MX records, 932 check_host() MUST NOT pretend the target is its single MX, and MUST 933 NOT default to an A lookup on the directly. This 934 behavior breaks with the legacy "implicit MX" rule. See [RFC5321], 935 Section 5. If such behavior is desired, the publisher should specify 936 an "a" directive. 938 5.5. "ptr" (deprecated) 940 This mechanism tests whether the DNS reverse-mapping for exists 941 and correctly points to a domain name within a particular domain. 942 This mechanism is deprecated and SHOULD NOT be used. 944 PTR = "ptr" [ ":" domain-spec ] 946 First, the 's name is looked up using this procedure: perform a 947 DNS reverse-mapping for , looking up the corresponding PTR record 948 in "in-addr.arpa." if the address is an IPv4 one and in "ip6.arpa." 949 if it is an IPv6 address. For each record returned, validate the 950 domain name by looking up its IP address. To prevent DoS attacks, 951 more than 10 PTR names MUST NOT be looked up during the evaluation of 952 a "ptr" mechanism (see Section 10). If is among the returned IP 953 addresses, then that domain name is validated. In pseudocode: 955 sending-domain_names := ptr_lookup(sending-host_IP); 956 if more than 10 sending-domain_names are found, use at most 10. 957 for each name in (sending-domain_names) { 958 IP_addresses := a_lookup(name); 959 if the sending-domain_IP is one of the IP_addresses { 960 validated-sending-domain_names += name; 961 } 962 } 964 Check all validated domain names to see if they end in the 965 domain. If any do, this mechanism matches. If no 966 validated domain name can be found, or if none of the validated 967 domain names end in the , this mechanism fails to match. 968 If a DNS error occurs while doing the PTR RR lookup, then this 969 mechanism fails to match. If a DNS error occurs while doing an A RR 970 lookup, then that domain name is skipped and the search continues. 972 Pseudocode: 974 for each name in (validated-sending-domain_names) { 975 if name ends in , return match. 976 if name is , return match. 977 } 978 return no-match. 980 This mechanism matches if the is either an ancestor of 981 a validated domain name or if the and a validated 982 domain name are the same. For example: "mail.example.com" is within 983 the domain "example.com", but "mail.bad-example.com" is not. 985 Note: This mechanism has been deprecated because it is slow, it is 986 not as reliable as other mechanisms in cases of DNS errors, and it 987 places a large burden on the arpa name servers. If used, proper PTR 988 records must be in place for the domain's hosts and the "ptr" 989 mechanism should be one of the last mechanisms checked. After many 990 yaers of SPF deployment experience it has been concluded it is 991 unnecessary and more reliable alternatives used instead. 993 5.6. "ip4" and "ip6" 995 These mechanisms test whether is contained within a given IP 996 network. 998 IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 999 IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 1001 ip4-cidr-length = "/" 1*DIGIT 1002 ip6-cidr-length = "/" 1*DIGIT 1003 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 1005 ip4-network = qnum "." qnum "." qnum "." qnum 1006 qnum = DIGIT ; 0-9 1007 / %x31-39 DIGIT ; 10-99 1008 / "1" 2DIGIT ; 100-199 1009 / "2" %x30-34 DIGIT ; 200-249 1010 / "25" %x30-35 ; 250-255 1011 ; as per conventional dotted quad notation. e.g., 192.0.2.0 1012 ip6-network = 1013 ; e.g., 2001:DB8::CD30 1015 The is compared to the given network. If CIDR-length high-order 1016 bits match, the mechanism matches. 1018 If ip4-cidr-length is omitted, it is taken to be "/32". If 1019 ip6-cidr-length is omitted, it is taken to be "/128". It is not 1020 permitted to omit parts of the IP address instead of using CIDR 1021 notations. That is, use 192.0.2.0/24 instead of 192.0.2. 1023 5.7. "exists" 1025 This mechanism is used to construct an arbitrary domain name that is 1026 used for a DNS A record query. It allows for complicated schemes 1027 involving arbitrary parts of the mail envelope to determine what is 1028 permitted. 1030 exists = "exists" ":" domain-spec 1032 The domain-spec is expanded as per Section 8. The resulting domain 1033 name is used for a DNS A RR lookup. If any A record is returned, 1034 this mechanism matches. The lookup type is A even when the 1035 connection type is IPv6. 1037 Domains can use this mechanism to specify arbitrarily complex 1038 queries. For example, suppose example.com publishes the record: 1040 v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all 1042 The might expand to 1043 "1.2.0.192.someuser._spf.example.com". This makes fine-grained 1044 decisions possible at the level of the user and client IP address. 1046 This mechanism enables queries that mimic the style of tests that 1047 existing anti-spam DNS blacklists (DNSBL) use. 1049 6. Modifier Definitions 1051 Modifiers are name/value pairs that provide additional information. 1052 Modifiers always have an "=" separating the name and the value. 1054 The modifiers defined in this document ("redirect" and "exp") MAY 1055 appear anywhere in the record, but SHOULD appear at the end, after 1056 all mechanisms. Ordering of these two modifiers does not matter. 1057 These two modifiers MUST NOT appear in a record more than once each. 1058 If they do, then check_host() exits with a result of "permerror". 1060 Unrecognized modifiers MUST be ignored no matter where in a record, 1061 or how often. This allows implementations of this document to 1062 gracefully handle records with modifiers that are defined in other 1063 specifications. 1065 6.1. redirect: Redirected Query 1067 If all mechanisms fail to match, and a "redirect" modifier is 1068 present, then processing proceeds as follows: 1070 redirect = "redirect" "=" domain-spec 1072 The domain-spec portion of the redirect section is expanded as per 1073 the macro rules in Section 8. Then check_host() is evaluated with 1074 the resulting string as the . The and 1075 arguments remain the same as in the current evaluation of 1076 check_host(). 1078 The result of this new evaluation of check_host() is then considered 1079 the result of the current evaluation with the exception that if no 1080 SPF record is found, or if the target-name is malformed, the result 1081 is a "permerror" rather than "none". 1083 Note that the newly-queried domain can itself specify redirect 1084 processing. 1086 This facility is intended for use by organizations that wish to apply 1087 the same record to multiple domains. For example: 1089 la.example.com. TXT "v=spf1 redirect=_spf.example.com" 1090 ny.example.com. TXT "v=spf1 redirect=_spf.example.com" 1091 sf.example.com. TXT "v=spf1 redirect=_spf.example.com" 1092 _spf.example.com. TXT "v=spf1 mx:example.com -all" 1094 In this example, mail from any of the three domains is described by 1095 the same record. This can be an administrative advantage. 1097 Note: In general, the domain "A" cannot reliably use a redirect to 1098 another domain "B" not under the same administrative control. Since 1099 the stays the same, there is no guarantee that the record at 1100 domain "B" will correctly work for mailboxes in domain "A", 1101 especially if domain "B" uses mechanisms involving localparts. An 1102 "include" directive is generally be more appropriate. 1104 For clarity, it is RECOMMENDED that any "redirect" modifier appear as 1105 the very last term in a record. 1107 6.2. exp: Explanation 1109 explanation = "exp" "=" domain-spec 1111 If check_host() results in a "fail" due to a mechanism match (such as 1112 "-all"), and the "exp" modifier is present, then the explanation 1113 string returned is computed as described below. If no "exp" modifier 1114 is present, then either a default explanation string or an empty 1115 explanation string MUST be returned. 1117 The domain-spec is macro expanded (see Section 8) and becomes the 1118 . The DNS TXT record for the is fetched. 1120 If there are any DNS processing errors (any RCODE other than 0), or 1121 if no records are returned, or if more than one record is returned, 1122 or if there are syntax errors in the explanation string, then proceed 1123 as if no exp modifier was given. 1125 The fetched TXT record's strings are concatenated with no spaces, and 1126 then treated as an explain-string, which is macro-expanded. This 1127 final result is the explanation string. Implementations MAY limit 1128 the length of the resulting explanation string to allow for other 1129 protocol constraints and/or reasonable processing limits. Since the 1130 explanation string is intended for an SMTP response and [RFC5321] 1131 Section 2.4 says that responses are in [US-ASCII], the explanation 1132 string is also limited to US-ASCII. 1134 Software evaluating check_host() can use this string to communicate 1135 information from the publishing domain in the form of a short message 1136 or URL. Software SHOULD make it clear that the explanation string 1137 comes from a third party. For example, it can prepend the macro 1138 string "%{o} explains: " to the explanation, such as shown in 1139 Section 2.5.4. 1141 Suppose example.com has this record: 1143 v=spf1 mx -all exp=explain._spf.%{d} 1145 Here are some examples of possible explanation TXT records at 1146 explain._spf.example.com: 1148 "Mail from example.com should only be sent by its own servers." 1149 -- a simple, constant message 1151 "%{i} is not one of %{d}'s designated mail servers." 1152 -- a message with a little more information, including the IP 1153 address that failed the check 1155 "See http://%{d}/why.html?s=%{S}&i=%{I}" 1156 -- a complicated example that constructs a URL with the 1157 arguments to check_host() so that a web page can be 1158 generated with detailed, custom instructions 1160 Note: During recursion into an "include" mechanism, an exp= modifier 1161 from the MUST NOT be used. In contrast, when executing 1162 a "redirect" modifier, an exp= modifier from the original domain MUST 1163 NOT be used. 1165 7. The Received-SPF Header Field 1167 It is RECOMMENDED that SMTP receivers record the result of SPF 1168 processing in the message header. If an SMTP receiver chooses to do 1169 so, it SHOULD use the "Received-SPF" header field defined here for 1170 each identity that was checked. This information is intended for the 1171 recipient. (Information intended for the sender is described in 1172 Section 6.2, Explanation.) 1174 The Received-SPF header field is a trace field (see [RFC5322] Section 1175 3.6.7) and SHOULD be prepended to the existing header, above the 1176 Received: field that is generated by the SMTP receiver. It MUST 1177 appear above all other Received-SPF fields in the message. The 1178 header field has the following format: 1180 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 1181 [ key-value-list ] CRLF 1183 result = "pass" / "fail" / "softfail" / "neutral" / 1184 "none" / "temperror" / "permerror" 1186 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 1187 [";"] 1189 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 1191 key = "client-ip" / "envelope-from" / "helo" / 1192 "problem" / "receiver" / "identity" / 1193 mechanism / name 1195 identity = "mailfrom" ; for the "MAIL FROM" identity 1196 / "helo" ; for the "HELO" identity 1197 / name ; other identities 1199 dot-atom = 1200 quoted-string = 1201 comment = 1202 CFWS = 1203 FWS = 1204 CRLF = 1206 The header field SHOULD include a "(...)" style comment after the 1207 result, conveying supporting information for the result, such as 1208 , , and . 1210 The following key-value pairs are designed for later machine parsing. 1211 SPF clients SHOULD give enough information so that the SPF results 1212 can be verified. That is, at least "client-ip", "helo", and, if the 1213 "MAIL FROM" identity was checked, "envelope-from". 1215 client-ip the IP address of the SMTP client 1217 envelope-from the envelope sender mailbox 1219 helo the host name given in the HELO or EHLO command 1221 mechanism the mechanism that matched (if no mechanisms matched, 1222 substitute the word "default") 1224 problem if an error was returned, details about the error 1226 receiver the host name of the SPF client 1228 identity the identity that was checked; see the ABNF 1229 rule 1231 Other keys MAY be defined by SPF clients. 1233 SPF clients MUST make sure that the Received-SPF header field does 1234 not contain invalid characters, is not excessively long, and does not 1235 contain malicious data that has been provided by the sender. 1237 Examples of various header styles that could be generated are the 1238 following: 1240 Received-SPF: pass (mybox.example.org: domain of 1241 myname@example.com designates 192.0.2.1 as permitted sender) 1242 receiver=mybox.example.org; client-ip=192.0.2.1; 1243 envelope-from="myname@example.com"; helo=foo.example.com; 1245 Received-SPF: fail (mybox.example.org: domain of 1246 myname@example.com does not designate 1247 192.0.2.1 as permitted sender) 1248 identity=mailfrom; client-ip=192.0.2.1; 1249 envelope-from="myname@example.com"; 1251 8. Macros 1253 8.1. Macro Definitions 1255 Many mechanisms and modifiers perform macro expansion on the term. 1257 domain-spec = macro-string domain-end 1258 domain-end = ( "." toplabel [ "." ] ) / macro-expand 1260 toplabel = ( *alphanum ALPHA *alphanum ) / 1261 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 1262 ; LDH rule plus additional TLD restrictions 1263 ; (see [RFC3696], Section 2) 1264 alphanum = ALPHA / DIGIT 1266 explain-string = *( macro-string / SP ) 1268 macro-string = *( macro-expand / macro-literal ) 1269 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 1270 / "%%" / "%_" / "%-" 1271 macro-literal = %x21-24 / %x26-7E 1272 ; visible characters except "%" 1273 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 1274 "c" / "r" / "t" / "v" 1275 transformers = *DIGIT [ "r" ] 1276 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 1278 A literal "%" is expressed by "%%". 1280 "%_" expands to a single " " space. 1281 "%-" expands to a URL-encoded space, viz., "%20". 1283 The following macro letters are expanded in term arguments: 1285 s = 1286 l = local-part of 1287 o = domain of 1288 d = 1289 i = 1290 i p = the validated domain name of (deprecated) 1291 v = the string "in-addr" if is ipv4, or "ip6" if is ipv6 1292 h = HELO/EHLO domain 1294 The following macro letters are allowed only in "exp" text: 1296 c = SMTP client IP (easily readable format) 1297 r = domain name of host performing the check 1298 t = current timestamp 1300 A '%' character not followed by a '{', '%', '-', or '_' character is 1301 a syntax error. So 1302 -exists:%(ir).sbl.spamhaus.example.org 1303 is incorrect and will cause check_host() to return a "permerror". 1304 Instead, say 1305 -exists:%{ir}.sbl.spamhaus.example.org 1307 Optional transformers are the following: 1309 *DIGIT = zero or more digits 1310 'r' = reverse value, splitting on dots by default 1312 If transformers or delimiters are provided, the replacement value for 1313 a macro letter is split into parts. After performing any reversal 1314 operation and/or removal of left-hand parts, the parts are rejoined 1315 using "." and not the original splitting characters. 1317 By default, strings are split on "." (dots). Note that no special 1318 treatment is given to leading, trailing, or consecutive delimiters, 1319 and so the list of parts might contain empty strings. Older 1320 implementations of SPF prohibit trailing dots in domain names, so 1321 trailing dots should not be published by domain owners, although they 1322 must be accepted by implementations conforming to this document. 1323 Macros MAY specify delimiter characters that are used instead of ".". 1325 The 'r' transformer indicates a reversal operation: if the client IP 1326 address were 192.0.2.1, the macro %{i} would expand to "192.0.2.1" 1327 and the macro %{ir} would expand to "1.2.0.192". 1329 The DIGIT transformer indicates the number of right-hand parts to 1330 use, after optional reversal. If a DIGIT is specified, the value 1331 MUST be nonzero. If no DIGITs are specified, or if the value 1332 specifies more parts than are available, all the available parts are 1333 used. If the DIGIT was 5, and only 3 parts were available, the macro 1334 interpreter would pretend the DIGIT was 3. Implementations MUST 1335 support at least a value of 128, as that is the maximum number of 1336 labels in a domain name. 1338 The "s" macro expands to the argument. It is an email 1339 address with a localpart, an "@" character, and a domain. The "l" 1340 macro expands to just the localpart. The "o" macro expands to just 1341 the domain part. Note that these values remain the same during 1342 recursive and chained evaluations due to "include" and/or "redirect". 1343 Note also that if the original had no localpart, the 1344 localpart was set to "postmaster" in initial processing (see 1345 Section 4.3). 1347 For IPv4 addresses, both the "i" and "c" macros expand to the 1348 standard dotted-quad format. 1350 For IPv6 addresses, the "i" macro expands to a dot-format address; it 1351 is intended for use in %{ir}. The "c" macro MAY expand to any of the 1352 hexadecimal colon-format addresses specified in [RFC3513], Section 1353 2.2. It is intended for humans to read. 1355 The "p" macro expands to the validated domain name of . The 1356 procedure for finding the validated domain name is defined in 1357 Section 5.5. If the is present in the list of validated 1358 domains, it SHOULD be used. Otherwise, if a subdomain of the 1359 is present, it SHOULD be used. Otherwise, any name from the 1360 list MAY be used. If there are no validated domain names or if a DNS 1361 error occurs, the string "unknown" is used. This macro is deprecated 1362 and SHOULD NOT be used. 1364 The "r" macro expands to the name of the receiving MTA. This SHOULD 1365 be a fully qualified domain name, but if one does not exist (as when 1366 the checking is done by a MUA) or if policy restrictions dictate 1367 otherwise, the word "unknown" SHOULD be substituted. The domain name 1368 can be different from the name found in the MX record that the client 1369 MTA used to locate the receiving MTA. 1371 The "t" macro expands to the decimal representation of the 1372 approximate number of seconds since the Epoch (Midnight, January 1, 1373 1970, UTC). This is the same value as is returned by the POSIX 1374 time() function in most standards-compliant libraries. 1376 When the result of macro expansion is used in a domain name query, if 1377 the expanded domain name exceeds 253 characters (the maximum length 1378 of a domain name), the left side is truncated to fit, by removing 1379 successive domain labels until the total length does not exceed 253 1380 characters. 1382 Uppercased macros expand exactly as their lowercased equivalents, and 1383 are then URL escaped. URL escaping must be performed for characters 1384 not in the "unreserved" set, which is defined in [RFC3986]. 1386 Note: Care must be taken so that macro expansion for legitimate email 1387 does not exceed the 63-character limit on DNS labels. The localpart 1388 of email addresses, in particular, can have more than 63 characters 1389 between dots. 1391 Note: Domains should avoid using the "s", "l", "o", or "h" macros in 1392 conjunction with any mechanism directive. Although these macros are 1393 powerful and allow per-user records to be published, they severely 1394 limit the ability of implementations to cache results of check_host() 1395 and they reduce the effectiveness of DNS caches. 1397 Implementations should be aware that if no directive processed during 1398 the evaluation of check_host() contains an "s", "l", "o", or "h" 1399 macro, then the results of the evaluation can be cached on the basis 1400 of and alone for as long as the shortest Time To Live 1401 (TTL) of all the DNS records involved. 1403 8.2. Expansion Examples 1405 The is strong-bad@email.example.com. 1406 The IPv4 SMTP client IP is 192.0.2.3. 1407 The IPv6 SMTP client IP is 2001:DB8::CB01. 1408 The PTR domain name of the client IP is mx.example.org. 1410 macro expansion 1411 ------- ---------------------------- 1412 %{s} strong-bad@email.example.com 1413 %{o} email.example.com 1414 %{d} email.example.com 1415 %{d4} email.example.com 1416 %{d3} email.example.com 1417 %{d2} example.com 1418 %{d1} com 1419 %{dr} com.example.email 1420 %{d2r} example.email 1421 %{l} strong-bad 1422 %{l-} strong.bad 1423 %{lr} strong-bad 1424 %{lr-} bad.strong 1425 %{l1r-} strong 1427 macro-string expansion 1428 -------------------------------------------------------------------- 1429 %{ir}.%{v}._spf.%{d2} 3.2.0.192.in-addr._spf.example.com 1430 %{lr-}.lp._spf.%{d2} bad.strong.lp._spf.example.com 1432 %{lr-}.lp.%{ir}.%{v}._spf.%{d2} 1433 bad.strong.lp.3.2.0.192.in-addr._spf.example.com 1435 %{ir}.%{v}.%{l1r-}.lp._spf.%{d2} 1436 3.2.0.192.in-addr.strong.lp._spf.example.com 1438 %{d2}.trusted-domains.example.net 1439 example.com.trusted-domains.example.net 1441 IPv6: 1442 %{ir}.%{v}._spf.%{d2} 1.0.B.C.0.0.0.0. 1443 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 1445 9. Implications 1447 This section outlines the major implications that adoption of this 1448 document will have on various entities involved in Internet email. 1449 It is intended to make clear to the reader where this document 1450 knowingly affects the operation of such entities. This section is 1451 not a "how-to" manual, or a "best practices" document, and it is not 1452 a comprehensive list of what such entities should do in light of this 1453 document. 1455 This section is non-normative. 1457 9.1. Sending Domains 1459 Domains that wish to be compliant with this specification will need 1460 to determine the list of hosts that they allow to use their domain 1461 name in the "HELO" and "MAIL FROM" identities. It is recognized that 1462 forming such a list is not just a simple technical exercise, but 1463 involves policy decisions with both technical and administrative 1464 considerations. 1466 It can be helpful to publish records that include a "tracking 1467 exists:" mechanism. By looking at the name server logs, a rough list 1468 can then be generated. For example: 1470 v=spf1 exists:_h.%{h}._l.%{l}._o.%{o}._i.%{i}._spf.%{d} ?all 1472 9.2. Mailing Lists 1474 Mailing lists must be aware of how they re-inject mail that is sent 1475 to the list. Mailing lists MUST comply with the requirements in 1476 [RFC5321], Section 3.10, and [RFC1123], Section 5.3.6, that say that 1477 the reverse-path MUST be changed to be the mailbox of a person or 1478 other entity who administers the list. Whereas the reasons for 1479 changing the reverse-path are many and long-standing, SPF adds 1480 enforcement to this requirement. 1482 In practice, almost all mailing list software in use already complies 1483 with this requirement. Mailing lists that do not comply might 1484 encounter problems depending on how access to the list is restricted. 1485 Such lists that are entirely internal to a domain (only people in the 1486 domain can send to or receive from the list) are not affected. 1488 9.3. Forwarding Services and Aliases 1490 Forwarding services take mail that is received at a mailbox and 1491 direct it to some external mailbox. At the time of this writing, the 1492 near-universal practice of such services is to use the original "MAIL 1493 FROM" of a message when re-injecting it for delivery to the external 1494 mailbox. [RFC1123] and [RFC5321] describe this action as an "alias" 1495 rather than a "mail list". This means that the external mailbox's 1496 MTA sees all such mail in a connection from a host of the forwarding 1497 service, and so the "MAIL FROM" identity will not, in general, pass 1498 authorization. 1500 There are three places that techniques can be used to ameliorate this 1501 problem. 1503 1. The beginning, when email is first sent. 1505 1. "Neutral" results could be given for IP addresses that might 1506 be forwarders, instead of "fail" results. For example: 1508 "v=spf1 mx -exists:%{ir}.sbl.spamhaus.example.org ?all" 1510 This would cause a lookup on an anti-spam DNS blacklist 1511 (DNSBL) and cause a result of "fail" only for email coming 1512 from listed sources. All other email, including email sent 1513 through forwarders, would receive a "neutral" result. By 1514 checking the DNSBL after the known good sources, problems 1515 with incorrect listing on the DNSBL are greatly reduced. 1517 2. The "MAIL FROM" identity could have additional information in 1518 the localpart that cryptographically identifies the mail as 1519 coming from an authorized source. In this case, such an SPF 1520 record could be used: 1522 "v=spf1 mx exists:%{l}._spf_verify.%{d} -all" 1524 Then, a specialized DNS server can be set up to serve the 1525 _spf_verify subdomain that validates the localpart. Although 1526 this requires an extra DNS lookup, this happens only when the 1527 email would otherwise be rejected as not coming from a known 1528 good source. 1529 Note that due to the 63-character limit for domain labels, 1530 this approach only works reliably if the localpart signature 1531 scheme is guaranteed either to only produce localparts with a 1532 maximum of 63 characters or to gracefully handle truncated 1533 localparts. 1535 3. Similarly, a specialized DNS server could be set up that will 1536 rate-limit the email coming from unexpected IP addresses. 1538 "v=spf1 mx exists:%{ir}._spf_rate.%{d} -all" 1540 4. SPF allows the creation of per-user policies for special 1541 cases. For example, the following SPF record and appropriate 1542 wildcard DNS records can be used: 1544 "v=spf1 mx redirect=%{l1r+}._at_.%{o}._spf.%{d}" 1546 2. The middle, when email is forwarded. 1548 1. Forwarding services can solve the problem by rewriting the 1549 "MAIL FROM" to be in their own domain. This means that mail 1550 rejected from the external mailbox will have to be forwarded 1551 back to the original sender by the forwarding service. 1552 Various schemes to do this exist though they vary widely in 1553 complexity and resource requirements on the part of the 1554 forwarding service. 1556 2. Several popular MTAs can be forced from "alias" semantics to 1557 "mailing list" semantics by configuring an additional alias 1558 with "owner-" prepended to the original alias name (e.g., an 1559 alias of "friends: george@example.com, fred@example.org" 1560 would need another alias of the form "owner-friends: 1561 localowner"). 1563 3. The end, when email is received. 1565 1. If the owner of the external mailbox wishes to trust the 1566 forwarding service, he can direct the external mailbox's MTA 1567 to skip SPF tests when the client host belongs to the 1568 forwarding service. 1570 2. Tests against other identities, such as the "HELO" identity, 1571 MAY be used to override a failed test against the "MAIL FROM" 1572 identity. 1574 3. For larger domains, it might not be possible to have a 1575 complete or accurate list of forwarding services used by the 1576 owners of the domain's mailboxes. In such cases, whitelists 1577 of generally-recognized forwarding services could be 1578 employed. 1580 9.4. Mail Services 1582 Service providers that offer mail services to third-party domains, 1583 such as sending of bulk mail, might want to adjust their setup in 1584 light of the authorization check described in this document. If the 1585 "MAIL FROM" identity used for such email uses the domain of the 1586 service provider, then the provider needs only to ensure that its 1587 sending host is authorized by its own SPF record, if any. 1589 If the "MAIL FROM" identity does not use the mail service provider's 1590 domain, then extra care must be taken. The SPF record format has 1591 several options for the third-party domain to authorize the service 1592 provider's MTAs to send mail on its behalf. For mail service 1593 providers, such as ISPs, that have a wide variety of customers using 1594 the same MTA, steps should be taken to prevent cross-customer forgery 1595 (see Section 10.4). 1597 9.5. MTA Relays 1599 The authorization check generally precludes the use of arbitrary MTA 1600 relays between sender and receiver of an email message. 1602 Within an organization, MTA relays can be effectively deployed. 1603 However, for purposes of this document, such relays are effectively 1604 transparent. The SPF authorization check is a check between border 1605 MTAs of different domains. 1607 For mail senders, this means that published SPF records must 1608 authorize any MTAs that actually send across the Internet. Usually, 1609 these are just the border MTAs as internal MTAs simply forward mail 1610 to these MTAs for delivery. 1612 Mail receivers will generally want to perform the authorization check 1613 at the border MTAs, specifically including all secondary MXs. This 1614 allows mail that fails to be rejected during the SMTP session rather 1615 than sending a failure report. Internal MTAs then do not perform the 1616 authorization test. To perform the authorization test other than at 1617 the border, the host that first transferred the message to the 1618 organization must be determined, which can be difficult to extract 1619 from the message header. Testing other than at the border is not 1620 recommended. 1622 10. Security Considerations 1624 10.1. Processing Limits 1626 As with most aspects of email, there are a number of ways that 1627 malicious parties could use the protocol as an avenue for a 1628 Denial-of-Service (DoS) attack. The processing limits outlined here 1629 are designed to prevent attacks such as the following: 1631 o A malicious party could create an SPF record with many references 1632 to a victim's domain and send many emails to different SPF 1633 clients; those SPF clients would then create a DoS attack. In 1634 effect, the SPF clients are being used to amplify the attacker's 1635 bandwidth by using fewer bytes in the SMTP session than are used 1636 by the DNS queries. Using SPF clients also allows the attacker to 1637 hide the true source of the attack. 1639 o Whereas implementations of check_host() are supposed to limit the 1640 number of DNS lookups, malicious domains could publish records 1641 that exceed these limits in an attempt to waste computation effort 1642 at their targets when they send them mail. Malicious domains 1643 could also design SPF records that cause particular 1644 implementations to use excessive memory or CPU usage, or to 1645 trigger bugs. 1647 o Malicious parties could send a large volume of mail purporting to 1648 come from the intended target to a wide variety of legitimate mail 1649 hosts. These legitimate machines would then present a DNS load on 1650 the target as they fetched the relevant records. 1652 Of these, the case of a third party referenced in the SPF record is 1653 the easiest for a DoS attack to effectively exploit. As a result, 1654 limits that might seem reasonable for an individual mail server can 1655 still allow an unreasonable amount of bandwidth amplification. 1656 Therefore, the processing limits need to be quite low. 1658 SPF implementations MUST limit the number of mechanisms and modifiers 1659 that do DNS lookups to at most 10 per SPF check, including any 1660 lookups caused by the use of the "include" mechanism or the 1661 "redirect" modifier. If this number is exceeded during a check, a 1662 permerror MUST be returned. The "include", "a", "mx", "ptr", and 1663 "exists" mechanisms as well as the "redirect" modifier do count 1664 against this limit. The "all", "ip4", and "ip6" mechanisms do not 1665 require DNS lookups and therefore do not count against this limit. 1666 The "exp" modifier does not count against this limit because the DNS 1667 lookup to fetch the explanation string occurs after the SPF record 1668 has been evaluated. 1670 When evaluating the "mx" and "ptr" mechanisms, or the %{p} macro, 1671 there MUST be a limit of no more than 10 MX or PTR RRs looked up and 1672 checked. If more than 10 "mx" or "ptr" records are returned for this 1673 further lookup, a permerror MUST be returned. 1675 SPF implementations SHOULD limit the total amount of data obtained 1676 from the DNS queries. For example, when DNS over TCP or EDNS0 are 1677 available, there might need to be an explicit limit to how much data 1678 will be accepted to prevent excessive bandwidth usage or memory usage 1679 and DoS attacks. 1681 MTAs or other processors MAY also impose a limit on the maximum 1682 amount of elapsed time to evaluate check_host(). Such a limit SHOULD 1683 allow at least 20 seconds. If such a limit is exceeded, the result 1684 of authorization SHOULD be "temperror". 1686 Domains publishing records SHOULD try to keep the number of "include" 1687 mechanisms and chained "redirect" modifiers to a minimum. Domains 1688 SHOULD also try to minimize the amount of other DNS information 1689 needed to evaluate a record. This can be done by choosing directives 1690 that require less DNS information and placing lower-cost mechanisms 1691 earlier in the SPF record. 1693 For example, consider a domain set up as follows: 1695 example.com. IN MX 10 mx.example.com. 1696 mx.example.com. IN A 192.0.2.1 1697 a.example.com. IN TXT "v=spf1 mx:example.com -all" 1698 b.example.com. IN TXT "v=spf1 a:mx.example.com -all" 1699 c.example.com. IN TXT "v=spf1 ip4:192.0.2.1 -all" 1701 Evaluating check_host() for the domain "a.example.com" requires the 1702 MX records for "example.com", and then the A records for the listed 1703 hosts. Evaluating for "b.example.com" requires only the A records. 1704 Evaluating for "c.example.com" requires none. 1706 However, there might be administrative considerations: using "a" over 1707 "ip4" allows hosts to be renumbered easily. Using "mx" over "a" 1708 allows the set of mail hosts to be changed easily. 1710 10.2. SPF-Authorized Email May Contain Other False Identities 1712 The "MAIL FROM" and "HELO" identity authorizations must not be 1713 construed to provide more assurance than they do. It is entirely 1714 possible for a malicious sender to inject a message using his own 1715 domain in the identities used by SPF, to have that domain's SPF 1716 record authorize the sending host, and yet the message can easily 1717 list other identities in its header. Unless the user or the MUA 1718 takes care to note that the authorized identity does not match the 1719 other more commonly-presented identities (such as the From: header 1720 field), the user might be lulled into a false sense of security. 1722 10.3. Spoofed DNS and IP Data 1724 There are two aspects of this protocol that malicious parties could 1725 exploit to undermine the validity of the check_host() function: 1727 o The evaluation of check_host() relies heavily on DNS. A malicious 1728 attacker could attack the DNS infrastructure and cause 1729 check_host() to see spoofed DNS data, and then return incorrect 1730 results. This could include returning "pass" for an value 1731 where the actual domain's record would evaluate to "fail". See 1732 [RFC3833] for a description of DNS weaknesses. 1734 o The client IP address, , is assumed to be correct. A 1735 malicious attacker could spoof TCP sequence numbers to make mail 1736 appear to come from a permitted host for a domain that the 1737 attacker is impersonating. 1739 10.4. Cross-User Forgery 1741 By definition, SPF policies just map domain names to sets of 1742 authorized MTAs, not whole email addresses to sets of authorized 1743 users. Although the "l" macro (Section 8) provides a limited way to 1744 define individual sets of authorized MTAs for specific email 1745 addresses, it is generally impossible to verify, through SPF, the use 1746 of specific email addresses by individual users of the same MTA. 1748 It is up to mail services and their MTAs to directly prevent 1749 cross-user forgery: based on SMTP AUTH ([RFC2554]), users should be 1750 restricted to using only those email addresses that are actually 1751 under their control (see [RFC4409], Section 6.1). Another means to 1752 verify the identity of individual users is message cryptography such 1753 as PGP ([RFC2440]) or S/MIME ([RFC3851]). 1755 10.5. Untrusted Information Sources 1757 An SPF compliant receiver gathers information from the SMTP commands 1758 it receives and from the published DNS records of the sending domain 1759 holder, (e.g., "HELO" domain name, the "MAIL FROM" address from the 1760 envelope, and SPF DNS records published by the domain holder). 1762 This information, passed to the receiver in the Received-SPF: trace 1763 fields, may be returned to the client MTA as an SMTP rejection 1764 message. If such an SMTP rejection message is generated, the 1765 information from the trace fields must be checked for such problems 1766 as invalid characters and excessively long lines. 1768 When the authorization check fails, an explanation string could be 1769 included in the reject response. Both the sender and the rejecting 1770 receiver need to be aware that the explanation was determined by the 1771 publisher of the SPF record checked and, in general, not the 1772 receiver. The explanation can contain malicious URLs, or it might be 1773 offensive or misleading. 1775 Explanations returned to sender domains due to exp modifiers, 1776 (Section 6.2), were generated by the sender policy published by the 1777 domain holders themselves. As long as messages are only returned 1778 with non-delivery notification to domains publishing the explanation 1779 strings from their own DNS SPF records, the only affected parties are 1780 the original publishers of the domain's SPF records. 1782 In practice, such non-delivery notifications can be misdirected, such 1783 as when an MTA accepts an email and only later generates the 1784 notification to a forged address, or when an email forwarder does not 1785 direct the bounce back to the original sender. 1787 10.6. Privacy Exposure 1789 Checking SPF records causes DNS queries to be sent to the domain 1790 owner. These DNS queries, especially if they are caused by the 1791 "exists" mechanism, can contain information about who is sending 1792 email and likely to which MTA the email is being sent. This can 1793 introduce some privacy concerns, which are more or less of an issue 1794 depending on local laws and the relationship between the domain owner 1795 and the person sending the email. 1797 11. Contributors and Acknowledgements 1799 This document is largely based on the work of Meng Weng Wong, Mark 1800 Lentczner, and Wayne Schlitt. Although, as this section 1801 acknowledges, many people have contributed to this document, a very 1802 large portion of the writing and editing are due to Meng, Mark, and 1803 Wayne. 1805 This design owes a debt of parentage to [RMX] by Hadmut Danisch and 1806 to [DMP] by Gordon Fecyk. The idea of using a DNS record to check 1807 the legitimacy of an email address traces its ancestry further back 1808 through messages on the namedroppers mailing list by Paul Vixie 1809 [Vixie] (based on suggestion by Jim Miller) and by David Green 1810 [Green]. 1812 Philip Gladstone contributed the concept of macros to the 1813 specification, multiplying the expressiveness of the language and 1814 making per-user and per-IP lookups possible. 1816 The authors of bothe this document and [RFC4408] would also like to 1817 thank the literally hundreds of individuals who have participated in 1818 the development of this design. They are far too numerous to name, 1819 but they include the following: 1821 The participants in the SPFbis working group. 1822 The folks on the spf-discuss mailing list. 1823 The folks on the SPAM-L mailing list. 1824 The folks on the IRTF ASRG mailing list. 1825 The folks on the IETF MARID mailing list. 1826 The folks on #perl. 1828 12. IANA Considerations 1830 12.1. The SPF DNS Record Type 1832 Per [RFC4408], the IANA assigned the Resource Record Type and Qtype 1833 from the DNS Parameters Registry for the SPF RR type with code 99. 1835 12.2. The Received-SPF Mail Header Field 1837 Per [RFC3864], the "Received-SPF:" header field is added to the IANA 1838 Permanent Message Header Field Registry. The following is the 1839 registration template: 1841 Header field name: Received-SPF 1842 Applicable protocol: mail ([RFC5322]) 1843 Status: Standards Track 1844 Author/Change controller: IETF 1845 Specification document(s): [RFC4408], RFC XXXX 1847 13. References 1849 13.1. Normative References 1851 [RFC1035] Mockapetris, P., "Domain names - implementation and 1852 specification", STD 13, RFC 1035, November 1987. 1854 [RFC1123] Braden, R., "Requirements for Internet Hosts - Application 1855 and Support", STD 3, RFC 1123, October 1989. 1857 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1858 Requirement Levels", BCP 14, RFC 2119, March 1997. 1860 [RFC3463] Vaudreuil, G., "Enhanced Mail System Status Codes", 1861 RFC 3463, January 2003. 1863 [RFC3513] Hinden, R. and S. Deering, "Internet Protocol Version 6 1864 (IPv6) Addressing Architecture", RFC 3513, April 2003. 1866 [RFC3864] Klyne, G., Nottingham, M., and J. Mogul, "Registration 1867 Procedures for Message Header Fields", BCP 90, RFC 3864, 1868 September 2004. 1870 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1871 Resource Identifier (URI): Generic Syntax", STD 66, 1872 RFC 3986, January 2005. 1874 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 1875 Specifications: ABNF", STD 68, RFC 5234, January 2008. 1877 [RFC5321] Klensin, J., "Simple Mail Transfer Protocol", RFC 5321, 1878 October 2008. 1880 [RFC5322] Resnick, P., Ed., "Internet Message Format", RFC 5322, 1881 October 2008. 1883 [US-ASCII] 1884 American National Standards Institute (formerly United 1885 States of America Standards Institute), "USA Code for 1886 Information Interchange, X3.4", 1968. 1888 ANSI X3.4-1968 has been replaced by newer versions with 1889 slight modifications, but the 1968 version remains 1890 definitive for the Internet. 1892 13.2. Informative References 1894 [DMP] Fecyk, G., "Designated Mailers Protocol". 1896 Work In Progress 1898 [Green] Green, D., "Domain-Authorized SMTP Mail", 2002. 1900 [RFC1034] Mockapetris, P., "Domain names - concepts and facilities", 1901 STD 13, RFC 1034, November 1987. 1903 [RFC1983] Malkin, G., "Internet Users' Glossary", RFC 1983, 1904 August 1996. 1906 [RFC2440] Callas, J., Donnerhacke, L., Finney, H., and R. Thayer, 1907 "OpenPGP Message Format", RFC 2440, November 1998. 1909 [RFC2554] Myers, J., "SMTP Service Extension for Authentication", 1910 RFC 2554, March 1999. 1912 [RFC3696] Klensin, J., "Application Techniques for Checking and 1913 Transformation of Names", RFC 3696, February 2004. 1915 [RFC3833] Atkins, D. and R. Austein, "Threat Analysis of the Domain 1916 Name System (DNS)", RFC 3833, August 2004. 1918 [RFC3851] Ramsdell, B., "Secure/Multipurpose Internet Mail 1919 Extensions (S/MIME) Version 3.1 Message Specification", 1920 RFC 3851, July 2004. 1922 [RFC4408] Wong, M. and W. Schlitt, "Sender Policy Framework (SPF) 1923 for Authorizing Use of Domains in E-Mail, Version 1", 1924 RFC 4408, April 2006. 1926 [RFC4409] Gellens, R. and J. Klensin, "Message Submission for Mail", 1927 RFC 4409, April 2006. 1929 [RFC5598] Crocker, D., "Internet Mail Architecture", RFC 5598, 1930 July 2009. 1932 [RMX] Danisch, H., "The RMX DNS RR Type for light weight sender 1933 authentication". 1935 Work In Progress 1937 [Vixie] Vixie, P., "Repudiating MAIL FROM", 2002. 1939 Appendix A. Collected ABNF 1941 This section is normative and any discrepancies with the ABNF 1942 fragments in the preceding text are to be resolved in favor of this 1943 grammar. 1945 See [RFC5234] for ABNF notation. Please note that as per this ABNF 1946 definition, literal text strings (those in quotes) are case- 1947 insensitive. Hence, "mx" matches "mx", "MX", "mX", and "Mx". 1949 record = version terms *SP 1950 version = "v=spf1" 1952 terms = *( 1*SP ( directive / modifier ) ) 1954 directive = [ qualifier ] mechanism 1955 qualifier = "+" / "-" / "?" / "~" 1956 mechanism = ( all / include 1957 / A / MX / PTR / IP4 / IP6 / exists ) 1959 all = "all" 1960 include = "include" ":" domain-spec 1961 A = "a" [ ":" domain-spec ] [ dual-cidr-length ] 1962 MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 1963 PTR = "ptr" [ ":" domain-spec ] 1964 IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 1965 IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 1966 exists = "exists" ":" domain-spec 1968 modifier = redirect / explanation / unknown-modifier 1969 redirect = "redirect" "=" domain-spec 1970 explanation = "exp" "=" domain-spec 1971 unknown-modifier = name "=" macro-string 1972 ; where name is not any known modifier 1974 ip4-cidr-length = "/" 1*DIGIT 1975 ip6-cidr-length = "/" 1*DIGIT 1976 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 1978 ip4-network = qnum "." qnum "." qnum "." qnum 1979 qnum = DIGIT ; 0-9 1980 / %x31-39 DIGIT ; 10-99 1981 / "1" 2DIGIT ; 100-199 1982 / "2" %x30-34 DIGIT ; 200-249 1983 / "25" %x30-35 ; 250-255 1984 ; conventional dotted quad notation. e.g., 192.0.2.0 1985 ip6-network = 1986 ; e.g., 2001:DB8::CD30 1988 domain-spec = macro-string domain-end 1989 domain-end = ( "." toplabel [ "." ] ) / macro-expand 1991 toplabel = ( *alphanum ALPHA *alphanum ) / 1992 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 1993 ; LDH rule plus additional TLD restrictions 1994 ; (see [RFC3696], Section 2) 1995 alphanum = ALPHA / DIGIT 1997 explain-string = *( macro-string / SP ) 1999 macro-string = *( macro-expand / macro-literal ) 2000 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 2001 / "%%" / "%_" / "%-" 2002 macro-literal = %x21-24 / %x26-7E 2003 ; visible characters except "%" 2004 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 2005 "c" / "r" / "t" / "v" 2006 transformers = *DIGIT [ "r" ] 2007 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 2009 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 2011 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 2012 [ key-value-list ] CRLF 2014 result = "pass" / "fail" / "softfail" / "neutral" / 2015 "none" / "temperror" / "permerror" 2017 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 2018 [";"] 2020 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 2022 key = "client-ip" / "envelope-from" / "helo" / 2023 "problem" / "receiver" / "identity" / 2024 mechanism / name 2026 identity = "mailfrom" ; for the "MAIL FROM" identity 2027 / "helo" ; for the "HELO" identity 2028 / name ; other identities 2030 dot-atom = 2031 quoted-string = 2032 comment = 2033 CFWS = 2034 FWS = 2035 CRLF = 2037 Appendix B. Extended Examples 2039 These examples are based on the following DNS setup: 2041 ; A domain with two mail servers, two hosts 2042 ; and two servers at the domain name 2043 $ORIGIN example.com. 2044 @ MX 10 mail-a 2045 MX 20 mail-b 2046 A 192.0.2.10 2047 A 192.0.2.11 2048 amy A 192.0.2.65 2049 bob A 192.0.2.66 2050 mail-a A 192.0.2.129 2051 mail-b A 192.0.2.130 2052 www CNAME example.com. 2054 ; A related domain 2055 $ORIGIN example.org. 2056 @ MX 10 mail-c 2057 mail-c A 192.0.2.140 2059 ; The reverse IP for those addresses 2060 $ORIGIN 2.0.192.in-addr.arpa. 2061 10 PTR example.com. 2062 11 PTR example.com. 2063 65 PTR amy.example.com. 2064 66 PTR bob.example.com. 2065 129 PTR mail-a.example.com. 2066 130 PTR mail-b.example.com. 2067 140 PTR mail-c.example.org. 2069 ; A rogue reverse IP domain that claims to be 2070 ; something it's not 2071 $ORIGIN 0.0.10.in-addr.arpa. 2072 4 PTR bob.example.com. 2074 B.1. Simple Examples 2076 These examples show various possible published records for 2077 example.com and which values if would cause check_host() to 2078 return "pass". Note that is "example.com". 2080 v=spf1 +all 2081 -- any passes 2083 v=spf1 a -all 2084 -- hosts 192.0.2.10 and 192.0.2.11 pass 2086 v=spf1 a:example.org -all 2087 -- no sending hosts pass since example.org has no A records 2089 v=spf1 mx -all 2090 -- sending hosts 192.0.2.129 and 192.0.2.130 pass 2092 v=spf1 mx:example.org -all 2093 -- sending host 192.0.2.140 passes 2095 v=spf1 mx mx:example.org -all 2096 -- sending hosts 192.0.2.129, 192.0.2.130, and 192.0.2.140 pass 2098 v=spf1 mx/30 mx:example.org/30 -all 2099 -- any sending host in 192.0.2.128/30 or 192.0.2.140/30 passes 2101 v=spf1 ptr -all 2102 -- sending host 192.0.2.65 passes (reverse DNS is valid and is in 2103 example.com) 2104 -- sending host 192.0.2.140 fails (reverse DNS is valid, but not 2105 in example.com) 2106 -- sending host 10.0.0.4 fails (reverse IP is not valid) 2108 v=spf1 ip4:192.0.2.128/28 -all 2109 -- sending host 192.0.2.65 fails 2110 -- sending host 192.0.2.129 passes 2112 B.2. Multiple Domain Example 2114 These examples show the effect of related records: 2116 example.org: "v=spf1 include:example.com include:example.net -all" 2118 This record would be used if mail from example.org actually came 2119 through servers at example.com and example.net. Example.org's 2120 designated servers are the union of example.com's and example.net's 2121 designated servers. 2123 la.example.org: "v=spf1 redirect=example.org" 2124 ny.example.org: "v=spf1 redirect=example.org" 2125 sf.example.org: "v=spf1 redirect=example.org" 2127 These records allow a set of domains that all use the same mail 2128 system to make use of that mail system's record. In this way, only 2129 the mail system's record needs to be updated when the mail setup 2130 changes. These domains' records never have to change. 2132 B.3. DNSBL Style Example 2134 Imagine that, in addition to the domain records listed above, there 2135 are these: 2137 $ORIGIN _spf.example.com. 2138 mary.mobile-users A 127.0.0.2 2139 fred.mobile-users A 127.0.0.2 2140 15.15.168.192.joel.remote-users A 127.0.0.2 2141 16.15.168.192.joel.remote-users A 127.0.0.2 2143 The following records describe users at example.com who mail from 2144 arbitrary servers, or who mail from personal servers. 2146 example.com: 2148 v=spf1 mx 2149 include:mobile-users._spf.%{d} 2150 include:remote-users._spf.%{d} 2151 -all 2153 mobile-users._spf.example.com: 2155 v=spf1 exists:%{l1r+}.%{d} 2157 remote-users._spf.example.com: 2159 v=spf1 exists:%{ir}.%{l1r+}.%{d} 2161 B.4. Multiple Requirements Example 2163 Say that your sender policy requires both that the IP address is 2164 within a certain range and that the reverse DNS for the IP matches. 2165 This can be done several ways, including the following: 2167 example.com. SPF ( "v=spf1 " 2168 "-include:ip4._spf.%{d} " 2169 "-include:ptr._spf.%{d} " 2170 "+all" ) 2171 ip4._spf.example.com. SPF "v=spf1 -ip4:192.0.2.0/24 +all" 2172 ptr._spf.example.com. SPF "v=spf1 -ptr +all" 2174 This example shows how the "-include" mechanism can be useful, how an 2175 SPF record that ends in "+all" can be very restrictive, and the use 2176 of De Morgan's Law. 2178 Appendix C. Change History 2180 Changes since RFC 4408 (to be removed prior to publication) 2182 Moved to standards track 2184 Authors updated 2186 IESG Note regarding experimental use replaced with discussion of 2187 results 2189 Process errata: 2191 Add %v macro to ABNF grammar 2193 Replace "uric" by "unreserved" 2195 Recommend an SMTP reply code for optional permerror rejections 2197 Correct syntax in Received-SPF examples 2199 Fix unknown-modifier clause is too greedy in ABNF 2201 Correct use of empty domain-spec on exp modifier 2203 Fix minor typo errata 2205 Convert to spfbis working group draft, 2206 draft-ietf-spfbis-4408bis-00 2208 Addressed Ticket #1, RFC 4408 Section 2.5.6 - Temporary errors 2210 Clarified text about IPv4 mapped addresses to resolve test suite 2211 ambiguity 2213 Clarified ambiguity about result when more than 10 "mx" or "ptr" 2214 records are returned for lookup to specify permerror. This 2215 resolves one of the test suite ambiguities 2217 Made all references to result codes lower case per issue #7 2219 Adjusted section 2.2 Requirement to check mail from per issue #15 2221 Added missing "v" element in macro-letter in the collected ABNF 2222 per issue #16 - section 8.1 was already fixed in the pre-WG draft 2224 Marked ptr and "p" macro deprecated/SHOULD NOT use per issue #27 2225 Expunged lower case may from the draft per issue #8 2227 Expunged "x-" name as an obsolete concept 2229 Updated obslete references: RFC2821 to RFC5321, RFC2822 to 2230 RFC5322, and RFC4234 to RFC5234 2232 Author's Address 2234 Scott Kitterman 2235 Agari 2236 3611 Scheel Dr 2237 Ellicott City, MD 21042 2238 United States of America 2240 Email: scott@kitterman.com