idnits 2.17.1 draft-kitterman-4408bis-00.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. -- The draft header indicates that this document obsoletes RFC4408, but the abstract doesn't seem to mention this, which it should. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 1211 has weird spacing: '...pe-from the e...' == The document seems to use 'NOT RECOMMENDED' as an RFC 2119 keyword, but does not include the phrase in its RFC 2119 key words list. == 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 (October 24, 2011) is 4567 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 2005, but not defined ** Obsolete normative reference: RFC 2821 (Obsoleted by RFC 5321) ** Obsolete normative reference: RFC 2822 (Obsoleted by RFC 5322) ** Obsolete normative reference: RFC 3513 (Obsoleted by RFC 4291) ** Obsolete normative reference: RFC 4234 (Obsoleted by RFC 5234) -- 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) -- Obsolete informational reference (is this intentional?): RFC 4871 (Obsoleted by RFC 6376) Summary: 4 errors (**), 0 flaws (~~), 8 warnings (==), 9 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group D. Kitterman 3 Internet-Draft W. Schlitt 4 Obsoletes: 4408 (if approved) October 24, 2011 5 Intended status: Standards Track 6 Expires: April 26, 2012 8 Sender Policy Framework (SPF) for Authorizing Use of Domains in E-Mail, 9 Version 1 10 draft-kitterman-4408bis-00.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 may 19 explicitly authorize the hosts that are allowed to use its domain 20 name, and a receiving host may check such authorization. 22 Status of this Memo 24 This Internet-Draft is submitted in full conformance with the 25 provisions of BCP 78 and BCP 79. 27 Internet-Drafts are working documents of the Internet Engineering 28 Task Force (IETF). Note that other groups may also distribute 29 working documents as Internet-Drafts. The list of current Internet- 30 Drafts is at http://datatracker.ietf.org/drafts/current/. 32 Internet-Drafts are draft documents valid for a maximum of six months 33 and may be updated, replaced, or obsoleted by other documents at any 34 time. It is inappropriate to use Internet-Drafts as reference 35 material or to cite them other than as "work in progress." 37 This Internet-Draft will expire on April 26, 2012. 39 Copyright Notice 41 Copyright (c) 2011 IETF Trust and the persons identified as the 42 document authors. All rights reserved. 44 This document is subject to BCP 78 and the IETF Trust's Legal 45 Provisions Relating to IETF Documents 46 (http://trustee.ietf.org/license-info) in effect on the date of 47 publication of this document. Please review these documents 48 carefully, as they describe your rights and restrictions with respect 49 to this document. Code Components extracted from this document must 50 include Simplified BSD License text as described in Section 4.e of 51 the Trust Legal Provisions and are provided without warranty as 52 described in the Simplified BSD License. 54 This document may contain material from IETF Documents or IETF 55 Contributions published or made publicly available before November 56 10, 2008. The person(s) controlling the copyright in some of this 57 material may not have granted the IETF Trust the right to allow 58 modifications of such material outside the IETF Standards Process. 59 Without obtaining an adequate license from the person(s) controlling 60 the copyright in such materials, this document may not be modified 61 outside the IETF Standards Process, and derivative works of it may 62 not be created outside the IETF Standards Process, except to format 63 it for publication as an RFC or to translate it into languages other 64 than English. 66 Table of Contents 68 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5 69 1.1. Protocol Status . . . . . . . . . . . . . . . . . . . . . 5 70 1.2. Experimental History . . . . . . . . . . . . . . . . . . . 6 71 1.3. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 72 2. Operation . . . . . . . . . . . . . . . . . . . . . . . . . . 7 73 2.1. The HELO Identity . . . . . . . . . . . . . . . . . . . . 7 74 2.2. The MAIL FROM Identity . . . . . . . . . . . . . . . . . . 7 75 2.3. Publishing Authorization . . . . . . . . . . . . . . . . . 7 76 2.4. Checking Authorization . . . . . . . . . . . . . . . . . . 8 77 2.5. Interpreting the Result . . . . . . . . . . . . . . . . . 9 78 2.5.1. None . . . . . . . . . . . . . . . . . . . . . . . . . 9 79 2.5.2. Neutral . . . . . . . . . . . . . . . . . . . . . . . 10 80 2.5.3. Pass . . . . . . . . . . . . . . . . . . . . . . . . . 10 81 2.5.4. Fail . . . . . . . . . . . . . . . . . . . . . . . . . 10 82 2.5.5. SoftFail . . . . . . . . . . . . . . . . . . . . . . . 10 83 2.5.6. TempError . . . . . . . . . . . . . . . . . . . . . . 11 84 2.5.7. PermError . . . . . . . . . . . . . . . . . . . . . . 11 85 3. SPF Records . . . . . . . . . . . . . . . . . . . . . . . . . 12 86 3.1. Publishing . . . . . . . . . . . . . . . . . . . . . . . . 12 87 3.1.1. DNS Resource Record Types . . . . . . . . . . . . . . 12 88 3.1.2. Multiple DNS Records . . . . . . . . . . . . . . . . . 13 89 3.1.3. Multiple Strings in a Single DNS record . . . . . . . 13 90 3.1.4. Record Size . . . . . . . . . . . . . . . . . . . . . 13 91 3.1.5. Wildcard Records . . . . . . . . . . . . . . . . . . . 14 92 4. The check_host() Function . . . . . . . . . . . . . . . . . . 15 93 4.1. Arguments . . . . . . . . . . . . . . . . . . . . . . . . 15 94 4.2. Results . . . . . . . . . . . . . . . . . . . . . . . . . 15 95 4.3. Initial Processing . . . . . . . . . . . . . . . . . . . . 15 96 4.4. Record Lookup . . . . . . . . . . . . . . . . . . . . . . 16 97 4.5. Selecting Records . . . . . . . . . . . . . . . . . . . . 16 98 4.6. Record Evaluation . . . . . . . . . . . . . . . . . . . . 16 99 4.6.1. Term Evaluation . . . . . . . . . . . . . . . . . . . 17 100 4.6.2. Mechanisms . . . . . . . . . . . . . . . . . . . . . . 17 101 4.6.3. Modifiers . . . . . . . . . . . . . . . . . . . . . . 18 102 4.7. Default Result . . . . . . . . . . . . . . . . . . . . . . 18 103 4.8. Domain Specification . . . . . . . . . . . . . . . . . . . 18 104 5. Mechanism Definitions . . . . . . . . . . . . . . . . . . . . 20 105 5.1. "all" . . . . . . . . . . . . . . . . . . . . . . . . . . 20 106 5.2. "include" . . . . . . . . . . . . . . . . . . . . . . . . 21 107 5.3. "a" . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 108 5.4. "mx" . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 109 5.5. "ptr" . . . . . . . . . . . . . . . . . . . . . . . . . . 23 110 5.6. "ip4" and "ip6" . . . . . . . . . . . . . . . . . . . . . 24 111 5.7. "exists" . . . . . . . . . . . . . . . . . . . . . . . . . 25 112 6. Modifier Definitions . . . . . . . . . . . . . . . . . . . . . 26 113 6.1. redirect: Redirected Query . . . . . . . . . . . . . . . . 26 114 6.2. exp: Explanation . . . . . . . . . . . . . . . . . . . . . 27 115 7. The Received-SPF Header Field . . . . . . . . . . . . . . . . 29 116 8. Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 117 8.1. Macro Definitions . . . . . . . . . . . . . . . . . . . . 31 118 8.2. Expansion Examples . . . . . . . . . . . . . . . . . . . . 34 119 9. Implications . . . . . . . . . . . . . . . . . . . . . . . . . 35 120 9.1. Sending Domains . . . . . . . . . . . . . . . . . . . . . 35 121 9.2. Mailing Lists . . . . . . . . . . . . . . . . . . . . . . 35 122 9.3. Forwarding Services and Aliases . . . . . . . . . . . . . 35 123 9.4. Mail Services . . . . . . . . . . . . . . . . . . . . . . 37 124 9.5. MTA Relays . . . . . . . . . . . . . . . . . . . . . . . . 38 125 10. Security Considerations . . . . . . . . . . . . . . . . . . . 39 126 10.1. Processing Limits . . . . . . . . . . . . . . . . . . . . 39 127 10.2. SPF-Authorized E-Mail May Contain Other False 128 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 . . . . . . . . . . . . . . . . . . . 48 141 Appendix B. Extended Examples . . . . . . . . . . . . . . . . . . 50 142 B.1. Simple Examples . . . . . . . . . . . . . . . . . . . . . 50 143 B.2. Multiple Domain Example . . . . . . . . . . . . . . . . . 51 144 B.3. DNSBL Style Example . . . . . . . . . . . . . . . . . . . 52 145 B.4. Multiple Requirements Example . . . . . . . . . . . . . . 52 146 Appendix C. Change History . . . . . . . . . . . . . . . . . . . 53 147 Appendix D. TODO . . . . . . . . . . . . . . . . . . . . . . . . 54 148 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 55 150 1. Introduction 152 The current E-Mail infrastructure has the property that any host 153 injecting mail into the mail system can identify itself as any domain 154 name it wants. Hosts can do this at a variety of levels: in 155 particular, the session, the envelope, and the mail headers. 156 Although this feature is desirable in some circumstances, it is a 157 major obstacle to reducing Unsolicited Bulk E-Mail (UBE, aka spam). 158 Furthermore, many domain name holders are understandably concerned 159 about the ease with which other entities may make use of their domain 160 names, often with malicious intent. 162 This document defines a protocol by which domain owners may authorize 163 hosts to use their domain name in the "MAIL FROM" or "HELO" identity. 164 Compliant domain holders publish Sender Policy Framework (SPF) 165 records specifying which hosts are permitted to use their names, and 166 compliant mail receivers use the published SPF records to test the 167 authorization of sending Mail Transfer Agents (MTAs) using a given 168 "HELO" or "MAIL FROM" identity during a mail transaction. 170 An additional benefit to mail receivers is that after the use of an 171 identity is verified, local policy decisions about the mail can be 172 made based on the sender's domain, rather than the host's IP address. 173 This is advantageous because reputation of domain names is likely to 174 be more accurate than reputation of host IP addresses. Furthermore, 175 if a claimed identity fails verification, local policy can take 176 stronger action against such E-Mail, such as rejecting it. 178 1.1. Protocol Status 180 SPF has been in development since the summer of 2003 and has seen 181 deployment beyond the developers beginning in December 2003. The 182 design of SPF slowly evolved until the spring of 2004 and has since 183 stabilized. There have been quite a number of forms of SPF, some 184 written up as documents, some submitted as Internet Drafts, and many 185 discussed and debated in development forums. The protocol was 186 originally documented in [RFC4408], which this memo replaces. 188 The goal of this document is to clearly document the protocol defined 189 by earlier draft specifications of SPF as used in existing 190 implementations. This conception of SPF is sometimes called "SPF 191 Classic". It is understood that particular implementations and 192 deployments may differ from, and build upon, this work. It is hoped 193 that we have nonetheless captured the common understanding of SPF 194 version 1. 196 1.2. Experimental History 198 This document updates and replaces RFC 4408 that was part of a group 199 of simultaneously published Experimental RFCs (RFC 4405, RFC 4406, 200 RFC 4407, and RFC 4408) in 2006. At that time the IESG requested the 201 community observe the success or failure of the two approaches 202 documented in these RFCs during the two years following publication, 203 in order that a community consensus can be reached in the future. 205 In the interval since that statement, DKIM (see [RFC4871] was 206 developed and achieved wide deployment. Both Sender ID (as the 207 protocol defined in RFC 4405, RFC 4406, and RFC 4407 was named) and 208 DKIM target "message content", as described in [RFC5598], while SPF 209 targets the "transit-handling envelope". The success or failure of 210 the Sender ID portion of this IESG experiment should be evaluated 211 relative to DKIM. 213 SPF is widely deployed by large and small email providers alike. 214 There are multiple, interoperable implementations. 216 For SPF (as documented in RFC 4408) a careful effort was made to 217 collect and document lessons learned and errata during the two year 218 period. The errata list has been stable (no new submissions) and 219 only minor protocol lessons learned were identified. 221 1.3. Terminology 223 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 224 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 225 document are to be interpreted as described in [RFC2119]. 227 This document is concerned with the portion of a mail message 228 commonly called "envelope sender", "return path", "reverse path", 229 "bounce address", "2821 FROM", or "MAIL FROM". Since these terms are 230 either not well defined or often used casually, this document defines 231 the "MAIL FROM" identity in Section 2.2. Note that other terms that 232 may superficially look like the common terms, such as "reverse-path", 233 are used only with the defined meanings from normative documents. 235 2. Operation 237 2.1. The HELO Identity 239 The "HELO" identity derives from either the SMTP HELO or EHLO command 240 (see [RFC2821]). These commands supply the SMTP client (sending 241 host) for the SMTP session. Note that requirements for the domain 242 presented in the EHLO or HELO command are not always clear to the 243 sending party, and SPF clients must be prepared for the "HELO" 244 identity to be malformed or an IP address literal. At the time of 245 this writing, many legitimate E-Mails are delivered with invalid HELO 246 domains. 248 It is RECOMMENDED that SPF clients not only check the "MAIL FROM" 249 identity, but also separately check the "HELO" identity by applying 250 the check_host() function (Section 4) to the "HELO" identity as the 251 . 253 2.2. The MAIL FROM Identity 255 The "MAIL FROM" identity derives from the SMTP MAIL command (see 256 [RFC2821]). This command supplies the "reverse-path" for a message, 257 which generally consists of the sender mailbox, and is the mailbox to 258 which notification messages are to be sent if there are problems 259 delivering the message. 261 [RFC2821] allows the reverse-path to be null (see Section 4.5.5 in 262 RFC 2821). In this case, there is no explicit sender mailbox, and 263 such a message can be assumed to be a notification message from the 264 mail system itself. When the reverse-path is null, this document 265 defines the "MAIL FROM" identity to be the mailbox composed of the 266 localpart "postmaster" and the "HELO" identity (which may or may not 267 have been checked separately before). 269 SPF clients MUST check the "MAIL FROM" identity. SPF clients check 270 the "MAIL FROM" identity by applying the check_host() function to the 271 "MAIL FROM" identity as the . 273 2.3. Publishing Authorization 275 An SPF-compliant domain MUST publish a valid SPF record as described 276 in Section 3. This record authorizes the use of the domain name in 277 the "HELO" and "MAIL FROM" identities by the MTAs it specifies. 279 If domain owners choose to publish SPF records, it is RECOMMENDED 280 that they end in "-all", or redirect to other records that do, so 281 that a definitive determination of authorization can be made. 283 Domain holders may publish SPF records that explicitly authorize no 284 hosts if mail should never originate using that domain. 286 When changing SPF records, care must be taken to ensure that there is 287 a transition period so that the old policy remains valid until all 288 legitimate E-Mail has been checked. 290 2.4. Checking Authorization 292 A mail receiver can perform a set of SPF checks for each mail message 293 it receives. An SPF check tests the authorization of a client host 294 to emit mail with a given identity. Typically, such checks are done 295 by a receiving MTA, but can be performed elsewhere in the mail 296 processing chain so long as the required information is available and 297 reliable. At least the "MAIL FROM" identity MUST be checked, but it 298 is RECOMMENDED that the "HELO" identity also be checked beforehand. 300 Without explicit approval of the domain owner, checking other 301 identities against SPF version 1 records is NOT RECOMMENDED because 302 there are cases that are known to give incorrect results. For 303 example, almost all mailing lists rewrite the "MAIL FROM" identity 304 (see Section 9.2), but some do not change any other identities in the 305 message. The scenario described in Section 9.3, sub-section 1.2, is 306 another example. Documents that define other identities should 307 define the method for explicit approval. 309 It is possible that mail receivers will use the SPF check as part of 310 a larger set of tests on incoming mail. The results of other tests 311 may influence whether or not a particular SPF check is performed. 312 For example, finding the sending host's IP address on a local white 313 list may cause all other tests to be skipped and all mail from that 314 host to be accepted. 316 When a mail receiver decides to perform an SPF check, it MUST use a 317 correctly-implemented check_host() function (Section 4) evaluated 318 with the correct parameters. Although the test as a whole is 319 optional, once it has been decided to perform a test it must be 320 performed as specified so that the correct semantics are preserved 321 between publisher and receiver. 323 To make the test, the mail receiver MUST evaluate the check_host() 324 function with the arguments set as follows: 326 - the IP address of the SMTP client that is emitting the 327 mail, either IPv4 or IPv6. 329 - the domain portion of the "MAIL FROM" or "HELO" identity. 331 - the "MAIL FROM" or "HELO" identity. 333 Note that the argument may not be a well-formed domain name. 334 For example, if the reverse-path was null, then the EHLO/HELO domain 335 is used, with its associated problems (see Section 2.1). In these 336 cases, check_host() is defined in Section 4.3 to return a "None" 337 result. 339 Although invalid, malformed, or non-existent domains cause SPF checks 340 to return "None" because no SPF record can be found, it has long been 341 the policy of many MTAs to reject E-Mail from such domains, 342 especially in the case of invalid "MAIL FROM". In order to prevent 343 the circumvention of SPF records, rejecting E-Mail from invalid 344 domains should be considered. 346 Implementations must take care to correctly extract the from 347 the data given with the SMTP MAIL FROM command as many MTAs will 348 still accept such things as source routes (see [RFC2821], Appendix 349 C), the %-hack (see [RFC1123]), and bang paths (see [RFC1983]). 350 These archaic features have been maliciously used to bypass security 351 systems. 353 2.5. Interpreting the Result 355 This section describes how software that performs the authorization 356 should interpret the results of the check_host() function. The 357 authorization check SHOULD be performed during the processing of the 358 SMTP transaction that sends the mail. This allows errors to be 359 returned directly to the sending MTA by way of SMTP replies. 361 Performing the authorization after the SMTP transaction has finished 362 may cause problems, such as the following: (1) It may be difficult to 363 accurately extract the required information from potentially 364 deceptive headers; (2) legitimate E-Mail may fail because the 365 sender's policy may have since changed. 367 Generating non-delivery notifications to forged identities that have 368 failed the authorization check is generally abusive and against the 369 explicit wishes of the identity owner. 371 2.5.1. None 373 A result of "None" means that no records were published by the domain 374 or that no checkable sender domain could be determined from the given 375 identity. The checking software cannot ascertain whether or not the 376 client host is authorized. 378 2.5.2. Neutral 380 The domain owner has explicitly stated that he cannot or does not 381 want to assert whether or not the IP address is authorized. A 382 "Neutral" result MUST be treated exactly like the "None" result; the 383 distinction exists only for informational purposes. Treating 384 "Neutral" more harshly than "None" would discourage domain owners 385 from testing the use of SPF records (see Section 9.1). 387 2.5.3. Pass 389 A "Pass" result means that the client is authorized to inject mail 390 with the given identity. The domain can now, in the sense of 391 reputation, be considered responsible for sending the message. 392 Further policy checks can now proceed with confidence in the 393 legitimate use of the identity. 395 2.5.4. Fail 397 A "Fail" result is an explicit statement that the client is not 398 authorized to use the domain in the given identity. The checking 399 software can choose to mark the mail based on this or to reject the 400 mail outright. 402 If the checking software chooses to reject the mail during the SMTP 403 transaction, then it SHOULD use an SMTP reply code of 550 (see 404 [RFC2821]) and, if supported, the 5.7.1 Delivery Status Notification 405 (DSN) code (see [RFC3464]), in addition to an appropriate reply text. 406 The check_host() function may return either a default explanation 407 string or one from the domain that published the SPF records (see 408 Section 6.2). If the information does not originate with the 409 checking software, it should be made clear that the text is provided 410 by the sender's domain. For example: 412 550-5.7.1 SPF MAIL FROM check failed: 413 550-5.7.1 The domain example.com explains: 414 550 5.7.1 Please see http://www.example.com/mailpolicy.html 416 2.5.5. SoftFail 418 A "SoftFail" result should be treated as somewhere between a "Fail" 419 and a "Neutral". The domain believes the host is not authorized but 420 is not willing to make that strong of a statement. Receiving 421 software SHOULD NOT reject the message based solely on this result, 422 but MAY subject the message to closer scrutiny than normal. 424 The domain owner wants to discourage the use of this host and thus 425 desires limited feedback when a "SoftFail" result occurs. For 426 example, the recipient's Mail User Agent (MUA) could highlight the 427 "SoftFail" status, or the receiving MTA could give the sender a 428 message using a technique called "greylisting" whereby the MTA can 429 issue an SMTP reply code of 451 (4.3.0 DSN code) with a note the 430 first time the message is received, but accept it the second time. 432 2.5.6. TempError 434 A "TempError" result means that the SPF client encountered a 435 transient error while performing the check. Checking software can 436 choose to accept or temporarily reject the message. If the message 437 is rejected during the SMTP transaction for this reason, the software 438 SHOULD use an SMTP reply code of 451 and, if supported, the 4.4.3 DSN 439 code. 441 2.5.7. PermError 443 A "PermError" result means that the domain's published records could 444 not be correctly interpreted. This signals an error condition that 445 requires manual intervention to be resolved, as opposed to the 446 TempError result. If the message is rejected during the SMTP 447 transaction for this reason, the software SHOULD use an SMTP reply 448 code of 550 and, if supported, the 5.5.2 DSN code. Be aware that if 449 the domain owner uses macros (Section 8), it is possible that this 450 result is due to the checked identities having an unexpected format. 452 3. SPF Records 454 An SPF record is a DNS Resource Record (RR) that declares which hosts 455 are, and are not, authorized to use a domain name for the "HELO" and 456 "MAIL FROM" identities. Loosely, the record partitions all hosts 457 into permitted and not-permitted sets (though some hosts might fall 458 into neither category). 460 The SPF record is a single string of text. An example record is the 461 following: 463 v=spf1 +mx a:colo.example.com/28 -all 465 This record has a version of "spf1" and three directives: "+mx", 466 "a:colo.example.com/28" (the + is implied), and "-all". 468 3.1. Publishing 470 Domain owners wishing to be SPF compliant must publish SPF records 471 for the hosts that are used in the "MAIL FROM" and "HELO" identities. 472 The SPF records are placed in the DNS tree at the host name it 473 pertains to, not a subdomain under it, such as is done with SRV 474 records. This is the same whether the TXT or SPF RR type (see 475 Section 3.1.1) is used. 477 The example above in Section 3 might be published via these lines in 478 a domain zone file: 480 example.com. TXT "v=spf1 +mx a:colo.example.com/28 -all" 481 smtp-out.example.com. TXT "v=spf1 a -all" 483 When publishing via TXT records, beware of other TXT records 484 published there for other purposes. They may cause problems with 485 size limits (see Section 3.1.4). 487 3.1.1. DNS Resource Record Types 489 This document defines a new DNS RR of type SPF, code 99. The format 490 of this type is identical to the TXT RR [RFC1035]. For either type, 491 the character content of the record is encoded as [US-ASCII]. 493 It is recognized that the current practice (using a TXT record) is 494 not optimal, but it is necessary because there are a number of DNS 495 server and resolver implementations in common use that cannot handle 496 the new RR type. The two-record-type scheme provides a forward path 497 to the better solution of using an RR type reserved for this purpose. 499 An SPF-compliant domain name SHOULD have SPF records of both RR 500 types. A compliant domain name MUST have a record of at least one 501 type. If a domain has records of both types, they MUST have 502 identical content. For example, instead of publishing just one 503 record as in Section 3.1 above, it is better to publish: 505 example.com. IN TXT "v=spf1 +mx a:colo.example.com/28 -all" 506 example.com. IN SPF "v=spf1 +mx a:colo.example.com/28 -all" 508 Example RRs in this document are shown with the TXT record type; 509 however, they could be published with the SPF type or with both 510 types. 512 3.1.2. Multiple DNS Records 514 A domain name MUST NOT have multiple records that would cause an 515 authorization check to select more than one record. See Section 4.5 516 for the selection rules. 518 3.1.3. Multiple Strings in a Single DNS record 520 As defined in [RFC1035] sections 3.3.14 and 3.3, a single text DNS 521 record (either TXT or SPF RR types) can be composed of more than one 522 string. If a published record contains multiple strings, then the 523 record MUST be treated as if those strings are concatenated together 524 without adding spaces. For example: 526 IN TXT "v=spf1 .... first" "second string..." 528 MUST be treated as equivalent to 530 IN TXT "v=spf1 .... firstsecond string..." 532 SPF or TXT records containing multiple strings are useful in 533 constructing records that would exceed the 255-byte maximum length of 534 a string within a single TXT or SPF RR record. 536 3.1.4. Record Size 538 The published SPF record for a given domain name SHOULD remain small 539 enough that the results of a query for it will fit within 512 octets. 540 This will keep even older DNS implementations from falling over to 541 TCP. Since the answer size is dependent on many things outside the 542 scope of this document, it is only possible to give this guideline: 543 If the combined length of the DNS name and the text of all the 544 records of a given type (TXT or SPF) is under 450 characters, then 545 DNS answers should fit in UDP packets. Note that when computing the 546 sizes for queries of the TXT format, one must take into account any 547 other TXT records published at the domain name. Records that are too 548 long to fit in a single UDP packet MAY be silently ignored by SPF 549 clients. 551 3.1.5. Wildcard Records 553 Use of wildcard records for publishing is not recommended. Care must 554 be taken if wildcard records are used. If a domain publishes 555 wildcard MX records, it may want to publish wildcard declarations, 556 subject to the same requirements and problems. In particular, the 557 declaration must be repeated for any host that has any RR records at 558 all, and for subdomains thereof. For example, the example given in 559 [RFC1034], Section 4.3.3, could be extended with the following: 561 X.COM. MX 10 A.X.COM 562 X.COM. TXT "v=spf1 a:A.X.COM -all" 564 *.X.COM. MX 10 A.X.COM 565 *.X.COM. TXT "v=spf1 a:A.X.COM -all" 567 A.X.COM. A 1.2.3.4 568 A.X.COM. MX 10 A.X.COM 569 A.X.COM. TXT "v=spf1 a:A.X.COM -all" 571 *.A.X.COM. MX 10 A.X.COM 572 *.A.X.COM. TXT "v=spf1 a:A.X.COM -all" 574 Notice that SPF records must be repeated twice for every name within 575 the domain: once for the name, and once with a wildcard to cover the 576 tree under the name. 578 Use of wildcards is discouraged in general as they cause every name 579 under the domain to exist and queries against arbitrary names will 580 never return RCODE 3 (Name Error). 582 4. The check_host() Function 584 The check_host() function fetches SPF records, parses them, and 585 interprets them to determine whether a particular host is or is not 586 permitted to send mail with a given identity. Mail receivers that 587 perform this check MUST correctly evaluate the check_host() function 588 as described here. 590 Implementations MAY use a different algorithm than the canonical 591 algorithm defined here, so long as the results are the same in all 592 cases. 594 4.1. Arguments 596 The check_host() function takes these arguments: 598 - the IP address of the SMTP client that is emitting the 599 mail, either IPv4 or IPv6. 601 - the domain that provides the sought-after authorization 602 information; initially, the domain portion of the "MAIL 603 FROM" or "HELO" identity. 605 - the "MAIL FROM" or "HELO" identity. 607 The domain portion of will usually be the same as the 608 argument when check_host() is initially evaluated. However, 609 this will generally not be true for recursive evaluations (see 610 Section 5.2 below). 612 Actual implementations of the check_host() function may need 613 additional arguments. 615 4.2. Results 617 The function check_host() can return one of several results described 618 in Section 2.5. Based on the result, the action to be taken is 619 determined by the local policies of the receiver. 621 4.3. Initial Processing 623 If the is malformed (label longer than 63 characters, zero- 624 length label not at the end, etc.) or is not a fully qualified domain 625 name, or if the DNS lookup returns "domain does not exist" (RCODE 3), 626 check_host() immediately returns the result "None". 628 If the has no localpart, substitute the string "postmaster" 629 for the localpart. 631 4.4. Record Lookup 633 In accordance with how the records are published (see Section 3.1 634 above), a DNS query needs to be made for the name, querying 635 for either RR type TXT, SPF, or both. If both SPF and TXT RRs are 636 looked up, the queries MAY be done in parallel. 638 If all DNS lookups that are made return a server failure (RCODE 2), 639 or other error (RCODE other than 0 or 3), or time out, then 640 check_host() exits immediately with the result "TempError". 642 4.5. Selecting Records 644 Records begin with a version section: 646 record = version terms *SP 647 version = "v=spf1" 649 Starting with the set of records that were returned by the lookup, 650 record selection proceeds in two steps: 652 1. Records that do not begin with a version section of exactly 653 "v=spf1" are discarded. Note that the version section is 654 terminated either by an SP character or the end of the record. A 655 record with a version section of "v=spf10" does not match and 656 must be discarded. 658 2. If any records of type SPF are in the set, then all records of 659 type TXT are discarded. 661 After the above steps, there should be exactly one record remaining 662 and evaluation can proceed. If there are two or more records 663 remaining, then check_host() exits immediately with the result of 664 "PermError". 666 If no matching records are returned, an SPF client MUST assume that 667 the domain makes no SPF declarations. SPF processing MUST stop and 668 return "None". 670 4.6. Record Evaluation 672 After one SPF record has been selected, the check_host() function 673 parses and interprets it to find a result for the current test. If 674 there are any syntax errors, check_host() returns immediately with 675 the result "PermError". 677 Implementations MAY choose to parse the entire record first and 678 return "PermError" if the record is not syntactically well formed. 680 However, in all cases, any syntax errors anywhere in the record MUST 681 be detected. 683 4.6.1. Term Evaluation 685 There are two types of terms: mechanisms and modifiers. A record 686 contains an ordered list of these as specified in the following 687 Augmented Backus-Naur Form (ABNF). 689 terms = *( 1*SP ( directive / modifier ) ) 691 directive = [ qualifier ] mechanism 692 qualifier = "+" / "-" / "?" / "~" 693 mechanism = ( all / include 694 / A / MX / PTR / IP4 / IP6 / exists ) 695 modifier = redirect / explanation / unknown-modifier 696 unknown-modifier = name "=" macro-string 697 ; where name is not any known modifier 699 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 701 Most mechanisms allow a ":" or "/" character after the name. 703 Modifiers always contain an equals ('=') character immediately after 704 the name, and before any ":" or "/" characters that may be part of 705 the macro-string. 707 Terms that do not contain any of "=", ":", or "/" are mechanisms, as 708 defined in Section 5. 710 As per the definition of the ABNF notation in [RFC4234], mechanism 711 and modifier names are case-insensitive. 713 4.6.2. Mechanisms 715 Each mechanism is considered in turn from left to right. If there 716 are no more mechanisms, the result is specified in Section 4.7. 718 When a mechanism is evaluated, one of three things can happen: it can 719 match, not match, or throw an exception. 721 If it matches, processing ends and the qualifier value is returned as 722 the result of that record. If it does not match, processing 723 continues with the next mechanism. If it throws an exception, 724 mechanism processing ends and the exception value is returned. 726 The possible qualifiers, and the results they return are as follows: 728 "+" Pass 729 "-" Fail 730 "~" SoftFail 731 "?" Neutral 733 The qualifier is optional and defaults to "+". 735 When a mechanism matches and the qualifier is "-", then a "Fail" 736 result is returned and the explanation string is computed as 737 described in Section 6.2. 739 The specific mechanisms are described in Section 5. 741 4.6.3. Modifiers 743 Modifiers are not mechanisms: they do not return match or not-match. 744 Instead they provide additional information. Although modifiers do 745 not directly affect the evaluation of the record, the "redirect" 746 modifier has an effect after all the mechanisms have been evaluated. 748 4.7. Default Result 750 If none of the mechanisms match and there is no "redirect" modifier, 751 then the check_host() returns a result of "Neutral", just as if 752 "?all" were specified as the last directive. If there is a 753 "redirect" modifier, check_host() proceeds as defined in Section 6.1. 755 Note that records SHOULD always use either a "redirect" modifier or 756 an "all" mechanism to explicitly terminate processing. 758 For example: 760 v=spf1 +mx -all 761 or 762 v=spf1 +mx redirect=_spf.example.com 764 4.8. Domain Specification 766 Several of these mechanisms and modifiers have a domain-spec section. 767 The domain-spec string is macro expanded (see Section 8). The 768 resulting string is the common presentation form of a fully-qualified 769 DNS name: a series of labels separated by periods. This domain is 770 called the in the rest of this document. 772 Note: The result of the macro expansion is not subject to any further 773 escaping. Hence, this facility cannot produce all characters that 774 are legal in a DNS label (e.g., the control characters). However, 775 this facility is powerful enough to express legal host names and 776 common utility labels (such as "_spf") that are used in DNS. 778 For several mechanisms, the is optional. If it is not 779 provided, the is used as the . 781 5. Mechanism Definitions 783 This section defines two types of mechanisms. 785 Basic mechanisms contribute to the language framework. They do not 786 specify a particular type of authorization scheme. 788 all 789 include 791 Designated sender mechanisms are used to designate a set of 792 addresses as being permitted or not permitted to use the for 793 sending mail. 795 a 796 mx 797 ptr 798 ip4 799 ip6 800 exists 802 The following conventions apply to all mechanisms that perform a 803 comparison between and an IP address at any point: 805 If no CIDR-length is given in the directive, then and the IP 806 address are compared for equality. (Here, CIDR is Classless Inter- 807 Domain Routing.) 809 If a CIDR-length is specified, then only the specified number of 810 high-order bits of and the IP address are compared for equality. 812 When any mechanism fetches host addresses to compare with , when 813 is an IPv4 address, A records are fetched, when is an IPv6 814 address, AAAA records are fetched. Even if the SMTP connection is 815 via IPv6, an IPv4-mapped IPv6 IP address (see [RFC3513], Section 816 2.5.5) MUST still be considered an IPv4 address. 818 Several mechanisms rely on information fetched from DNS. For these 819 DNS queries, except where noted, if the DNS server returns an error 820 (RCODE other than 0 or 3) or the query times out, the mechanism 821 throws the exception "TempError". If the server returns "domain does 822 not exist" (RCODE 3), then evaluation of the mechanism continues as 823 if the server returned no error (RCODE 0) and zero answer records. 825 5.1. "all" 827 all = "all" 828 The "all" mechanism is a test that always matches. It is used as the 829 rightmost mechanism in a record to provide an explicit default. 831 For example: 833 v=spf1 a mx -all 835 Mechanisms after "all" will never be tested. Any "redirect" modifier 836 (Section 6.1) has no effect when there is an "all" mechanism. 838 5.2. "include" 840 include = "include" ":" domain-spec 842 The "include" mechanism triggers a recursive evaluation of 843 check_host(). The domain-spec is expanded as per Section 8. Then 844 check_host() is evaluated with the resulting string as the . 845 The and arguments remain the same as in the current 846 evaluation of check_host(). 848 In hindsight, the name "include" was poorly chosen. Only the 849 evaluated result of the referenced SPF record is used, rather than 850 acting as if the referenced SPF record was literally included in the 851 first. For example, evaluating a "-all" directive in the referenced 852 record does not terminate the overall processing and does not 853 necessarily result in an overall "Fail". (Better names for this 854 mechanism would have been "if-pass", "on-pass", etc.) 856 The "include" mechanism makes it possible for one domain to designate 857 multiple administratively-independent domains. For example, a vanity 858 domain "example.net" might send mail using the servers of 859 administratively-independent domains example.com and example.org. 861 Example.net could say 863 IN TXT "v=spf1 include:example.com include:example.org -all" 865 This would direct check_host() to, in effect, check the records of 866 example.com and example.org for a "Pass" result. Only if the host 867 were not permitted for either of those domains would the result be 868 "Fail". 870 Whether this mechanism matches, does not match, or throws an 871 exception depends on the result of the recursive evaluation of 872 check_host(): 874 +---------------------------------+---------------------------------+ 875 | A recursive check_host() result | Causes the "include" mechanism | 876 | of: | to: | 877 +---------------------------------+---------------------------------+ 878 | Pass | match | 879 | | | 880 | Fail | not match | 881 | | | 882 | SoftFail | not match | 883 | | | 884 | Neutral | not match | 885 | | | 886 | TempError | throw TempError | 887 | | | 888 | PermError | throw PermError | 889 | | | 890 | None | throw PermError | 891 +---------------------------------+---------------------------------+ 893 The "include" mechanism is intended for crossing administrative 894 boundaries. Although it is possible to use includes to consolidate 895 multiple domains that share the same set of designated hosts, domains 896 are encouraged to use redirects where possible, and to minimize the 897 number of includes within a single administrative domain. For 898 example, if example.com and example.org were managed by the same 899 entity, and if the permitted set of hosts for both domains was 900 "mx:example.com", it would be possible for example.org to specify 901 "include:example.com", but it would be preferable to specify 902 "redirect=example.com" or even "mx:example.com". 904 5.3. "a" 906 This mechanism matches if is one of the 's IP 907 addresses. 909 A = "a" [ ":" domain-spec ] [ dual-cidr-length ] 911 An address lookup is done on the . The is compared 912 to the returned address(es). If any address matches, the mechanism 913 matches. 915 5.4. "mx" 917 This mechanism matches if is one of the MX hosts for a domain 918 name. 920 MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 921 check_host() first performs an MX lookup on the . Then 922 it performs an address lookup on each MX name returned. The is 923 compared to each returned IP address. To prevent Denial of Service 924 (DoS) attacks, more than 10 MX names MUST NOT be looked up during the 925 evaluation of an "mx" mechanism (see Section 10). If any address 926 matches, the mechanism matches. 928 Note regarding implicit MXs: If the has no MX records, 929 check_host() MUST NOT pretend the target is its single MX, and MUST 930 NOT default to an A lookup on the directly. This 931 behavior breaks with the legacy "implicit MX" rule. See [RFC2821], 932 Section 5. If such behavior is desired, the publisher should specify 933 an "a" directive. 935 5.5. "ptr" 937 This mechanism tests whether the DNS reverse-mapping for exists 938 and correctly points to a domain name within a particular domain. 940 PTR = "ptr" [ ":" domain-spec ] 942 First, the 's name is looked up using this procedure: perform a 943 DNS reverse-mapping for , looking up the corresponding PTR record 944 in "in-addr.arpa." if the address is an IPv4 one and in "ip6.arpa." 945 if it is an IPv6 address. For each record returned, validate the 946 domain name by looking up its IP address. To prevent DoS attacks, 947 more than 10 PTR names MUST NOT be looked up during the evaluation of 948 a "ptr" mechanism (see Section 10). If is among the returned IP 949 addresses, then that domain name is validated. In pseudocode: 951 sending-domain_names := ptr_lookup(sending-host_IP); 952 if more than 10 sending-domain_names are found, use at most 10. 953 for each name in (sending-domain_names) { 954 IP_addresses := a_lookup(name); 955 if the sending-domain_IP is one of the IP_addresses { 956 validated-sending-domain_names += name; 957 } 958 } 960 Check all validated domain names to see if they end in the 961 domain. If any do, this mechanism matches. If no 962 validated domain name can be found, or if none of the validated 963 domain names end in the , this mechanism fails to match. 964 If a DNS error occurs while doing the PTR RR lookup, then this 965 mechanism fails to match. If a DNS error occurs while doing an A RR 966 lookup, then that domain name is skipped and the search continues. 968 Pseudocode: 970 for each name in (validated-sending-domain_names) { 971 if name ends in , return match. 972 if name is , return match. 973 } 974 return no-match. 976 This mechanism matches if the is either an ancestor of 977 a validated domain name or if the and a validated 978 domain name are the same. For example: "mail.example.com" is within 979 the domain "example.com", but "mail.bad-example.com" is not. 981 Note: Use of this mechanism is discouraged because it is slow, it is 982 not as reliable as other mechanisms in cases of DNS errors, and it 983 places a large burden on the arpa name servers. If used, proper PTR 984 records must be in place for the domain's hosts and the "ptr" 985 mechanism should be one of the last mechanisms checked. 987 5.6. "ip4" and "ip6" 989 These mechanisms test whether is contained within a given IP 990 network. 992 IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 993 IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 995 ip4-cidr-length = "/" 1*DIGIT 996 ip6-cidr-length = "/" 1*DIGIT 997 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 999 ip4-network = qnum "." qnum "." qnum "." qnum 1000 qnum = DIGIT ; 0-9 1001 / %x31-39 DIGIT ; 10-99 1002 / "1" 2DIGIT ; 100-199 1003 / "2" %x30-34 DIGIT ; 200-249 1004 / "25" %x30-35 ; 250-255 1005 ; as per conventional dotted quad notation. e.g., 192.0.2.0 1006 ip6-network = 1007 ; e.g., 2001:DB8::CD30 1009 The is compared to the given network. If CIDR-length high-order 1010 bits match, the mechanism matches. 1012 If ip4-cidr-length is omitted, it is taken to be "/32". If 1013 ip6-cidr-length is omitted, it is taken to be "/128". It is not 1014 permitted to omit parts of the IP address instead of using CIDR 1015 notations. That is, use 192.0.2.0/24 instead of 192.0.2. 1017 5.7. "exists" 1019 This mechanism is used to construct an arbitrary domain name that is 1020 used for a DNS A record query. It allows for complicated schemes 1021 involving arbitrary parts of the mail envelope to determine what is 1022 permitted. 1024 exists = "exists" ":" domain-spec 1026 The domain-spec is expanded as per Section 8. The resulting domain 1027 name is used for a DNS A RR lookup. If any A record is returned, 1028 this mechanism matches. The lookup type is A even when the 1029 connection type is IPv6. 1031 Domains can use this mechanism to specify arbitrarily complex 1032 queries. For example, suppose example.com publishes the record: 1034 v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all 1036 The might expand to 1037 "1.2.0.192.someuser._spf.example.com". This makes fine-grained 1038 decisions possible at the level of the user and client IP address. 1040 This mechanism enables queries that mimic the style of tests that 1041 existing anti-spam DNS blacklists (DNSBL) use. 1043 6. Modifier Definitions 1045 Modifiers are name/value pairs that provide additional information. 1046 Modifiers always have an "=" separating the name and the value. 1048 The modifiers defined in this document ("redirect" and "exp") MAY 1049 appear anywhere in the record, but SHOULD appear at the end, after 1050 all mechanisms. Ordering of these two modifiers does not matter. 1051 These two modifiers MUST NOT appear in a record more than once each. 1052 If they do, then check_host() exits with a result of "PermError". 1054 Unrecognized modifiers MUST be ignored no matter where in a record, 1055 or how often. This allows implementations of this document to 1056 gracefully handle records with modifiers that are defined in other 1057 specifications. 1059 6.1. redirect: Redirected Query 1061 If all mechanisms fail to match, and a "redirect" modifier is 1062 present, then processing proceeds as follows: 1064 redirect = "redirect" "=" domain-spec 1066 The domain-spec portion of the redirect section is expanded as per 1067 the macro rules in Section 8. Then check_host() is evaluated with 1068 the resulting string as the . The and 1069 arguments remain the same as in the current evaluation of 1070 check_host(). 1072 The result of this new evaluation of check_host() is then considered 1073 the result of the current evaluation with the exception that if no 1074 SPF record is found, or if the target-name is malformed, the result 1075 is a "PermError" rather than "None". 1077 Note that the newly-queried domain may itself specify redirect 1078 processing. 1080 This facility is intended for use by organizations that wish to apply 1081 the same record to multiple domains. For example: 1083 la.example.com. TXT "v=spf1 redirect=_spf.example.com" 1084 ny.example.com. TXT "v=spf1 redirect=_spf.example.com" 1085 sf.example.com. TXT "v=spf1 redirect=_spf.example.com" 1086 _spf.example.com. TXT "v=spf1 mx:example.com -all" 1088 In this example, mail from any of the three domains is described by 1089 the same record. This can be an administrative advantage. 1091 Note: In general, the domain "A" cannot reliably use a redirect to 1092 another domain "B" not under the same administrative control. Since 1093 the stays the same, there is no guarantee that the record at 1094 domain "B" will correctly work for mailboxes in domain "A", 1095 especially if domain "B" uses mechanisms involving localparts. An 1096 "include" directive may be more appropriate. 1098 For clarity, it is RECOMMENDED that any "redirect" modifier appear as 1099 the very last term in a record. 1101 6.2. exp: Explanation 1103 explanation = "exp" "=" domain-spec 1105 If check_host() results in a "Fail" due to a mechanism match (such as 1106 "-all"), and the "exp" modifier is present, then the explanation 1107 string returned is computed as described below. If no "exp" modifier 1108 is present, then either a default explanation string or an empty 1109 explanation string may be returned. 1111 The domain-spec is macro expanded (see Section 8) and becomes the 1112 . The DNS TXT record for the is fetched. 1114 If there are any DNS processing errors (any RCODE other than 0), or 1115 if no records are returned, or if more than one record is returned, 1116 or if there are syntax errors in the explanation string, then proceed 1117 as if no exp modifier was given. 1119 The fetched TXT record's strings are concatenated with no spaces, and 1120 then treated as an explain-string, which is macro-expanded. This 1121 final result is the explanation string. Implementations MAY limit 1122 the length of the resulting explanation string to allow for other 1123 protocol constraints and/or reasonable processing limits. Since the 1124 explanation string is intended for an SMTP response and [RFC2821] 1125 Section 2.4 says that responses are in [US-ASCII], the explanation 1126 string is also limited to US-ASCII. 1128 Software evaluating check_host() can use this string to communicate 1129 information from the publishing domain in the form of a short message 1130 or URL. Software SHOULD make it clear that the explanation string 1131 comes from a third party. For example, it can prepend the macro 1132 string "%{o} explains: " to the explanation, such as shown in 1133 Section 2.5.4. 1135 Suppose example.com has this record: 1137 v=spf1 mx -all exp=explain._spf.%{d} 1139 Here are some examples of possible explanation TXT records at 1140 explain._spf.example.com: 1142 "Mail from example.com should only be sent by its own servers." 1143 -- a simple, constant message 1145 "%{i} is not one of %{d}'s designated mail servers." 1146 -- a message with a little more information, including the IP 1147 address that failed the check 1149 "See http://%{d}/why.html?s=%{S}&i=%{I}" 1150 -- a complicated example that constructs a URL with the 1151 arguments to check_host() so that a web page can be 1152 generated with detailed, custom instructions 1154 Note: During recursion into an "include" mechanism, an exp= modifier 1155 from the MUST NOT be used. In contrast, when executing 1156 a "redirect" modifier, an exp= modifier from the original domain MUST 1157 NOT be used. 1159 7. The Received-SPF Header Field 1161 It is RECOMMENDED that SMTP receivers record the result of SPF 1162 processing in the message header. If an SMTP receiver chooses to do 1163 so, it SHOULD use the "Received-SPF" header field defined here for 1164 each identity that was checked. This information is intended for the 1165 recipient. (Information intended for the sender is described in 1166 Section 6.2, Explanation.) 1168 The Received-SPF header field is a trace field (see [RFC2822] Section 1169 3.6.7) and SHOULD be prepended to the existing header, above the 1170 Received: field that is generated by the SMTP receiver. It MUST 1171 appear above all other Received-SPF fields in the message. The 1172 header field has the following format: 1174 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 1175 [ key-value-list ] CRLF 1177 result = "Pass" / "Fail" / "SoftFail" / "Neutral" / 1178 "None" / "TempError" / "PermError" 1180 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 1181 [";"] 1183 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 1185 key = "client-ip" / "envelope-from" / "helo" / 1186 "problem" / "receiver" / "identity" / 1187 mechanism / "x-" name / name 1189 identity = "mailfrom" ; for the "MAIL FROM" identity 1190 / "helo" ; for the "HELO" identity 1191 / name ; other identities 1193 dot-atom = 1194 quoted-string = 1195 comment = 1196 CFWS = 1197 FWS = 1198 CRLF = 1200 The header field SHOULD include a "(...)" style comment after the 1201 result, conveying supporting information for the result, such as 1202 , , and . 1204 The following key-value pairs are designed for later machine parsing. 1205 SPF clients SHOULD give enough information so that the SPF results 1206 can be verified. That is, at least "client-ip", "helo", and, if the 1207 "MAIL FROM" identity was checked, "envelope-from". 1209 client-ip the IP address of the SMTP client 1211 envelope-from the envelope sender mailbox 1213 helo the host name given in the HELO or EHLO command 1215 mechanism the mechanism that matched (if no mechanisms matched, 1216 substitute the word "default") 1218 problem if an error was returned, details about the error 1220 receiver the host name of the SPF client 1222 identity the identity that was checked; see the ABNF 1223 rule 1225 Other keys may be defined by SPF clients. Until a new key name 1226 becomes widely accepted, new key names should start with "x-". 1228 SPF clients MUST make sure that the Received-SPF header field does 1229 not contain invalid characters, is not excessively long, and does not 1230 contain malicious data that has been provided by the sender. 1232 Examples of various header styles that could be generated are the 1233 following: 1235 Received-SPF: Pass (mybox.example.org: domain of 1236 myname@example.com designates 192.0.2.1 as permitted sender) 1237 receiver=mybox.example.org; client-ip=192.0.2.1; 1238 envelope-from="myname@example.com"; helo=foo.example.com; 1240 Received-SPF: Fail (mybox.example.org: domain of 1241 myname@example.com does not designate 1242 192.0.2.1 as permitted sender) 1243 identity=mailfrom; client-ip=192.0.2.1; 1244 envelope-from="myname@example.com"; 1246 8. Macros 1248 8.1. Macro Definitions 1250 Many mechanisms and modifiers perform macro expansion on the term. 1252 domain-spec = macro-string domain-end 1253 domain-end = ( "." toplabel [ "." ] ) / macro-expand 1255 toplabel = ( *alphanum ALPHA *alphanum ) / 1256 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 1257 ; LDH rule plus additional TLD restrictions 1258 ; (see [RFC3696], Section 2) 1259 alphanum = ALPHA / DIGIT 1261 explain-string = *( macro-string / SP ) 1263 macro-string = *( macro-expand / macro-literal ) 1264 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 1265 / "%%" / "%_" / "%-" 1266 macro-literal = %x21-24 / %x26-7E 1267 ; visible characters except "%" 1268 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 1269 "c" / "r" / "t" / "v" 1270 transformers = *DIGIT [ "r" ] 1271 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 1273 A literal "%" is expressed by "%%". 1275 "%_" expands to a single " " space. 1276 "%-" expands to a URL-encoded space, viz., "%20". 1278 The following macro letters are expanded in term arguments: 1280 s = 1281 l = local-part of 1282 o = domain of 1283 d = 1284 i = 1285 p = the validated domain name of 1286 v = the string "in-addr" if is ipv4, or "ip6" if is ipv6 1287 h = HELO/EHLO domain 1289 The following macro letters are allowed only in "exp" text: 1291 c = SMTP client IP (easily readable format) 1292 r = domain name of host performing the check 1293 t = current timestamp 1295 A '%' character not followed by a '{', '%', '-', or '_' character is 1296 a syntax error. So 1297 -exists:%(ir).sbl.spamhaus.example.org 1298 is incorrect and will cause check_host() to return a "PermError". 1299 Instead, say 1300 -exists:%{ir}.sbl.spamhaus.example.org 1302 Optional transformers are the following: 1304 *DIGIT = zero or more digits 1305 'r' = reverse value, splitting on dots by default 1307 If transformers or delimiters are provided, the replacement value for 1308 a macro letter is split into parts. After performing any reversal 1309 operation and/or removal of left-hand parts, the parts are rejoined 1310 using "." and not the original splitting characters. 1312 By default, strings are split on "." (dots). Note that no special 1313 treatment is given to leading, trailing, or consecutive delimiters, 1314 and so the list of parts may contain empty strings. Older 1315 implementations of SPF prohibit trailing dots in domain names, so 1316 trailing dots should not be published by domain owners, although they 1317 must be accepted by implementations conforming to this document. 1318 Macros may specify delimiter characters that are used instead of ".". 1320 The 'r' transformer indicates a reversal operation: if the client IP 1321 address were 192.0.2.1, the macro %{i} would expand to "192.0.2.1" 1322 and the macro %{ir} would expand to "1.2.0.192". 1324 The DIGIT transformer indicates the number of right-hand parts to 1325 use, after optional reversal. If a DIGIT is specified, the value 1326 MUST be nonzero. If no DIGITs are specified, or if the value 1327 specifies more parts than are available, all the available parts are 1328 used. If the DIGIT was 5, and only 3 parts were available, the macro 1329 interpreter would pretend the DIGIT was 3. Implementations MUST 1330 support at least a value of 128, as that is the maximum number of 1331 labels in a domain name. 1333 The "s" macro expands to the argument. It is an E-Mail 1334 address with a localpart, an "@" character, and a domain. The "l" 1335 macro expands to just the localpart. The "o" macro expands to just 1336 the domain part. Note that these values remain the same during 1337 recursive and chained evaluations due to "include" and/or "redirect". 1338 Note also that if the original had no localpart, the 1339 localpart was set to "postmaster" in initial processing (see 1340 Section 4.3). 1342 For IPv4 addresses, both the "i" and "c" macros expand to the 1343 standard dotted-quad format. 1345 For IPv6 addresses, the "i" macro expands to a dot-format address; it 1346 is intended for use in %{ir}. The "c" macro may expand to any of the 1347 hexadecimal colon-format addresses specified in [RFC3513], Section 1348 2.2. It is intended for humans to read. 1350 The "p" macro expands to the validated domain name of . The 1351 procedure for finding the validated domain name is defined in 1352 Section 5.5. If the is present in the list of validated 1353 domains, it SHOULD be used. Otherwise, if a subdomain of the 1354 is present, it SHOULD be used. Otherwise, any name from the 1355 list may be used. If there are no validated domain names or if a DNS 1356 error occurs, the string "unknown" is used. 1358 The "r" macro expands to the name of the receiving MTA. This SHOULD 1359 be a fully qualified domain name, but if one does not exist (as when 1360 the checking is done by a MUA) or if policy restrictions dictate 1361 otherwise, the word "unknown" SHOULD be substituted. The domain name 1362 may be different from the name found in the MX record that the client 1363 MTA used to locate the receiving MTA. 1365 The "t" macro expands to the decimal representation of the 1366 approximate number of seconds since the Epoch (Midnight, January 1, 1367 1970, UTC). This is the same value as is returned by the POSIX 1368 time() function in most standards-compliant libraries. 1370 When the result of macro expansion is used in a domain name query, if 1371 the expanded domain name exceeds 253 characters (the maximum length 1372 of a domain name), the left side is truncated to fit, by removing 1373 successive domain labels until the total length does not exceed 253 1374 characters. 1376 Uppercased macros expand exactly as their lowercased equivalents, and 1377 are then URL escaped. URL escaping must be performed for characters 1378 not in the "unreserved" set, which is defined in [RFC3986]. 1380 Note: Care must be taken so that macro expansion for legitimate 1381 E-Mail does not exceed the 63-character limit on DNS labels. The 1382 localpart of E-Mail addresses, in particular, can have more than 63 1383 characters between dots. 1385 Note: Domains should avoid using the "s", "l", "o", or "h" macros in 1386 conjunction with any mechanism directive. Although these macros are 1387 powerful and allow per-user records to be published, they severely 1388 limit the ability of implementations to cache results of check_host() 1389 and they reduce the effectiveness of DNS caches. 1391 Implementations should be aware that if no directive processed during 1392 the evaluation of check_host() contains an "s", "l", "o", or "h" 1393 macro, then the results of the evaluation can be cached on the basis 1394 of and alone for as long as the shortest Time To Live 1395 (TTL) of all the DNS records involved. 1397 8.2. Expansion Examples 1399 The is strong-bad@email.example.com. 1400 The IPv4 SMTP client IP is 192.0.2.3. 1401 The IPv6 SMTP client IP is 2001:DB8::CB01. 1402 The PTR domain name of the client IP is mx.example.org. 1404 macro expansion 1405 ------- ---------------------------- 1406 %{s} strong-bad@email.example.com 1407 %{o} email.example.com 1408 %{d} email.example.com 1409 %{d4} email.example.com 1410 %{d3} email.example.com 1411 %{d2} example.com 1412 %{d1} com 1413 %{dr} com.example.email 1414 %{d2r} example.email 1415 %{l} strong-bad 1416 %{l-} strong.bad 1417 %{lr} strong-bad 1418 %{lr-} bad.strong 1419 %{l1r-} strong 1421 macro-string expansion 1422 -------------------------------------------------------------------- 1423 %{ir}.%{v}._spf.%{d2} 3.2.0.192.in-addr._spf.example.com 1424 %{lr-}.lp._spf.%{d2} bad.strong.lp._spf.example.com 1426 %{lr-}.lp.%{ir}.%{v}._spf.%{d2} 1427 bad.strong.lp.3.2.0.192.in-addr._spf.example.com 1429 %{ir}.%{v}.%{l1r-}.lp._spf.%{d2} 1430 3.2.0.192.in-addr.strong.lp._spf.example.com 1432 %{d2}.trusted-domains.example.net 1433 example.com.trusted-domains.example.net 1435 IPv6: 1436 %{ir}.%{v}._spf.%{d2} 1.0.B.C.0.0.0.0. 1437 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 1439 9. Implications 1441 This section outlines the major implications that adoption of this 1442 document will have on various entities involved in Internet E-Mail. 1443 It is intended to make clear to the reader where this document 1444 knowingly affects the operation of such entities. This section is 1445 not a "how-to" manual, or a "best practices" document, and it is not 1446 a comprehensive list of what such entities should do in light of this 1447 document. 1449 This section is non-normative. 1451 9.1. Sending Domains 1453 Domains that wish to be compliant with this specification will need 1454 to determine the list of hosts that they allow to use their domain 1455 name in the "HELO" and "MAIL FROM" identities. It is recognized that 1456 forming such a list is not just a simple technical exercise, but 1457 involves policy decisions with both technical and administrative 1458 considerations. 1460 It can be helpful to publish records that include a "tracking 1461 exists:" mechanism. By looking at the name server logs, a rough list 1462 may then be generated. For example: 1464 v=spf1 exists:_h.%{h}._l.%{l}._o.%{o}._i.%{i}._spf.%{d} ?all 1466 9.2. Mailing Lists 1468 Mailing lists must be aware of how they re-inject mail that is sent 1469 to the list. Mailing lists MUST comply with the requirements in 1470 [RFC2821], Section 3.10, and [RFC1123], Section 5.3.6, that say that 1471 the reverse-path MUST be changed to be the mailbox of a person or 1472 other entity who administers the list. Whereas the reasons for 1473 changing the reverse-path are many and long-standing, SPF adds 1474 enforcement to this requirement. 1476 In practice, almost all mailing list software in use already complies 1477 with this requirement. Mailing lists that do not comply may or may 1478 not encounter problems depending on how access to the list is 1479 restricted. Such lists that are entirely internal to a domain (only 1480 people in the domain can send to or receive from the list) are not 1481 affected. 1483 9.3. Forwarding Services and Aliases 1485 Forwarding services take mail that is received at a mailbox and 1486 direct it to some external mailbox. At the time of this writing, the 1487 near-universal practice of such services is to use the original "MAIL 1488 FROM" of a message when re-injecting it for delivery to the external 1489 mailbox. [RFC1123] and [RFC2821] describe this action as an "alias" 1490 rather than a "mail list". This means that the external mailbox's 1491 MTA sees all such mail in a connection from a host of the forwarding 1492 service, and so the "MAIL FROM" identity will not, in general, pass 1493 authorization. 1495 There are three places that techniques can be used to ameliorate this 1496 problem. 1498 1. The beginning, when E-Mail is first sent. 1500 1. "Neutral" results could be given for IP addresses that may be 1501 forwarders, instead of "Fail" results. For example: 1503 "v=spf1 mx -exists:%{ir}.sbl.spamhaus.example.org ?all" 1505 This would cause a lookup on an anti-spam DNS blacklist 1506 (DNSBL) and cause a result of "Fail" only for E-Mail coming 1507 from listed sources. All other E-Mail, including E-Mail sent 1508 through forwarders, would receive a "Neutral" result. By 1509 checking the DNSBL after the known good sources, problems 1510 with incorrect listing on the DNSBL are greatly reduced. 1512 2. The "MAIL FROM" identity could have additional information in 1513 the localpart that cryptographically identifies the mail as 1514 coming from an authorized source. In this case, such an SPF 1515 record could be used: 1517 "v=spf1 mx exists:%{l}._spf_verify.%{d} -all" 1519 Then, a specialized DNS server can be set up to serve the 1520 _spf_verify subdomain that validates the localpart. Although 1521 this requires an extra DNS lookup, this happens only when the 1522 E-Mail would otherwise be rejected as not coming from a known 1523 good source. 1524 Note that due to the 63-character limit for domain labels, 1525 this approach only works reliably if the localpart signature 1526 scheme is guaranteed either to only produce localparts with a 1527 maximum of 63 characters or to gracefully handle truncated 1528 localparts. 1530 3. Similarly, a specialized DNS server could be set up that will 1531 rate-limit the E-Mail coming from unexpected IP addresses. 1533 "v=spf1 mx exists:%{ir}._spf_rate.%{d} -all" 1535 4. SPF allows the creation of per-user policies for special 1536 cases. For example, the following SPF record and appropriate 1537 wildcard DNS records can be used: 1539 "v=spf1 mx redirect=%{l1r+}._at_.%{o}._spf.%{d}" 1541 2. The middle, when E-Mail is forwarded. 1543 1. Forwarding services can solve the problem by rewriting the 1544 "MAIL FROM" to be in their own domain. This means that mail 1545 bounced from the external mailbox will have to be re-bounced 1546 by the forwarding service. Various schemes to do this exist 1547 though they vary widely in complexity and resource 1548 requirements on the part of the forwarding service. 1550 2. Several popular MTAs can be forced from "alias" semantics to 1551 "mailing list" semantics by configuring an additional alias 1552 with "owner-" prepended to the original alias name (e.g., an 1553 alias of "friends: george@example.com, fred@example.org" 1554 would need another alias of the form "owner-friends: 1555 localowner"). 1557 3. The end, when E-Mail is received. 1559 1. If the owner of the external mailbox wishes to trust the 1560 forwarding service, he can direct the external mailbox's MTA 1561 to skip SPF tests when the client host belongs to the 1562 forwarding service. 1564 2. Tests against other identities, such as the "HELO" identity, 1565 may be used to override a failed test against the "MAIL FROM" 1566 identity. 1568 3. For larger domains, it may not be possible to have a complete 1569 or accurate list of forwarding services used by the owners of 1570 the domain's mailboxes. In such cases, whitelists of 1571 generally-recognized forwarding services could be employed. 1573 9.4. Mail Services 1575 Service providers that offer mail services to third-party domains, 1576 such as sending of bulk mail, may want to adjust their setup in light 1577 of the authorization check described in this document. If the "MAIL 1578 FROM" identity used for such E-Mail uses the domain of the service 1579 provider, then the provider needs only to ensure that its sending 1580 host is authorized by its own SPF record, if any. 1582 If the "MAIL FROM" identity does not use the mail service provider's 1583 domain, then extra care must be taken. The SPF record format has 1584 several options for the third-party domain to authorize the service 1585 provider's MTAs to send mail on its behalf. For mail service 1586 providers, such as ISPs, that have a wide variety of customers using 1587 the same MTA, steps should be taken to prevent cross-customer forgery 1588 (see Section 10.4). 1590 9.5. MTA Relays 1592 The authorization check generally precludes the use of arbitrary MTA 1593 relays between sender and receiver of an E-Mail message. 1595 Within an organization, MTA relays can be effectively deployed. 1596 However, for purposes of this document, such relays are effectively 1597 transparent. The SPF authorization check is a check between border 1598 MTAs of different domains. 1600 For mail senders, this means that published SPF records must 1601 authorize any MTAs that actually send across the Internet. Usually, 1602 these are just the border MTAs as internal MTAs simply forward mail 1603 to these MTAs for delivery. 1605 Mail receivers will generally want to perform the authorization check 1606 at the border MTAs, specifically including all secondary MXs. This 1607 allows mail that fails to be rejected during the SMTP session rather 1608 than bounced. Internal MTAs then do not perform the authorization 1609 test. To perform the authorization test other than at the border, 1610 the host that first transferred the message to the organization must 1611 be determined, which can be difficult to extract from the message 1612 header. Testing other than at the border is not recommended. 1614 10. Security Considerations 1616 10.1. Processing Limits 1618 As with most aspects of E-Mail, there are a number of ways that 1619 malicious parties could use the protocol as an avenue for a 1620 Denial-of-Service (DoS) attack. The processing limits outlined here 1621 are designed to prevent attacks such as the following: 1623 o A malicious party could create an SPF record with many references 1624 to a victim's domain and send many E-Mails to different SPF 1625 clients; those SPF clients would then create a DoS attack. In 1626 effect, the SPF clients are being used to amplify the attacker's 1627 bandwidth by using fewer bytes in the SMTP session than are used 1628 by the DNS queries. Using SPF clients also allows the attacker to 1629 hide the true source of the attack. 1631 o Whereas implementations of check_host() are supposed to limit the 1632 number of DNS lookups, malicious domains could publish records 1633 that exceed these limits in an attempt to waste computation effort 1634 at their targets when they send them mail. Malicious domains 1635 could also design SPF records that cause particular 1636 implementations to use excessive memory or CPU usage, or to 1637 trigger bugs. 1639 o Malicious parties could send a large volume of mail purporting to 1640 come from the intended target to a wide variety of legitimate mail 1641 hosts. These legitimate machines would then present a DNS load on 1642 the target as they fetched the relevant records. 1644 Of these, the case of a third party referenced in the SPF record is 1645 the easiest for a DoS attack to effectively exploit. As a result, 1646 limits that may seem reasonable for an individual mail server can 1647 still allow an unreasonable amount of bandwidth amplification. 1648 Therefore, the processing limits need to be quite low. 1650 SPF implementations MUST limit the number of mechanisms and modifiers 1651 that do DNS lookups to at most 10 per SPF check, including any 1652 lookups caused by the use of the "include" mechanism or the 1653 "redirect" modifier. If this number is exceeded during a check, a 1654 PermError MUST be returned. The "include", "a", "mx", "ptr", and 1655 "exists" mechanisms as well as the "redirect" modifier do count 1656 against this limit. The "all", "ip4", and "ip6" mechanisms do not 1657 require DNS lookups and therefore do not count against this limit. 1658 The "exp" modifier does not count against this limit because the DNS 1659 lookup to fetch the explanation string occurs after the SPF record 1660 has been evaluated. 1662 When evaluating the "mx" and "ptr" mechanisms, or the %{p} macro, 1663 there MUST be a limit of no more than 10 MX or PTR RRs looked up and 1664 checked. 1666 SPF implementations SHOULD limit the total amount of data obtained 1667 from the DNS queries. For example, when DNS over TCP or EDNS0 are 1668 available, there may need to be an explicit limit to how much data 1669 will be accepted to prevent excessive bandwidth usage or memory usage 1670 and DoS attacks. 1672 MTAs or other processors MAY also impose a limit on the maximum 1673 amount of elapsed time to evaluate check_host(). Such a limit SHOULD 1674 allow at least 20 seconds. If such a limit is exceeded, the result 1675 of authorization SHOULD be "TempError". 1677 Domains publishing records SHOULD try to keep the number of "include" 1678 mechanisms and chained "redirect" modifiers to a minimum. Domains 1679 SHOULD also try to minimize the amount of other DNS information 1680 needed to evaluate a record. This can be done by choosing directives 1681 that require less DNS information and placing lower-cost mechanisms 1682 earlier in the SPF record. 1684 For example, consider a domain set up as follows: 1686 example.com. IN MX 10 mx.example.com. 1687 mx.example.com. IN A 192.0.2.1 1688 a.example.com. IN TXT "v=spf1 mx:example.com -all" 1689 b.example.com. IN TXT "v=spf1 a:mx.example.com -all" 1690 c.example.com. IN TXT "v=spf1 ip4:192.0.2.1 -all" 1692 Evaluating check_host() for the domain "a.example.com" requires the 1693 MX records for "example.com", and then the A records for the listed 1694 hosts. Evaluating for "b.example.com" requires only the A records. 1695 Evaluating for "c.example.com" requires none. 1697 However, there may be administrative considerations: using "a" over 1698 "ip4" allows hosts to be renumbered easily. Using "mx" over "a" 1699 allows the set of mail hosts to be changed easily. 1701 10.2. SPF-Authorized E-Mail May Contain Other False Identities 1703 The "MAIL FROM" and "HELO" identity authorizations must not be 1704 construed to provide more assurance than they do. It is entirely 1705 possible for a malicious sender to inject a message using his own 1706 domain in the identities used by SPF, to have that domain's SPF 1707 record authorize the sending host, and yet the message can easily 1708 list other identities in its header. Unless the user or the MUA 1709 takes care to note that the authorized identity does not match the 1710 other more commonly-presented identities (such as the From: header 1711 field), the user may be lulled into a false sense of security. 1713 10.3. Spoofed DNS and IP Data 1715 There are two aspects of this protocol that malicious parties could 1716 exploit to undermine the validity of the check_host() function: 1718 o The evaluation of check_host() relies heavily on DNS. A malicious 1719 attacker could attack the DNS infrastructure and cause 1720 check_host() to see spoofed DNS data, and then return incorrect 1721 results. This could include returning "Pass" for an value 1722 where the actual domain's record would evaluate to "Fail". See 1723 [RFC3833] for a description of DNS weaknesses. 1725 o The client IP address, , is assumed to be correct. A 1726 malicious attacker could spoof TCP sequence numbers to make mail 1727 appear to come from a permitted host for a domain that the 1728 attacker is impersonating. 1730 10.4. Cross-User Forgery 1732 By definition, SPF policies just map domain names to sets of 1733 authorized MTAs, not whole E-Mail addresses to sets of authorized 1734 users. Although the "l" macro (Section 8) provides a limited way to 1735 define individual sets of authorized MTAs for specific E-Mail 1736 addresses, it is generally impossible to verify, through SPF, the use 1737 of specific E-Mail addresses by individual users of the same MTA. 1739 It is up to mail services and their MTAs to directly prevent 1740 cross-user forgery: based on SMTP AUTH ([RFC2554]), users should be 1741 restricted to using only those E-Mail addresses that are actually 1742 under their control (see [RFC4409], Section 6.1). Another means to 1743 verify the identity of individual users is message cryptography such 1744 as PGP ([RFC2440]) or S/MIME ([RFC3851]). 1746 10.5. Untrusted Information Sources 1748 SPF uses information supplied by third parties, such as the "HELO" 1749 domain name, the "MAIL FROM" address, and SPF records. This 1750 information is then passed to the receiver in the Received-SPF: trace 1751 fields and possibly returned to the client MTA in the form of an SMTP 1752 rejection message. This information must be checked for invalid 1753 characters and excessively long lines. 1755 When the authorization check fails, an explanation string may be 1756 included in the reject response. Both the sender and the rejecting 1757 receiver need to be aware that the explanation was determined by the 1758 publisher of the SPF record checked and, in general, not the 1759 receiver. The explanation may contain malicious URLs, or it may be 1760 offensive or misleading. 1762 This is probably less of a concern than it may initially seem since 1763 such messages are returned to the sender, and the explanation strings 1764 come from the sender policy published by the domain in the identity 1765 claimed by that very sender. As long as the DSN is not redirected to 1766 someone other than the actual sender, the only people who see 1767 malicious explanation strings are people whose messages claim to be 1768 from domains that publish such strings in their SPF records. In 1769 practice, DSNs can be misdirected, such as when an MTA accepts an 1770 E-Mail and then later generates a DSN to a forged address, or when an 1771 E-Mail forwarder does not direct the DSN back to the original sender. 1773 10.6. Privacy Exposure 1775 Checking SPF records causes DNS queries to be sent to the domain 1776 owner. These DNS queries, especially if they are caused by the 1777 "exists" mechanism, can contain information about who is sending 1778 E-Mail and likely to which MTA the E-Mail is being sent. This can 1779 introduce some privacy concerns, which may be more or less of an 1780 issue depending on local laws and the relationship between the domain 1781 owner and the person sending the E-Mail. 1783 11. Contributors and Acknowledgements 1785 This document is largely based on the work of Meng Weng Wong and Mark 1786 Lentczner. Although, as this section acknowledges, many people have 1787 contributed to this document, a very large portion of the writing and 1788 editing are due to Meng and Mark. 1790 This design owes a debt of parentage to [RMX] by Hadmut Danisch and 1791 to [DMP] by Gordon Fecyk. The idea of using a DNS record to check 1792 the legitimacy of an E-Mail address traces its ancestry further back 1793 through messages on the namedroppers mailing list by Paul Vixie 1794 [Vixie] (based on suggestion by Jim Miller) and by David Green 1795 [Green]. 1797 Philip Gladstone contributed the concept of macros to the 1798 specification, multiplying the expressiveness of the language and 1799 making per-user and per-IP lookups possible. 1801 The authors would also like to thank the literally hundreds of 1802 individuals who have participated in the development of this design. 1803 They are far too numerous to name, but they include the following: 1805 The folks on the spf-discuss mailing list. 1806 The folks on the SPAM-L mailing list. 1807 The folks on the IRTF ASRG mailing list. 1808 The folks on the IETF MARID mailing list. 1809 The folks on #perl. 1811 12. IANA Considerations 1813 12.1. The SPF DNS Record Type 1815 The IANA has assigned a new Resource Record Type and Qtype from the 1816 DNS Parameters Registry for the SPF RR type with code 99. 1818 12.2. The Received-SPF Mail Header Field 1820 Per [RFC3864], the "Received-SPF:" header field is added to the IANA 1821 Permanent Message Header Field Registry. The following is the 1822 registration template: 1824 Header field name: Received-SPF 1825 Applicable protocol: mail ([RFC2822]) 1826 Status: Standards Track 1827 Author/Change controller: IETF 1828 Specification document(s): RFC XXXX 1830 13. References 1832 13.1. Normative References 1834 [RFC1035] Mockapetris, P., "Domain names - implementation and 1835 specification", STD 13, RFC 1035, November 1987. 1837 [RFC1123] Braden, R., "Requirements for Internet Hosts - Application 1838 and Support", STD 3, RFC 1123, October 1989. 1840 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1841 Requirement Levels", BCP 14, RFC 2119, March 1997. 1843 [RFC2821] Klensin, J., "Simple Mail Transfer Protocol", RFC 2821, 1844 April 2001. 1846 [RFC2822] Resnick, P., "Internet Message Format", RFC 2822, 1847 April 2001. 1849 [RFC3464] Moore, K. and G. Vaudreuil, "An Extensible Message Format 1850 for Delivery Status Notifications", RFC 3464, 1851 January 2003. 1853 [RFC3513] Hinden, R. and S. Deering, "Internet Protocol Version 6 1854 (IPv6) Addressing Architecture", RFC 3513, April 2003. 1856 [RFC3864] Klyne, G., Nottingham, M., and J. Mogul, "Registration 1857 Procedures for Message Header Fields", BCP 90, RFC 3864, 1858 September 2004. 1860 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1861 Resource Identifier (URI): Generic Syntax", STD 66, 1862 RFC 3986, January 2005. 1864 [RFC4234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1865 Specifications: ABNF", RFC 4234, October 2005. 1867 [US-ASCII] 1868 American National Standards Institute (formerly United 1869 States of America Standards Institute), "USA Code for 1870 Information Interchange, X3.4", 1968. 1872 ANSI X3.4-1968 has been replaced by newer versions with 1873 slight modifications, but the 1968 version remains 1874 definitive for the Internet. 1876 13.2. Informative References 1878 [DMP] Fecyk, G., "Designated Mailers Protocol". 1880 Work In Progress 1882 [Green] Green, D., "Domain-Authorized SMTP Mail", 2002. 1884 [RFC1034] Mockapetris, P., "Domain names - concepts and facilities", 1885 STD 13, RFC 1034, November 1987. 1887 [RFC1983] Malkin, G., "Internet Users' Glossary", RFC 1983, 1888 August 1996. 1890 [RFC2440] Callas, J., Donnerhacke, L., Finney, H., and R. Thayer, 1891 "OpenPGP Message Format", RFC 2440, November 1998. 1893 [RFC2554] Myers, J., "SMTP Service Extension for Authentication", 1894 RFC 2554, March 1999. 1896 [RFC3696] Klensin, J., "Application Techniques for Checking and 1897 Transformation of Names", RFC 3696, February 2004. 1899 [RFC3833] Atkins, D. and R. Austein, "Threat Analysis of the Domain 1900 Name System (DNS)", RFC 3833, August 2004. 1902 [RFC3851] Ramsdell, B., "Secure/Multipurpose Internet Mail 1903 Extensions (S/MIME) Version 3.1 Message Specification", 1904 RFC 3851, July 2004. 1906 [RFC4408] Wong, M. and W. Schlitt, "Sender Policy Framework (SPF) 1907 for Authorizing Use of Domains in E-Mail, Version 1", 1908 RFC 4408, April 2006. 1910 [RFC4409] Gellens, R. and J. Klensin, "Message Submission for Mail", 1911 RFC 4409, April 2006. 1913 [RFC4871] Allman, E., Callas, J., Delany, M., Libbey, M., Fenton, 1914 J., and M. Thomas, "DomainKeys Identified Mail (DKIM) 1915 Signatures", RFC 4871, May 2007. 1917 [RFC5598] Crocker, D., "Internet Mail Architecture", RFC 5598, 1918 July 2009. 1920 [RMX] Danisch, H., "The RMX DNS RR Type for light weight sender 1921 authentication". 1923 Work In Progress 1925 [Vixie] Vixie, P., "Repudiating MAIL FROM", 2002. 1927 Appendix A. Collected ABNF 1929 This section is normative and any discrepancies with the ABNF 1930 fragments in the preceding text are to be resolved in favor of this 1931 grammar. 1933 See [RFC4234] for ABNF notation. Please note that as per this ABNF 1934 definition, literal text strings (those in quotes) are case- 1935 insensitive. Hence, "mx" matches "mx", "MX", "mX", and "Mx". 1937 record = version terms *SP 1938 version = "v=spf1" 1940 terms = *( 1*SP ( directive / modifier ) ) 1942 directive = [ qualifier ] mechanism 1943 qualifier = "+" / "-" / "?" / "~" 1944 mechanism = ( all / include 1945 / A / MX / PTR / IP4 / IP6 / exists ) 1947 all = "all" 1948 include = "include" ":" domain-spec 1949 A = "a" [ ":" domain-spec ] [ dual-cidr-length ] 1950 MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 1951 PTR = "ptr" [ ":" domain-spec ] 1952 IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 1953 IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 1954 exists = "exists" ":" domain-spec 1956 modifier = redirect / explanation / unknown-modifier 1957 redirect = "redirect" "=" domain-spec 1958 explanation = "exp" "=" domain-spec 1959 unknown-modifier = name "=" macro-string 1960 ; where name is not any known modifier 1962 ip4-cidr-length = "/" 1*DIGIT 1963 ip6-cidr-length = "/" 1*DIGIT 1964 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 1966 ip4-network = qnum "." qnum "." qnum "." qnum 1967 qnum = DIGIT ; 0-9 1968 / %x31-39 DIGIT ; 10-99 1969 / "1" 2DIGIT ; 100-199 1970 / "2" %x30-34 DIGIT ; 200-249 1971 / "25" %x30-35 ; 250-255 1972 ; conventional dotted quad notation. e.g., 192.0.2.0 1973 ip6-network = 1974 ; e.g., 2001:DB8::CD30 1976 domain-spec = macro-string domain-end 1977 domain-end = ( "." toplabel [ "." ] ) / macro-expand 1979 toplabel = ( *alphanum ALPHA *alphanum ) / 1980 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 1981 ; LDH rule plus additional TLD restrictions 1982 ; (see [RFC3696], Section 2) 1983 alphanum = ALPHA / DIGIT 1985 explain-string = *( macro-string / SP ) 1987 macro-string = *( macro-expand / macro-literal ) 1988 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 1989 / "%%" / "%_" / "%-" 1990 macro-literal = %x21-24 / %x26-7E 1991 ; visible characters except "%" 1992 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 1993 "c" / "r" / "t" 1994 transformers = *DIGIT [ "r" ] 1995 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 1997 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 1999 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 2000 [ key-value-list ] CRLF 2002 result = "Pass" / "Fail" / "SoftFail" / "Neutral" / 2003 "None" / "TempError" / "PermError" 2005 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 2006 [";"] 2008 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 2010 key = "client-ip" / "envelope-from" / "helo" / 2011 "problem" / "receiver" / "identity" / 2012 mechanism / "x-" name / name 2014 identity = "mailfrom" ; for the "MAIL FROM" identity 2015 / "helo" ; for the "HELO" identity 2016 / name ; other identities 2018 dot-atom = 2019 quoted-string = 2020 comment = 2021 CFWS = 2022 FWS = 2023 CRLF = 2025 Appendix B. Extended Examples 2027 These examples are based on the following DNS setup: 2029 ; A domain with two mail servers, two hosts 2030 ; and two servers at the domain name 2031 $ORIGIN example.com. 2032 @ MX 10 mail-a 2033 MX 20 mail-b 2034 A 192.0.2.10 2035 A 192.0.2.11 2036 amy A 192.0.2.65 2037 bob A 192.0.2.66 2038 mail-a A 192.0.2.129 2039 mail-b A 192.0.2.130 2040 www CNAME example.com. 2042 ; A related domain 2043 $ORIGIN example.org. 2044 @ MX 10 mail-c 2045 mail-c A 192.0.2.140 2047 ; The reverse IP for those addresses 2048 $ORIGIN 2.0.192.in-addr.arpa. 2049 10 PTR example.com. 2050 11 PTR example.com. 2051 65 PTR amy.example.com. 2052 66 PTR bob.example.com. 2053 129 PTR mail-a.example.com. 2054 130 PTR mail-b.example.com. 2055 140 PTR mail-c.example.org. 2057 ; A rogue reverse IP domain that claims to be 2058 ; something it's not 2059 $ORIGIN 0.0.10.in-addr.arpa. 2060 4 PTR bob.example.com. 2062 B.1. Simple Examples 2064 These examples show various possible published records for 2065 example.com and which values if would cause check_host() to 2066 return "Pass". Note that is "example.com". 2068 v=spf1 +all 2069 -- any passes 2071 v=spf1 a -all 2072 -- hosts 192.0.2.10 and 192.0.2.11 pass 2074 v=spf1 a:example.org -all 2075 -- no sending hosts pass since example.org has no A records 2077 v=spf1 mx -all 2078 -- sending hosts 192.0.2.129 and 192.0.2.130 pass 2080 v=spf1 mx:example.org -all 2081 -- sending host 192.0.2.140 passes 2083 v=spf1 mx mx:example.org -all 2084 -- sending hosts 192.0.2.129, 192.0.2.130, and 192.0.2.140 pass 2086 v=spf1 mx/30 mx:example.org/30 -all 2087 -- any sending host in 192.0.2.128/30 or 192.0.2.140/30 passes 2089 v=spf1 ptr -all 2090 -- sending host 192.0.2.65 passes (reverse DNS is valid and is in 2091 example.com) 2092 -- sending host 192.0.2.140 fails (reverse DNS is valid, but not 2093 in example.com) 2094 -- sending host 10.0.0.4 fails (reverse IP is not valid) 2096 v=spf1 ip4:192.0.2.128/28 -all 2097 -- sending host 192.0.2.65 fails 2098 -- sending host 192.0.2.129 passes 2100 B.2. Multiple Domain Example 2102 These examples show the effect of related records: 2104 example.org: "v=spf1 include:example.com include:example.net -all" 2106 This record would be used if mail from example.org actually came 2107 through servers at example.com and example.net. Example.org's 2108 designated servers are the union of example.com's and example.net's 2109 designated servers. 2111 la.example.org: "v=spf1 redirect=example.org" 2112 ny.example.org: "v=spf1 redirect=example.org" 2113 sf.example.org: "v=spf1 redirect=example.org" 2115 These records allow a set of domains that all use the same mail 2116 system to make use of that mail system's record. In this way, only 2117 the mail system's record needs to be updated when the mail setup 2118 changes. These domains' records never have to change. 2120 B.3. DNSBL Style Example 2122 Imagine that, in addition to the domain records listed above, there 2123 are these: 2125 $ORIGIN _spf.example.com. 2126 mary.mobile-users A 127.0.0.2 2127 fred.mobile-users A 127.0.0.2 2128 15.15.168.192.joel.remote-users A 127.0.0.2 2129 16.15.168.192.joel.remote-users A 127.0.0.2 2131 The following records describe users at example.com who mail from 2132 arbitrary servers, or who mail from personal servers. 2134 example.com: 2136 v=spf1 mx 2137 include:mobile-users._spf.%{d} 2138 include:remote-users._spf.%{d} 2139 -all 2141 mobile-users._spf.example.com: 2143 v=spf1 exists:%{l1r+}.%{d} 2145 remote-users._spf.example.com: 2147 v=spf1 exists:%{ir}.%{l1r+}.%{d} 2149 B.4. Multiple Requirements Example 2151 Say that your sender policy requires both that the IP address is 2152 within a certain range and that the reverse DNS for the IP matches. 2153 This can be done several ways, including the following: 2155 example.com. SPF ( "v=spf1 " 2156 "-include:ip4._spf.%{d} " 2157 "-include:ptr._spf.%{d} " 2158 "+all" ) 2159 ip4._spf.example.com. SPF "v=spf1 -ip4:192.0.2.0/24 +all" 2160 ptr._spf.example.com. SPF "v=spf1 -ptr +all" 2162 This example shows how the "-include" mechanism can be useful, how an 2163 SPF record that ends in "+all" can be very restrictive, and the use 2164 of De Morgan's Law. 2166 Appendix C. Change History 2168 Changes since RFC 4408 (to be removed prior to publication) 2170 Moved to standards track 2172 Authors updated 2174 IESG Note regarding experimental use replaced with discussion of 2175 results 2177 Process errata: 2179 Add %v macro to ABNF grammar 2181 Replace "uric" by "unreserved" 2183 Recommend an SMTP reply code for optional PermError rejections 2185 Correct syntax in Received-SPF examples 2187 Fix unknown-modifier clause is too greedy in ABNF 2189 Correct use of empty domain-spec on exp modifier 2191 Fix minor typo errata 2193 Appendix D. TODO 2195 Finish errata (PermError on invalid domains after macro expansion) 2197 Review DNS RCODE/TempError criteria 2199 Review SPF test suite ambiguous results for additional errata 2201 Authors' Addresses 2203 D. Scott Kitterman 2204 3611 Scheel Dr 2205 Ellicott City, MD 21042 2206 United States of America 2208 Email: scott@kitterman.com 2210 Wayne Schlitt 2211 4615 Meredeth #9 2212 Lincoln Nebraska, NE 68506 2213 United States of America 2215 Email: wayne@schlitt.net 2216 URI: http://www.schlitt.net/spf/