idnits 2.17.1 draft-kitterman-4408bis-01.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- == There are 1 instance of lines with non-RFC2606-compliant FQDNs in the document. == There are 7 instances of lines with non-RFC6890-compliant IPv4 addresses in the document. If these are example addresses, they should be changed. == There are 1 instance of lines with private range IPv4 addresses in the document. If these are generic example addresses, they should be changed to use any of the ranges defined in RFC 6890 (or successor): 192.0.2.x, 198.51.100.x or 203.0.113.x. -- 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 1203 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 (June 13, 2012) is 4306 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 1997, but not defined == Unused Reference: 'RFC4871' is defined on line 1905, but no explicit reference was found in the text == Unused Reference: 'RFC5598' is defined on line 1909, but no explicit reference was found in the text ** 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 (~~), 10 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 June 13, 2012 4 Obsoletes: 4408 (if approved) 5 Intended status: Standards Track 6 Expires: December 15, 2012 8 Sender Policy Framework (SPF) for Authorizing Use of Domains in E-Mail, 9 Version 1 10 draft-kitterman-4408bis-01.txt 12 Abstract 14 E-mail on the Internet can be forged in a number of ways. In 15 particular, existing protocols place no restriction on what a sending 16 host can use as the reverse-path of a message or the domain given on 17 the SMTP HELO/EHLO commands. This document describes version 1 of 18 the Sender Policy Framework (SPF) protocol, whereby a domain 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 December 15, 2012. 39 Copyright Notice 41 Copyright (c) 2012 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 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 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 SPF is widely deployed by large and small email providers alike. 206 There are multiple, interoperable implementations. 208 For SPF (as documented in RFC 4408) a careful effort was made to 209 collect and document lessons learned and errata during the two year 210 period. The errata list has been stable (no new submissions) and 211 only minor protocol lessons learned were identified. 213 1.3. Terminology 215 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 216 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 217 document are to be interpreted as described in [RFC2119]. 219 This document is concerned with the portion of a mail message 220 commonly called "envelope sender", "return path", "reverse path", 221 "bounce address", "2821 FROM", or "MAIL FROM". Since these terms are 222 either not well defined or often used casually, this document defines 223 the "MAIL FROM" identity in Section 2.2. Note that other terms that 224 may superficially look like the common terms, such as "reverse-path", 225 are used only with the defined meanings from normative documents. 227 2. Operation 229 2.1. The HELO Identity 231 The "HELO" identity derives from either the SMTP HELO or EHLO command 232 (see [RFC2821]). These commands supply the SMTP client (sending 233 host) for the SMTP session. Note that requirements for the domain 234 presented in the EHLO or HELO command are not always clear to the 235 sending party, and SPF clients must be prepared for the "HELO" 236 identity to be malformed or an IP address literal. At the time of 237 this writing, many legitimate E-Mails are delivered with invalid HELO 238 domains. 240 It is RECOMMENDED that SPF clients not only check the "MAIL FROM" 241 identity, but also separately check the "HELO" identity by applying 242 the check_host() function (Section 4) to the "HELO" identity as the 243 . 245 2.2. The MAIL FROM Identity 247 The "MAIL FROM" identity derives from the SMTP MAIL command (see 248 [RFC2821]). This command supplies the "reverse-path" for a message, 249 which generally consists of the sender mailbox, and is the mailbox to 250 which notification messages are to be sent if there are problems 251 delivering the message. 253 [RFC2821] allows the reverse-path to be null (see Section 4.5.5 in 254 RFC 2821). In this case, there is no explicit sender mailbox, and 255 such a message can be assumed to be a notification message from the 256 mail system itself. When the reverse-path is null, this document 257 defines the "MAIL FROM" identity to be the mailbox composed of the 258 localpart "postmaster" and the "HELO" identity (which may or may not 259 have been checked separately before). 261 SPF clients MUST check the "MAIL FROM" identity. SPF clients check 262 the "MAIL FROM" identity by applying the check_host() function to the 263 "MAIL FROM" identity as the . 265 2.3. Publishing Authorization 267 An SPF-compliant domain MUST publish a valid SPF record as described 268 in Section 3. This record authorizes the use of the domain name in 269 the "HELO" and "MAIL FROM" identities by the MTAs it specifies. 271 If domain owners choose to publish SPF records, it is RECOMMENDED 272 that they end in "-all", or redirect to other records that do, so 273 that a definitive determination of authorization can be made. 275 Domain holders may publish SPF records that explicitly authorize no 276 hosts if mail should never originate using that domain. 278 When changing SPF records, care must be taken to ensure that there is 279 a transition period so that the old policy remains valid until all 280 legitimate E-Mail has been checked. 282 2.4. Checking Authorization 284 A mail receiver can perform a set of SPF checks for each mail message 285 it receives. An SPF check tests the authorization of a client host 286 to emit mail with a given identity. Typically, such checks are done 287 by a receiving MTA, but can be performed elsewhere in the mail 288 processing chain so long as the required information is available and 289 reliable. At least the "MAIL FROM" identity MUST be checked, but it 290 is RECOMMENDED that the "HELO" identity also be checked beforehand. 292 Without explicit approval of the domain owner, checking other 293 identities against SPF version 1 records is NOT RECOMMENDED because 294 there are cases that are known to give incorrect results. For 295 example, almost all mailing lists rewrite the "MAIL FROM" identity 296 (see Section 9.2), but some do not change any other identities in the 297 message. The scenario described in Section 9.3, sub-section 1.2, is 298 another example. Documents that define other identities should 299 define the method for explicit approval. 301 It is possible that mail receivers will use the SPF check as part of 302 a larger set of tests on incoming mail. The results of other tests 303 may influence whether or not a particular SPF check is performed. 304 For example, finding the sending host's IP address on a local white 305 list may cause all other tests to be skipped and all mail from that 306 host to be accepted. 308 When a mail receiver decides to perform an SPF check, it MUST use a 309 correctly-implemented check_host() function (Section 4) evaluated 310 with the correct parameters. Although the test as a whole is 311 optional, once it has been decided to perform a test it must be 312 performed as specified so that the correct semantics are preserved 313 between publisher and receiver. 315 To make the test, the mail receiver MUST evaluate the check_host() 316 function with the arguments set as follows: 318 - the IP address of the SMTP client that is emitting the 319 mail, either IPv4 or IPv6. 321 - the domain portion of the "MAIL FROM" or "HELO" identity. 323 - the "MAIL FROM" or "HELO" identity. 325 Note that the argument may not be a well-formed domain name. 326 For example, if the reverse-path was null, then the EHLO/HELO domain 327 is used, with its associated problems (see Section 2.1). In these 328 cases, check_host() is defined in Section 4.3 to return a "None" 329 result. 331 Although invalid, malformed, or non-existent domains cause SPF checks 332 to return "None" because no SPF record can be found, it has long been 333 the policy of many MTAs to reject E-Mail from such domains, 334 especially in the case of invalid "MAIL FROM". In order to prevent 335 the circumvention of SPF records, rejecting E-Mail from invalid 336 domains should be considered. 338 Implementations must take care to correctly extract the from 339 the data given with the SMTP MAIL FROM command as many MTAs will 340 still accept such things as source routes (see [RFC2821], Appendix 341 C), the %-hack (see [RFC1123]), and bang paths (see [RFC1983]). 342 These archaic features have been maliciously used to bypass security 343 systems. 345 2.5. Interpreting the Result 347 This section describes how software that performs the authorization 348 should interpret the results of the check_host() function. The 349 authorization check SHOULD be performed during the processing of the 350 SMTP transaction that sends the mail. This allows errors to be 351 returned directly to the sending MTA by way of SMTP replies. 353 Performing the authorization after the SMTP transaction has finished 354 may cause problems, such as the following: (1) It may be difficult to 355 accurately extract the required information from potentially 356 deceptive headers; (2) legitimate E-Mail may fail because the 357 sender's policy may have since changed. 359 Generating non-delivery notifications to forged identities that have 360 failed the authorization check is generally abusive and against the 361 explicit wishes of the identity owner. 363 2.5.1. None 365 A result of "None" means that no records were published by the domain 366 or that no checkable sender domain could be determined from the given 367 identity. The checking software cannot ascertain whether or not the 368 client host is authorized. 370 2.5.2. Neutral 372 The domain owner has explicitly stated that he cannot or does not 373 want to assert whether or not the IP address is authorized. A 374 "Neutral" result MUST be treated exactly like the "None" result; the 375 distinction exists only for informational purposes. Treating 376 "Neutral" more harshly than "None" would discourage domain owners 377 from testing the use of SPF records (see Section 9.1). 379 2.5.3. Pass 381 A "Pass" result means that the client is authorized to inject mail 382 with the given identity. The domain can now, in the sense of 383 reputation, be considered responsible for sending the message. 384 Further policy checks can now proceed with confidence in the 385 legitimate use of the identity. 387 2.5.4. Fail 389 A "Fail" result is an explicit statement that the client is not 390 authorized to use the domain in the given identity. The checking 391 software can choose to mark the mail based on this or to reject the 392 mail outright. 394 If the checking software chooses to reject the mail during the SMTP 395 transaction, then it SHOULD use an SMTP reply code of 550 (see 396 [RFC2821]) and, if supported, the 5.7.1 Delivery Status Notification 397 (DSN) code (see [RFC3464]), in addition to an appropriate reply text. 398 The check_host() function may return either a default explanation 399 string or one from the domain that published the SPF records (see 400 Section 6.2). If the information does not originate with the 401 checking software, it should be made clear that the text is provided 402 by the sender's domain. For example: 404 550-5.7.1 SPF MAIL FROM check failed: 405 550-5.7.1 The domain example.com explains: 406 550 5.7.1 Please see http://www.example.com/mailpolicy.html 408 2.5.5. SoftFail 410 A "SoftFail" result should be treated as somewhere between a "Fail" 411 and a "Neutral". The domain believes the host is not authorized but 412 is not willing to make that strong of a statement. Receiving 413 software SHOULD NOT reject the message based solely on this result, 414 but MAY subject the message to closer scrutiny than normal. 416 The domain owner wants to discourage the use of this host and thus 417 desires limited feedback when a "SoftFail" result occurs. For 418 example, the recipient's Mail User Agent (MUA) could highlight the 419 "SoftFail" status, or the receiving MTA could give the sender a 420 message using a technique called "greylisting" whereby the MTA can 421 issue an SMTP reply code of 451 (4.3.0 DSN code) with a note the 422 first time the message is received, but accept it the second time. 424 2.5.6. TempError 426 A "TempError" result means that the SPF client encountered a 427 transient error while performing the check. Checking software can 428 choose to accept or temporarily reject the message. If the message 429 is rejected during the SMTP transaction for this reason, the software 430 SHOULD use an SMTP reply code of 451 and, if supported, the 4.4.3 DSN 431 code. 433 2.5.7. PermError 435 A "PermError" result means that the domain's published records could 436 not be correctly interpreted. This signals an error condition that 437 requires manual intervention to be resolved, as opposed to the 438 TempError result. If the message is rejected during the SMTP 439 transaction for this reason, the software SHOULD use an SMTP reply 440 code of 550 and, if supported, the 5.5.2 DSN code. Be aware that if 441 the domain owner uses macros (Section 8), it is possible that this 442 result is due to the checked identities having an unexpected format. 444 3. SPF Records 446 An SPF record is a DNS Resource Record (RR) that declares which hosts 447 are, and are not, authorized to use a domain name for the "HELO" and 448 "MAIL FROM" identities. Loosely, the record partitions all hosts 449 into permitted and not-permitted sets (though some hosts might fall 450 into neither category). 452 The SPF record is a single string of text. An example record is the 453 following: 455 v=spf1 +mx a:colo.example.com/28 -all 457 This record has a version of "spf1" and three directives: "+mx", 458 "a:colo.example.com/28" (the + is implied), and "-all". 460 3.1. Publishing 462 Domain owners wishing to be SPF compliant must publish SPF records 463 for the hosts that are used in the "MAIL FROM" and "HELO" identities. 464 The SPF records are placed in the DNS tree at the host name it 465 pertains to, not a subdomain under it, such as is done with SRV 466 records. This is the same whether the TXT or SPF RR type (see 467 Section 3.1.1) is used. 469 The example above in Section 3 might be published via these lines in 470 a domain zone file: 472 example.com. TXT "v=spf1 +mx a:colo.example.com/28 -all" 473 smtp-out.example.com. TXT "v=spf1 a -all" 475 When publishing via TXT records, beware of other TXT records 476 published there for other purposes. They may cause problems with 477 size limits (see Section 3.1.4). 479 3.1.1. DNS Resource Record Types 481 This document defines a new DNS RR of type SPF, code 99. The format 482 of this type is identical to the TXT RR [RFC1035]. For either type, 483 the character content of the record is encoded as [US-ASCII]. 485 It is recognized that the current practice (using a TXT record) is 486 not optimal, but it is necessary because there are a number of DNS 487 server and resolver implementations in common use that cannot handle 488 the new RR type. The two-record-type scheme provides a forward path 489 to the better solution of using an RR type reserved for this purpose. 491 An SPF-compliant domain name SHOULD have SPF records of both RR 492 types. A compliant domain name MUST have a record of at least one 493 type. If a domain has records of both types, they MUST have 494 identical content. For example, instead of publishing just one 495 record as in Section 3.1 above, it is better to publish: 497 example.com. IN TXT "v=spf1 +mx a:colo.example.com/28 -all" 498 example.com. IN SPF "v=spf1 +mx a:colo.example.com/28 -all" 500 Example RRs in this document are shown with the TXT record type; 501 however, they could be published with the SPF type or with both 502 types. 504 3.1.2. Multiple DNS Records 506 A domain name MUST NOT have multiple records that would cause an 507 authorization check to select more than one record. See Section 4.5 508 for the selection rules. 510 3.1.3. Multiple Strings in a Single DNS record 512 As defined in [RFC1035] sections 3.3.14 and 3.3, a single text DNS 513 record (either TXT or SPF RR types) can be composed of more than one 514 string. If a published record contains multiple strings, then the 515 record MUST be treated as if those strings are concatenated together 516 without adding spaces. For example: 518 IN TXT "v=spf1 .... first" "second string..." 520 MUST be treated as equivalent to 522 IN TXT "v=spf1 .... firstsecond string..." 524 SPF or TXT records containing multiple strings are useful in 525 constructing records that would exceed the 255-byte maximum length of 526 a string within a single TXT or SPF RR record. 528 3.1.4. Record Size 530 The published SPF record for a given domain name SHOULD remain small 531 enough that the results of a query for it will fit within 512 octets. 532 This will keep even older DNS implementations from falling over to 533 TCP. Since the answer size is dependent on many things outside the 534 scope of this document, it is only possible to give this guideline: 535 If the combined length of the DNS name and the text of all the 536 records of a given type (TXT or SPF) is under 450 characters, then 537 DNS answers should fit in UDP packets. Note that when computing the 538 sizes for queries of the TXT format, one must take into account any 539 other TXT records published at the domain name. Records that are too 540 long to fit in a single UDP packet MAY be silently ignored by SPF 541 clients. 543 3.1.5. Wildcard Records 545 Use of wildcard records for publishing is not recommended. Care must 546 be taken if wildcard records are used. If a domain publishes 547 wildcard MX records, it may want to publish wildcard declarations, 548 subject to the same requirements and problems. In particular, the 549 declaration must be repeated for any host that has any RR records at 550 all, and for subdomains thereof. For example, the example given in 551 [RFC1034], Section 4.3.3, could be extended with the following: 553 X.COM. MX 10 A.X.COM 554 X.COM. TXT "v=spf1 a:A.X.COM -all" 556 *.X.COM. MX 10 A.X.COM 557 *.X.COM. TXT "v=spf1 a:A.X.COM -all" 559 A.X.COM. A 1.2.3.4 560 A.X.COM. MX 10 A.X.COM 561 A.X.COM. TXT "v=spf1 a:A.X.COM -all" 563 *.A.X.COM. MX 10 A.X.COM 564 *.A.X.COM. TXT "v=spf1 a:A.X.COM -all" 566 Notice that SPF records must be repeated twice for every name within 567 the domain: once for the name, and once with a wildcard to cover the 568 tree under the name. 570 Use of wildcards is discouraged in general as they cause every name 571 under the domain to exist and queries against arbitrary names will 572 never return RCODE 3 (Name Error). 574 4. The check_host() Function 576 The check_host() function fetches SPF records, parses them, and 577 interprets them to determine whether a particular host is or is not 578 permitted to send mail with a given identity. Mail receivers that 579 perform this check MUST correctly evaluate the check_host() function 580 as described here. 582 Implementations MAY use a different algorithm than the canonical 583 algorithm defined here, so long as the results are the same in all 584 cases. 586 4.1. Arguments 588 The check_host() function takes these arguments: 590 - the IP address of the SMTP client that is emitting the 591 mail, either IPv4 or IPv6. 593 - the domain that provides the sought-after authorization 594 information; initially, the domain portion of the "MAIL 595 FROM" or "HELO" identity. 597 - the "MAIL FROM" or "HELO" identity. 599 The domain portion of will usually be the same as the 600 argument when check_host() is initially evaluated. However, 601 this will generally not be true for recursive evaluations (see 602 Section 5.2 below). 604 Actual implementations of the check_host() function may need 605 additional arguments. 607 4.2. Results 609 The function check_host() can return one of several results described 610 in Section 2.5. Based on the result, the action to be taken is 611 determined by the local policies of the receiver. 613 4.3. Initial Processing 615 If the is malformed (label longer than 63 characters, zero- 616 length label not at the end, etc.) or is not a fully qualified domain 617 name, or if the DNS lookup returns "domain does not exist" (RCODE 3), 618 check_host() immediately returns the result "None". 620 If the has no localpart, substitute the string "postmaster" 621 for the localpart. 623 4.4. Record Lookup 625 In accordance with how the records are published (see Section 3.1 626 above), a DNS query needs to be made for the name, querying 627 for either RR type TXT, SPF, or both. If both SPF and TXT RRs are 628 looked up, the queries MAY be done in parallel. 630 If all DNS lookups that are made return a server failure (RCODE 2), 631 or other error (RCODE other than 0 or 3), or time out, then 632 check_host() exits immediately with the result "TempError". 634 4.5. Selecting Records 636 Records begin with a version section: 638 record = version terms *SP 639 version = "v=spf1" 641 Starting with the set of records that were returned by the lookup, 642 record selection proceeds in two steps: 644 1. Records that do not begin with a version section of exactly 645 "v=spf1" are discarded. Note that the version section is 646 terminated either by an SP character or the end of the record. A 647 record with a version section of "v=spf10" does not match and 648 must be discarded. 650 2. If any records of type SPF are in the set, then all records of 651 type TXT are discarded. 653 After the above steps, there should be exactly one record remaining 654 and evaluation can proceed. If there are two or more records 655 remaining, then check_host() exits immediately with the result of 656 "PermError". 658 If no matching records are returned, an SPF client MUST assume that 659 the domain makes no SPF declarations. SPF processing MUST stop and 660 return "None". 662 4.6. Record Evaluation 664 After one SPF record has been selected, the check_host() function 665 parses and interprets it to find a result for the current test. If 666 there are any syntax errors, check_host() returns immediately with 667 the result "PermError". 669 Implementations MAY choose to parse the entire record first and 670 return "PermError" if the record is not syntactically well formed. 672 However, in all cases, any syntax errors anywhere in the record MUST 673 be detected. 675 4.6.1. Term Evaluation 677 There are two types of terms: mechanisms and modifiers. A record 678 contains an ordered list of these as specified in the following 679 Augmented Backus-Naur Form (ABNF). 681 terms = *( 1*SP ( directive / modifier ) ) 683 directive = [ qualifier ] mechanism 684 qualifier = "+" / "-" / "?" / "~" 685 mechanism = ( all / include 686 / A / MX / PTR / IP4 / IP6 / exists ) 687 modifier = redirect / explanation / unknown-modifier 688 unknown-modifier = name "=" macro-string 689 ; where name is not any known modifier 691 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 693 Most mechanisms allow a ":" or "/" character after the name. 695 Modifiers always contain an equals ('=') character immediately after 696 the name, and before any ":" or "/" characters that may be part of 697 the macro-string. 699 Terms that do not contain any of "=", ":", or "/" are mechanisms, as 700 defined in Section 5. 702 As per the definition of the ABNF notation in [RFC4234], mechanism 703 and modifier names are case-insensitive. 705 4.6.2. Mechanisms 707 Each mechanism is considered in turn from left to right. If there 708 are no more mechanisms, the result is specified in Section 4.7. 710 When a mechanism is evaluated, one of three things can happen: it can 711 match, not match, or throw an exception. 713 If it matches, processing ends and the qualifier value is returned as 714 the result of that record. If it does not match, processing 715 continues with the next mechanism. If it throws an exception, 716 mechanism processing ends and the exception value is returned. 718 The possible qualifiers, and the results they return are as follows: 720 "+" Pass 721 "-" Fail 722 "~" SoftFail 723 "?" Neutral 725 The qualifier is optional and defaults to "+". 727 When a mechanism matches and the qualifier is "-", then a "Fail" 728 result is returned and the explanation string is computed as 729 described in Section 6.2. 731 The specific mechanisms are described in Section 5. 733 4.6.3. Modifiers 735 Modifiers are not mechanisms: they do not return match or not-match. 736 Instead they provide additional information. Although modifiers do 737 not directly affect the evaluation of the record, the "redirect" 738 modifier has an effect after all the mechanisms have been evaluated. 740 4.7. Default Result 742 If none of the mechanisms match and there is no "redirect" modifier, 743 then the check_host() returns a result of "Neutral", just as if 744 "?all" were specified as the last directive. If there is a 745 "redirect" modifier, check_host() proceeds as defined in Section 6.1. 747 Note that records SHOULD always use either a "redirect" modifier or 748 an "all" mechanism to explicitly terminate processing. 750 For example: 752 v=spf1 +mx -all 753 or 754 v=spf1 +mx redirect=_spf.example.com 756 4.8. Domain Specification 758 Several of these mechanisms and modifiers have a domain-spec section. 759 The domain-spec string is macro expanded (see Section 8). The 760 resulting string is the common presentation form of a fully-qualified 761 DNS name: a series of labels separated by periods. This domain is 762 called the in the rest of this document. 764 Note: The result of the macro expansion is not subject to any further 765 escaping. Hence, this facility cannot produce all characters that 766 are legal in a DNS label (e.g., the control characters). However, 767 this facility is powerful enough to express legal host names and 768 common utility labels (such as "_spf") that are used in DNS. 770 For several mechanisms, the is optional. If it is not 771 provided, the is used as the . 773 5. Mechanism Definitions 775 This section defines two types of mechanisms. 777 Basic mechanisms contribute to the language framework. They do not 778 specify a particular type of authorization scheme. 780 all 781 include 783 Designated sender mechanisms are used to designate a set of 784 addresses as being permitted or not permitted to use the for 785 sending mail. 787 a 788 mx 789 ptr 790 ip4 791 ip6 792 exists 794 The following conventions apply to all mechanisms that perform a 795 comparison between and an IP address at any point: 797 If no CIDR-length is given in the directive, then and the IP 798 address are compared for equality. (Here, CIDR is Classless Inter- 799 Domain Routing.) 801 If a CIDR-length is specified, then only the specified number of 802 high-order bits of and the IP address are compared for equality. 804 When any mechanism fetches host addresses to compare with , when 805 is an IPv4 address, A records are fetched, when is an IPv6 806 address, AAAA records are fetched. Even if the SMTP connection is 807 via IPv6, an IPv4-mapped IPv6 IP address (see [RFC3513], Section 808 2.5.5) MUST still be considered an IPv4 address. 810 Several mechanisms rely on information fetched from DNS. For these 811 DNS queries, except where noted, if the DNS server returns an error 812 (RCODE other than 0 or 3) or the query times out, the mechanism 813 throws the exception "TempError". If the server returns "domain does 814 not exist" (RCODE 3), then evaluation of the mechanism continues as 815 if the server returned no error (RCODE 0) and zero answer records. 817 5.1. "all" 819 all = "all" 820 The "all" mechanism is a test that always matches. It is used as the 821 rightmost mechanism in a record to provide an explicit default. 823 For example: 825 v=spf1 a mx -all 827 Mechanisms after "all" will never be tested. Any "redirect" modifier 828 (Section 6.1) has no effect when there is an "all" mechanism. 830 5.2. "include" 832 include = "include" ":" domain-spec 834 The "include" mechanism triggers a recursive evaluation of 835 check_host(). The domain-spec is expanded as per Section 8. Then 836 check_host() is evaluated with the resulting string as the . 837 The and arguments remain the same as in the current 838 evaluation of check_host(). 840 In hindsight, the name "include" was poorly chosen. Only the 841 evaluated result of the referenced SPF record is used, rather than 842 acting as if the referenced SPF record was literally included in the 843 first. For example, evaluating a "-all" directive in the referenced 844 record does not terminate the overall processing and does not 845 necessarily result in an overall "Fail". (Better names for this 846 mechanism would have been "if-pass", "on-pass", etc.) 848 The "include" mechanism makes it possible for one domain to designate 849 multiple administratively-independent domains. For example, a vanity 850 domain "example.net" might send mail using the servers of 851 administratively-independent domains example.com and example.org. 853 Example.net could say 855 IN TXT "v=spf1 include:example.com include:example.org -all" 857 This would direct check_host() to, in effect, check the records of 858 example.com and example.org for a "Pass" result. Only if the host 859 were not permitted for either of those domains would the result be 860 "Fail". 862 Whether this mechanism matches, does not match, or throws an 863 exception depends on the result of the recursive evaluation of 864 check_host(): 866 +---------------------------------+---------------------------------+ 867 | A recursive check_host() result | Causes the "include" mechanism | 868 | of: | to: | 869 +---------------------------------+---------------------------------+ 870 | Pass | match | 871 | | | 872 | Fail | not match | 873 | | | 874 | SoftFail | not match | 875 | | | 876 | Neutral | not match | 877 | | | 878 | TempError | throw TempError | 879 | | | 880 | PermError | throw PermError | 881 | | | 882 | None | throw PermError | 883 +---------------------------------+---------------------------------+ 885 The "include" mechanism is intended for crossing administrative 886 boundaries. Although it is possible to use includes to consolidate 887 multiple domains that share the same set of designated hosts, domains 888 are encouraged to use redirects where possible, and to minimize the 889 number of includes within a single administrative domain. For 890 example, if example.com and example.org were managed by the same 891 entity, and if the permitted set of hosts for both domains was 892 "mx:example.com", it would be possible for example.org to specify 893 "include:example.com", but it would be preferable to specify 894 "redirect=example.com" or even "mx:example.com". 896 5.3. "a" 898 This mechanism matches if is one of the 's IP 899 addresses. 901 A = "a" [ ":" domain-spec ] [ dual-cidr-length ] 903 An address lookup is done on the . The is compared 904 to the returned address(es). If any address matches, the mechanism 905 matches. 907 5.4. "mx" 909 This mechanism matches if is one of the MX hosts for a domain 910 name. 912 MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 913 check_host() first performs an MX lookup on the . Then 914 it performs an address lookup on each MX name returned. The is 915 compared to each returned IP address. To prevent Denial of Service 916 (DoS) attacks, more than 10 MX names MUST NOT be looked up during the 917 evaluation of an "mx" mechanism (see Section 10). If any address 918 matches, the mechanism matches. 920 Note regarding implicit MXs: If the has no MX records, 921 check_host() MUST NOT pretend the target is its single MX, and MUST 922 NOT default to an A lookup on the directly. This 923 behavior breaks with the legacy "implicit MX" rule. See [RFC2821], 924 Section 5. If such behavior is desired, the publisher should specify 925 an "a" directive. 927 5.5. "ptr" 929 This mechanism tests whether the DNS reverse-mapping for exists 930 and correctly points to a domain name within a particular domain. 932 PTR = "ptr" [ ":" domain-spec ] 934 First, the 's name is looked up using this procedure: perform a 935 DNS reverse-mapping for , looking up the corresponding PTR record 936 in "in-addr.arpa." if the address is an IPv4 one and in "ip6.arpa." 937 if it is an IPv6 address. For each record returned, validate the 938 domain name by looking up its IP address. To prevent DoS attacks, 939 more than 10 PTR names MUST NOT be looked up during the evaluation of 940 a "ptr" mechanism (see Section 10). If is among the returned IP 941 addresses, then that domain name is validated. In pseudocode: 943 sending-domain_names := ptr_lookup(sending-host_IP); 944 if more than 10 sending-domain_names are found, use at most 10. 945 for each name in (sending-domain_names) { 946 IP_addresses := a_lookup(name); 947 if the sending-domain_IP is one of the IP_addresses { 948 validated-sending-domain_names += name; 949 } 950 } 952 Check all validated domain names to see if they end in the 953 domain. If any do, this mechanism matches. If no 954 validated domain name can be found, or if none of the validated 955 domain names end in the , this mechanism fails to match. 956 If a DNS error occurs while doing the PTR RR lookup, then this 957 mechanism fails to match. If a DNS error occurs while doing an A RR 958 lookup, then that domain name is skipped and the search continues. 960 Pseudocode: 962 for each name in (validated-sending-domain_names) { 963 if name ends in , return match. 964 if name is , return match. 965 } 966 return no-match. 968 This mechanism matches if the is either an ancestor of 969 a validated domain name or if the and a validated 970 domain name are the same. For example: "mail.example.com" is within 971 the domain "example.com", but "mail.bad-example.com" is not. 973 Note: Use of this mechanism is discouraged because it is slow, it is 974 not as reliable as other mechanisms in cases of DNS errors, and it 975 places a large burden on the arpa name servers. If used, proper PTR 976 records must be in place for the domain's hosts and the "ptr" 977 mechanism should be one of the last mechanisms checked. 979 5.6. "ip4" and "ip6" 981 These mechanisms test whether is contained within a given IP 982 network. 984 IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 985 IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 987 ip4-cidr-length = "/" 1*DIGIT 988 ip6-cidr-length = "/" 1*DIGIT 989 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 991 ip4-network = qnum "." qnum "." qnum "." qnum 992 qnum = DIGIT ; 0-9 993 / %x31-39 DIGIT ; 10-99 994 / "1" 2DIGIT ; 100-199 995 / "2" %x30-34 DIGIT ; 200-249 996 / "25" %x30-35 ; 250-255 997 ; as per conventional dotted quad notation. e.g., 192.0.2.0 998 ip6-network = 999 ; e.g., 2001:DB8::CD30 1001 The is compared to the given network. If CIDR-length high-order 1002 bits match, the mechanism matches. 1004 If ip4-cidr-length is omitted, it is taken to be "/32". If 1005 ip6-cidr-length is omitted, it is taken to be "/128". It is not 1006 permitted to omit parts of the IP address instead of using CIDR 1007 notations. That is, use 192.0.2.0/24 instead of 192.0.2. 1009 5.7. "exists" 1011 This mechanism is used to construct an arbitrary domain name that is 1012 used for a DNS A record query. It allows for complicated schemes 1013 involving arbitrary parts of the mail envelope to determine what is 1014 permitted. 1016 exists = "exists" ":" domain-spec 1018 The domain-spec is expanded as per Section 8. The resulting domain 1019 name is used for a DNS A RR lookup. If any A record is returned, 1020 this mechanism matches. The lookup type is A even when the 1021 connection type is IPv6. 1023 Domains can use this mechanism to specify arbitrarily complex 1024 queries. For example, suppose example.com publishes the record: 1026 v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all 1028 The might expand to 1029 "1.2.0.192.someuser._spf.example.com". This makes fine-grained 1030 decisions possible at the level of the user and client IP address. 1032 This mechanism enables queries that mimic the style of tests that 1033 existing anti-spam DNS blacklists (DNSBL) use. 1035 6. Modifier Definitions 1037 Modifiers are name/value pairs that provide additional information. 1038 Modifiers always have an "=" separating the name and the value. 1040 The modifiers defined in this document ("redirect" and "exp") MAY 1041 appear anywhere in the record, but SHOULD appear at the end, after 1042 all mechanisms. Ordering of these two modifiers does not matter. 1043 These two modifiers MUST NOT appear in a record more than once each. 1044 If they do, then check_host() exits with a result of "PermError". 1046 Unrecognized modifiers MUST be ignored no matter where in a record, 1047 or how often. This allows implementations of this document to 1048 gracefully handle records with modifiers that are defined in other 1049 specifications. 1051 6.1. redirect: Redirected Query 1053 If all mechanisms fail to match, and a "redirect" modifier is 1054 present, then processing proceeds as follows: 1056 redirect = "redirect" "=" domain-spec 1058 The domain-spec portion of the redirect section is expanded as per 1059 the macro rules in Section 8. Then check_host() is evaluated with 1060 the resulting string as the . The and 1061 arguments remain the same as in the current evaluation of 1062 check_host(). 1064 The result of this new evaluation of check_host() is then considered 1065 the result of the current evaluation with the exception that if no 1066 SPF record is found, or if the target-name is malformed, the result 1067 is a "PermError" rather than "None". 1069 Note that the newly-queried domain may itself specify redirect 1070 processing. 1072 This facility is intended for use by organizations that wish to apply 1073 the same record to multiple domains. For example: 1075 la.example.com. TXT "v=spf1 redirect=_spf.example.com" 1076 ny.example.com. TXT "v=spf1 redirect=_spf.example.com" 1077 sf.example.com. TXT "v=spf1 redirect=_spf.example.com" 1078 _spf.example.com. TXT "v=spf1 mx:example.com -all" 1080 In this example, mail from any of the three domains is described by 1081 the same record. This can be an administrative advantage. 1083 Note: In general, the domain "A" cannot reliably use a redirect to 1084 another domain "B" not under the same administrative control. Since 1085 the stays the same, there is no guarantee that the record at 1086 domain "B" will correctly work for mailboxes in domain "A", 1087 especially if domain "B" uses mechanisms involving localparts. An 1088 "include" directive may be more appropriate. 1090 For clarity, it is RECOMMENDED that any "redirect" modifier appear as 1091 the very last term in a record. 1093 6.2. exp: Explanation 1095 explanation = "exp" "=" domain-spec 1097 If check_host() results in a "Fail" due to a mechanism match (such as 1098 "-all"), and the "exp" modifier is present, then the explanation 1099 string returned is computed as described below. If no "exp" modifier 1100 is present, then either a default explanation string or an empty 1101 explanation string may be returned. 1103 The domain-spec is macro expanded (see Section 8) and becomes the 1104 . The DNS TXT record for the is fetched. 1106 If there are any DNS processing errors (any RCODE other than 0), or 1107 if no records are returned, or if more than one record is returned, 1108 or if there are syntax errors in the explanation string, then proceed 1109 as if no exp modifier was given. 1111 The fetched TXT record's strings are concatenated with no spaces, and 1112 then treated as an explain-string, which is macro-expanded. This 1113 final result is the explanation string. Implementations MAY limit 1114 the length of the resulting explanation string to allow for other 1115 protocol constraints and/or reasonable processing limits. Since the 1116 explanation string is intended for an SMTP response and [RFC2821] 1117 Section 2.4 says that responses are in [US-ASCII], the explanation 1118 string is also limited to US-ASCII. 1120 Software evaluating check_host() can use this string to communicate 1121 information from the publishing domain in the form of a short message 1122 or URL. Software SHOULD make it clear that the explanation string 1123 comes from a third party. For example, it can prepend the macro 1124 string "%{o} explains: " to the explanation, such as shown in 1125 Section 2.5.4. 1127 Suppose example.com has this record: 1129 v=spf1 mx -all exp=explain._spf.%{d} 1131 Here are some examples of possible explanation TXT records at 1132 explain._spf.example.com: 1134 "Mail from example.com should only be sent by its own servers." 1135 -- a simple, constant message 1137 "%{i} is not one of %{d}'s designated mail servers." 1138 -- a message with a little more information, including the IP 1139 address that failed the check 1141 "See http://%{d}/why.html?s=%{S}&i=%{I}" 1142 -- a complicated example that constructs a URL with the 1143 arguments to check_host() so that a web page can be 1144 generated with detailed, custom instructions 1146 Note: During recursion into an "include" mechanism, an exp= modifier 1147 from the MUST NOT be used. In contrast, when executing 1148 a "redirect" modifier, an exp= modifier from the original domain MUST 1149 NOT be used. 1151 7. The Received-SPF Header Field 1153 It is RECOMMENDED that SMTP receivers record the result of SPF 1154 processing in the message header. If an SMTP receiver chooses to do 1155 so, it SHOULD use the "Received-SPF" header field defined here for 1156 each identity that was checked. This information is intended for the 1157 recipient. (Information intended for the sender is described in 1158 Section 6.2, Explanation.) 1160 The Received-SPF header field is a trace field (see [RFC2822] Section 1161 3.6.7) and SHOULD be prepended to the existing header, above the 1162 Received: field that is generated by the SMTP receiver. It MUST 1163 appear above all other Received-SPF fields in the message. The 1164 header field has the following format: 1166 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 1167 [ key-value-list ] CRLF 1169 result = "Pass" / "Fail" / "SoftFail" / "Neutral" / 1170 "None" / "TempError" / "PermError" 1172 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 1173 [";"] 1175 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 1177 key = "client-ip" / "envelope-from" / "helo" / 1178 "problem" / "receiver" / "identity" / 1179 mechanism / "x-" name / name 1181 identity = "mailfrom" ; for the "MAIL FROM" identity 1182 / "helo" ; for the "HELO" identity 1183 / name ; other identities 1185 dot-atom = 1186 quoted-string = 1187 comment = 1188 CFWS = 1189 FWS = 1190 CRLF = 1192 The header field SHOULD include a "(...)" style comment after the 1193 result, conveying supporting information for the result, such as 1194 , , and . 1196 The following key-value pairs are designed for later machine parsing. 1197 SPF clients SHOULD give enough information so that the SPF results 1198 can be verified. That is, at least "client-ip", "helo", and, if the 1199 "MAIL FROM" identity was checked, "envelope-from". 1201 client-ip the IP address of the SMTP client 1203 envelope-from the envelope sender mailbox 1205 helo the host name given in the HELO or EHLO command 1207 mechanism the mechanism that matched (if no mechanisms matched, 1208 substitute the word "default") 1210 problem if an error was returned, details about the error 1212 receiver the host name of the SPF client 1214 identity the identity that was checked; see the ABNF 1215 rule 1217 Other keys may be defined by SPF clients. Until a new key name 1218 becomes widely accepted, new key names should start with "x-". 1220 SPF clients MUST make sure that the Received-SPF header field does 1221 not contain invalid characters, is not excessively long, and does not 1222 contain malicious data that has been provided by the sender. 1224 Examples of various header styles that could be generated are the 1225 following: 1227 Received-SPF: Pass (mybox.example.org: domain of 1228 myname@example.com designates 192.0.2.1 as permitted sender) 1229 receiver=mybox.example.org; client-ip=192.0.2.1; 1230 envelope-from="myname@example.com"; helo=foo.example.com; 1232 Received-SPF: Fail (mybox.example.org: domain of 1233 myname@example.com does not designate 1234 192.0.2.1 as permitted sender) 1235 identity=mailfrom; client-ip=192.0.2.1; 1236 envelope-from="myname@example.com"; 1238 8. Macros 1240 8.1. Macro Definitions 1242 Many mechanisms and modifiers perform macro expansion on the term. 1244 domain-spec = macro-string domain-end 1245 domain-end = ( "." toplabel [ "." ] ) / macro-expand 1247 toplabel = ( *alphanum ALPHA *alphanum ) / 1248 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 1249 ; LDH rule plus additional TLD restrictions 1250 ; (see [RFC3696], Section 2) 1251 alphanum = ALPHA / DIGIT 1253 explain-string = *( macro-string / SP ) 1255 macro-string = *( macro-expand / macro-literal ) 1256 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 1257 / "%%" / "%_" / "%-" 1258 macro-literal = %x21-24 / %x26-7E 1259 ; visible characters except "%" 1260 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 1261 "c" / "r" / "t" / "v" 1262 transformers = *DIGIT [ "r" ] 1263 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 1265 A literal "%" is expressed by "%%". 1267 "%_" expands to a single " " space. 1268 "%-" expands to a URL-encoded space, viz., "%20". 1270 The following macro letters are expanded in term arguments: 1272 s = 1273 l = local-part of 1274 o = domain of 1275 d = 1276 i = 1277 p = the validated domain name of 1278 v = the string "in-addr" if is ipv4, or "ip6" if is ipv6 1279 h = HELO/EHLO domain 1281 The following macro letters are allowed only in "exp" text: 1283 c = SMTP client IP (easily readable format) 1284 r = domain name of host performing the check 1285 t = current timestamp 1287 A '%' character not followed by a '{', '%', '-', or '_' character is 1288 a syntax error. So 1289 -exists:%(ir).sbl.spamhaus.example.org 1290 is incorrect and will cause check_host() to return a "PermError". 1291 Instead, say 1292 -exists:%{ir}.sbl.spamhaus.example.org 1294 Optional transformers are the following: 1296 *DIGIT = zero or more digits 1297 'r' = reverse value, splitting on dots by default 1299 If transformers or delimiters are provided, the replacement value for 1300 a macro letter is split into parts. After performing any reversal 1301 operation and/or removal of left-hand parts, the parts are rejoined 1302 using "." and not the original splitting characters. 1304 By default, strings are split on "." (dots). Note that no special 1305 treatment is given to leading, trailing, or consecutive delimiters, 1306 and so the list of parts may contain empty strings. Older 1307 implementations of SPF prohibit trailing dots in domain names, so 1308 trailing dots should not be published by domain owners, although they 1309 must be accepted by implementations conforming to this document. 1310 Macros may specify delimiter characters that are used instead of ".". 1312 The 'r' transformer indicates a reversal operation: if the client IP 1313 address were 192.0.2.1, the macro %{i} would expand to "192.0.2.1" 1314 and the macro %{ir} would expand to "1.2.0.192". 1316 The DIGIT transformer indicates the number of right-hand parts to 1317 use, after optional reversal. If a DIGIT is specified, the value 1318 MUST be nonzero. If no DIGITs are specified, or if the value 1319 specifies more parts than are available, all the available parts are 1320 used. If the DIGIT was 5, and only 3 parts were available, the macro 1321 interpreter would pretend the DIGIT was 3. Implementations MUST 1322 support at least a value of 128, as that is the maximum number of 1323 labels in a domain name. 1325 The "s" macro expands to the argument. It is an E-Mail 1326 address with a localpart, an "@" character, and a domain. The "l" 1327 macro expands to just the localpart. The "o" macro expands to just 1328 the domain part. Note that these values remain the same during 1329 recursive and chained evaluations due to "include" and/or "redirect". 1330 Note also that if the original had no localpart, the 1331 localpart was set to "postmaster" in initial processing (see 1332 Section 4.3). 1334 For IPv4 addresses, both the "i" and "c" macros expand to the 1335 standard dotted-quad format. 1337 For IPv6 addresses, the "i" macro expands to a dot-format address; it 1338 is intended for use in %{ir}. The "c" macro may expand to any of the 1339 hexadecimal colon-format addresses specified in [RFC3513], Section 1340 2.2. It is intended for humans to read. 1342 The "p" macro expands to the validated domain name of . The 1343 procedure for finding the validated domain name is defined in 1344 Section 5.5. If the is present in the list of validated 1345 domains, it SHOULD be used. Otherwise, if a subdomain of the 1346 is present, it SHOULD be used. Otherwise, any name from the 1347 list may be used. If there are no validated domain names or if a DNS 1348 error occurs, the string "unknown" is used. 1350 The "r" macro expands to the name of the receiving MTA. This SHOULD 1351 be a fully qualified domain name, but if one does not exist (as when 1352 the checking is done by a MUA) or if policy restrictions dictate 1353 otherwise, the word "unknown" SHOULD be substituted. The domain name 1354 may be different from the name found in the MX record that the client 1355 MTA used to locate the receiving MTA. 1357 The "t" macro expands to the decimal representation of the 1358 approximate number of seconds since the Epoch (Midnight, January 1, 1359 1970, UTC). This is the same value as is returned by the POSIX 1360 time() function in most standards-compliant libraries. 1362 When the result of macro expansion is used in a domain name query, if 1363 the expanded domain name exceeds 253 characters (the maximum length 1364 of a domain name), the left side is truncated to fit, by removing 1365 successive domain labels until the total length does not exceed 253 1366 characters. 1368 Uppercased macros expand exactly as their lowercased equivalents, and 1369 are then URL escaped. URL escaping must be performed for characters 1370 not in the "unreserved" set, which is defined in [RFC3986]. 1372 Note: Care must be taken so that macro expansion for legitimate 1373 E-Mail does not exceed the 63-character limit on DNS labels. The 1374 localpart of E-Mail addresses, in particular, can have more than 63 1375 characters between dots. 1377 Note: Domains should avoid using the "s", "l", "o", or "h" macros in 1378 conjunction with any mechanism directive. Although these macros are 1379 powerful and allow per-user records to be published, they severely 1380 limit the ability of implementations to cache results of check_host() 1381 and they reduce the effectiveness of DNS caches. 1383 Implementations should be aware that if no directive processed during 1384 the evaluation of check_host() contains an "s", "l", "o", or "h" 1385 macro, then the results of the evaluation can be cached on the basis 1386 of and alone for as long as the shortest Time To Live 1387 (TTL) of all the DNS records involved. 1389 8.2. Expansion Examples 1391 The is strong-bad@email.example.com. 1392 The IPv4 SMTP client IP is 192.0.2.3. 1393 The IPv6 SMTP client IP is 2001:DB8::CB01. 1394 The PTR domain name of the client IP is mx.example.org. 1396 macro expansion 1397 ------- ---------------------------- 1398 %{s} strong-bad@email.example.com 1399 %{o} email.example.com 1400 %{d} email.example.com 1401 %{d4} email.example.com 1402 %{d3} email.example.com 1403 %{d2} example.com 1404 %{d1} com 1405 %{dr} com.example.email 1406 %{d2r} example.email 1407 %{l} strong-bad 1408 %{l-} strong.bad 1409 %{lr} strong-bad 1410 %{lr-} bad.strong 1411 %{l1r-} strong 1413 macro-string expansion 1414 -------------------------------------------------------------------- 1415 %{ir}.%{v}._spf.%{d2} 3.2.0.192.in-addr._spf.example.com 1416 %{lr-}.lp._spf.%{d2} bad.strong.lp._spf.example.com 1418 %{lr-}.lp.%{ir}.%{v}._spf.%{d2} 1419 bad.strong.lp.3.2.0.192.in-addr._spf.example.com 1421 %{ir}.%{v}.%{l1r-}.lp._spf.%{d2} 1422 3.2.0.192.in-addr.strong.lp._spf.example.com 1424 %{d2}.trusted-domains.example.net 1425 example.com.trusted-domains.example.net 1427 IPv6: 1428 %{ir}.%{v}._spf.%{d2} 1.0.B.C.0.0.0.0. 1429 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 1431 9. Implications 1433 This section outlines the major implications that adoption of this 1434 document will have on various entities involved in Internet E-Mail. 1435 It is intended to make clear to the reader where this document 1436 knowingly affects the operation of such entities. This section is 1437 not a "how-to" manual, or a "best practices" document, and it is not 1438 a comprehensive list of what such entities should do in light of this 1439 document. 1441 This section is non-normative. 1443 9.1. Sending Domains 1445 Domains that wish to be compliant with this specification will need 1446 to determine the list of hosts that they allow to use their domain 1447 name in the "HELO" and "MAIL FROM" identities. It is recognized that 1448 forming such a list is not just a simple technical exercise, but 1449 involves policy decisions with both technical and administrative 1450 considerations. 1452 It can be helpful to publish records that include a "tracking 1453 exists:" mechanism. By looking at the name server logs, a rough list 1454 may then be generated. For example: 1456 v=spf1 exists:_h.%{h}._l.%{l}._o.%{o}._i.%{i}._spf.%{d} ?all 1458 9.2. Mailing Lists 1460 Mailing lists must be aware of how they re-inject mail that is sent 1461 to the list. Mailing lists MUST comply with the requirements in 1462 [RFC2821], Section 3.10, and [RFC1123], Section 5.3.6, that say that 1463 the reverse-path MUST be changed to be the mailbox of a person or 1464 other entity who administers the list. Whereas the reasons for 1465 changing the reverse-path are many and long-standing, SPF adds 1466 enforcement to this requirement. 1468 In practice, almost all mailing list software in use already complies 1469 with this requirement. Mailing lists that do not comply may or may 1470 not encounter problems depending on how access to the list is 1471 restricted. Such lists that are entirely internal to a domain (only 1472 people in the domain can send to or receive from the list) are not 1473 affected. 1475 9.3. Forwarding Services and Aliases 1477 Forwarding services take mail that is received at a mailbox and 1478 direct it to some external mailbox. At the time of this writing, the 1479 near-universal practice of such services is to use the original "MAIL 1480 FROM" of a message when re-injecting it for delivery to the external 1481 mailbox. [RFC1123] and [RFC2821] describe this action as an "alias" 1482 rather than a "mail list". This means that the external mailbox's 1483 MTA sees all such mail in a connection from a host of the forwarding 1484 service, and so the "MAIL FROM" identity will not, in general, pass 1485 authorization. 1487 There are three places that techniques can be used to ameliorate this 1488 problem. 1490 1. The beginning, when E-Mail is first sent. 1492 1. "Neutral" results could be given for IP addresses that may be 1493 forwarders, instead of "Fail" results. For example: 1495 "v=spf1 mx -exists:%{ir}.sbl.spamhaus.example.org ?all" 1497 This would cause a lookup on an anti-spam DNS blacklist 1498 (DNSBL) and cause a result of "Fail" only for E-Mail coming 1499 from listed sources. All other E-Mail, including E-Mail sent 1500 through forwarders, would receive a "Neutral" result. By 1501 checking the DNSBL after the known good sources, problems 1502 with incorrect listing on the DNSBL are greatly reduced. 1504 2. The "MAIL FROM" identity could have additional information in 1505 the localpart that cryptographically identifies the mail as 1506 coming from an authorized source. In this case, such an SPF 1507 record could be used: 1509 "v=spf1 mx exists:%{l}._spf_verify.%{d} -all" 1511 Then, a specialized DNS server can be set up to serve the 1512 _spf_verify subdomain that validates the localpart. Although 1513 this requires an extra DNS lookup, this happens only when the 1514 E-Mail would otherwise be rejected as not coming from a known 1515 good source. 1516 Note that due to the 63-character limit for domain labels, 1517 this approach only works reliably if the localpart signature 1518 scheme is guaranteed either to only produce localparts with a 1519 maximum of 63 characters or to gracefully handle truncated 1520 localparts. 1522 3. Similarly, a specialized DNS server could be set up that will 1523 rate-limit the E-Mail coming from unexpected IP addresses. 1525 "v=spf1 mx exists:%{ir}._spf_rate.%{d} -all" 1527 4. SPF allows the creation of per-user policies for special 1528 cases. For example, the following SPF record and appropriate 1529 wildcard DNS records can be used: 1531 "v=spf1 mx redirect=%{l1r+}._at_.%{o}._spf.%{d}" 1533 2. The middle, when E-Mail is forwarded. 1535 1. Forwarding services can solve the problem by rewriting the 1536 "MAIL FROM" to be in their own domain. This means that mail 1537 bounced from the external mailbox will have to be re-bounced 1538 by the forwarding service. Various schemes to do this exist 1539 though they vary widely in complexity and resource 1540 requirements on the part of the forwarding service. 1542 2. Several popular MTAs can be forced from "alias" semantics to 1543 "mailing list" semantics by configuring an additional alias 1544 with "owner-" prepended to the original alias name (e.g., an 1545 alias of "friends: george@example.com, fred@example.org" 1546 would need another alias of the form "owner-friends: 1547 localowner"). 1549 3. The end, when E-Mail is received. 1551 1. If the owner of the external mailbox wishes to trust the 1552 forwarding service, he can direct the external mailbox's MTA 1553 to skip SPF tests when the client host belongs to the 1554 forwarding service. 1556 2. Tests against other identities, such as the "HELO" identity, 1557 may be used to override a failed test against the "MAIL FROM" 1558 identity. 1560 3. For larger domains, it may not be possible to have a complete 1561 or accurate list of forwarding services used by the owners of 1562 the domain's mailboxes. In such cases, whitelists of 1563 generally-recognized forwarding services could be employed. 1565 9.4. Mail Services 1567 Service providers that offer mail services to third-party domains, 1568 such as sending of bulk mail, may want to adjust their setup in light 1569 of the authorization check described in this document. If the "MAIL 1570 FROM" identity used for such E-Mail uses the domain of the service 1571 provider, then the provider needs only to ensure that its sending 1572 host is authorized by its own SPF record, if any. 1574 If the "MAIL FROM" identity does not use the mail service provider's 1575 domain, then extra care must be taken. The SPF record format has 1576 several options for the third-party domain to authorize the service 1577 provider's MTAs to send mail on its behalf. For mail service 1578 providers, such as ISPs, that have a wide variety of customers using 1579 the same MTA, steps should be taken to prevent cross-customer forgery 1580 (see Section 10.4). 1582 9.5. MTA Relays 1584 The authorization check generally precludes the use of arbitrary MTA 1585 relays between sender and receiver of an E-Mail message. 1587 Within an organization, MTA relays can be effectively deployed. 1588 However, for purposes of this document, such relays are effectively 1589 transparent. The SPF authorization check is a check between border 1590 MTAs of different domains. 1592 For mail senders, this means that published SPF records must 1593 authorize any MTAs that actually send across the Internet. Usually, 1594 these are just the border MTAs as internal MTAs simply forward mail 1595 to these MTAs for delivery. 1597 Mail receivers will generally want to perform the authorization check 1598 at the border MTAs, specifically including all secondary MXs. This 1599 allows mail that fails to be rejected during the SMTP session rather 1600 than bounced. Internal MTAs then do not perform the authorization 1601 test. To perform the authorization test other than at the border, 1602 the host that first transferred the message to the organization must 1603 be determined, which can be difficult to extract from the message 1604 header. Testing other than at the border is not recommended. 1606 10. Security Considerations 1608 10.1. Processing Limits 1610 As with most aspects of E-Mail, there are a number of ways that 1611 malicious parties could use the protocol as an avenue for a 1612 Denial-of-Service (DoS) attack. The processing limits outlined here 1613 are designed to prevent attacks such as the following: 1615 o A malicious party could create an SPF record with many references 1616 to a victim's domain and send many E-Mails to different SPF 1617 clients; those SPF clients would then create a DoS attack. In 1618 effect, the SPF clients are being used to amplify the attacker's 1619 bandwidth by using fewer bytes in the SMTP session than are used 1620 by the DNS queries. Using SPF clients also allows the attacker to 1621 hide the true source of the attack. 1623 o Whereas implementations of check_host() are supposed to limit the 1624 number of DNS lookups, malicious domains could publish records 1625 that exceed these limits in an attempt to waste computation effort 1626 at their targets when they send them mail. Malicious domains 1627 could also design SPF records that cause particular 1628 implementations to use excessive memory or CPU usage, or to 1629 trigger bugs. 1631 o Malicious parties could send a large volume of mail purporting to 1632 come from the intended target to a wide variety of legitimate mail 1633 hosts. These legitimate machines would then present a DNS load on 1634 the target as they fetched the relevant records. 1636 Of these, the case of a third party referenced in the SPF record is 1637 the easiest for a DoS attack to effectively exploit. As a result, 1638 limits that may seem reasonable for an individual mail server can 1639 still allow an unreasonable amount of bandwidth amplification. 1640 Therefore, the processing limits need to be quite low. 1642 SPF implementations MUST limit the number of mechanisms and modifiers 1643 that do DNS lookups to at most 10 per SPF check, including any 1644 lookups caused by the use of the "include" mechanism or the 1645 "redirect" modifier. If this number is exceeded during a check, a 1646 PermError MUST be returned. The "include", "a", "mx", "ptr", and 1647 "exists" mechanisms as well as the "redirect" modifier do count 1648 against this limit. The "all", "ip4", and "ip6" mechanisms do not 1649 require DNS lookups and therefore do not count against this limit. 1650 The "exp" modifier does not count against this limit because the DNS 1651 lookup to fetch the explanation string occurs after the SPF record 1652 has been evaluated. 1654 When evaluating the "mx" and "ptr" mechanisms, or the %{p} macro, 1655 there MUST be a limit of no more than 10 MX or PTR RRs looked up and 1656 checked. 1658 SPF implementations SHOULD limit the total amount of data obtained 1659 from the DNS queries. For example, when DNS over TCP or EDNS0 are 1660 available, there may need to be an explicit limit to how much data 1661 will be accepted to prevent excessive bandwidth usage or memory usage 1662 and DoS attacks. 1664 MTAs or other processors MAY also impose a limit on the maximum 1665 amount of elapsed time to evaluate check_host(). Such a limit SHOULD 1666 allow at least 20 seconds. If such a limit is exceeded, the result 1667 of authorization SHOULD be "TempError". 1669 Domains publishing records SHOULD try to keep the number of "include" 1670 mechanisms and chained "redirect" modifiers to a minimum. Domains 1671 SHOULD also try to minimize the amount of other DNS information 1672 needed to evaluate a record. This can be done by choosing directives 1673 that require less DNS information and placing lower-cost mechanisms 1674 earlier in the SPF record. 1676 For example, consider a domain set up as follows: 1678 example.com. IN MX 10 mx.example.com. 1679 mx.example.com. IN A 192.0.2.1 1680 a.example.com. IN TXT "v=spf1 mx:example.com -all" 1681 b.example.com. IN TXT "v=spf1 a:mx.example.com -all" 1682 c.example.com. IN TXT "v=spf1 ip4:192.0.2.1 -all" 1684 Evaluating check_host() for the domain "a.example.com" requires the 1685 MX records for "example.com", and then the A records for the listed 1686 hosts. Evaluating for "b.example.com" requires only the A records. 1687 Evaluating for "c.example.com" requires none. 1689 However, there may be administrative considerations: using "a" over 1690 "ip4" allows hosts to be renumbered easily. Using "mx" over "a" 1691 allows the set of mail hosts to be changed easily. 1693 10.2. SPF-Authorized E-Mail May Contain Other False Identities 1695 The "MAIL FROM" and "HELO" identity authorizations must not be 1696 construed to provide more assurance than they do. It is entirely 1697 possible for a malicious sender to inject a message using his own 1698 domain in the identities used by SPF, to have that domain's SPF 1699 record authorize the sending host, and yet the message can easily 1700 list other identities in its header. Unless the user or the MUA 1701 takes care to note that the authorized identity does not match the 1702 other more commonly-presented identities (such as the From: header 1703 field), the user may be lulled into a false sense of security. 1705 10.3. Spoofed DNS and IP Data 1707 There are two aspects of this protocol that malicious parties could 1708 exploit to undermine the validity of the check_host() function: 1710 o The evaluation of check_host() relies heavily on DNS. A malicious 1711 attacker could attack the DNS infrastructure and cause 1712 check_host() to see spoofed DNS data, and then return incorrect 1713 results. This could include returning "Pass" for an value 1714 where the actual domain's record would evaluate to "Fail". See 1715 [RFC3833] for a description of DNS weaknesses. 1717 o The client IP address, , is assumed to be correct. A 1718 malicious attacker could spoof TCP sequence numbers to make mail 1719 appear to come from a permitted host for a domain that the 1720 attacker is impersonating. 1722 10.4. Cross-User Forgery 1724 By definition, SPF policies just map domain names to sets of 1725 authorized MTAs, not whole E-Mail addresses to sets of authorized 1726 users. Although the "l" macro (Section 8) provides a limited way to 1727 define individual sets of authorized MTAs for specific E-Mail 1728 addresses, it is generally impossible to verify, through SPF, the use 1729 of specific E-Mail addresses by individual users of the same MTA. 1731 It is up to mail services and their MTAs to directly prevent 1732 cross-user forgery: based on SMTP AUTH ([RFC2554]), users should be 1733 restricted to using only those E-Mail addresses that are actually 1734 under their control (see [RFC4409], Section 6.1). Another means to 1735 verify the identity of individual users is message cryptography such 1736 as PGP ([RFC2440]) or S/MIME ([RFC3851]). 1738 10.5. Untrusted Information Sources 1740 SPF uses information supplied by third parties, such as the "HELO" 1741 domain name, the "MAIL FROM" address, and SPF records. This 1742 information is then passed to the receiver in the Received-SPF: trace 1743 fields and possibly returned to the client MTA in the form of an SMTP 1744 rejection message. This information must be checked for invalid 1745 characters and excessively long lines. 1747 When the authorization check fails, an explanation string may be 1748 included in the reject response. Both the sender and the rejecting 1749 receiver need to be aware that the explanation was determined by the 1750 publisher of the SPF record checked and, in general, not the 1751 receiver. The explanation may contain malicious URLs, or it may be 1752 offensive or misleading. 1754 This is probably less of a concern than it may initially seem since 1755 such messages are returned to the sender, and the explanation strings 1756 come from the sender policy published by the domain in the identity 1757 claimed by that very sender. As long as the DSN is not redirected to 1758 someone other than the actual sender, the only people who see 1759 malicious explanation strings are people whose messages claim to be 1760 from domains that publish such strings in their SPF records. In 1761 practice, DSNs can be misdirected, such as when an MTA accepts an 1762 E-Mail and then later generates a DSN to a forged address, or when an 1763 E-Mail forwarder does not direct the DSN back to the original sender. 1765 10.6. Privacy Exposure 1767 Checking SPF records causes DNS queries to be sent to the domain 1768 owner. These DNS queries, especially if they are caused by the 1769 "exists" mechanism, can contain information about who is sending 1770 E-Mail and likely to which MTA the E-Mail is being sent. This can 1771 introduce some privacy concerns, which may be more or less of an 1772 issue depending on local laws and the relationship between the domain 1773 owner and the person sending the E-Mail. 1775 11. Contributors and Acknowledgements 1777 This document is largely based on the work of Meng Weng Wong and Mark 1778 Lentczner. Although, as this section acknowledges, many people have 1779 contributed to this document, a very large portion of the writing and 1780 editing are due to Meng and Mark. 1782 This design owes a debt of parentage to [RMX] by Hadmut Danisch and 1783 to [DMP] by Gordon Fecyk. The idea of using a DNS record to check 1784 the legitimacy of an E-Mail address traces its ancestry further back 1785 through messages on the namedroppers mailing list by Paul Vixie 1786 [Vixie] (based on suggestion by Jim Miller) and by David Green 1787 [Green]. 1789 Philip Gladstone contributed the concept of macros to the 1790 specification, multiplying the expressiveness of the language and 1791 making per-user and per-IP lookups possible. 1793 The authors would also like to thank the literally hundreds of 1794 individuals who have participated in the development of this design. 1795 They are far too numerous to name, but they include the following: 1797 The folks on the spf-discuss mailing list. 1798 The folks on the SPAM-L mailing list. 1799 The folks on the IRTF ASRG mailing list. 1800 The folks on the IETF MARID mailing list. 1801 The folks on #perl. 1803 12. IANA Considerations 1805 12.1. The SPF DNS Record Type 1807 The IANA has assigned a new Resource Record Type and Qtype from the 1808 DNS Parameters Registry for the SPF RR type with code 99. 1810 12.2. The Received-SPF Mail Header Field 1812 Per [RFC3864], the "Received-SPF:" header field is added to the IANA 1813 Permanent Message Header Field Registry. The following is the 1814 registration template: 1816 Header field name: Received-SPF 1817 Applicable protocol: mail ([RFC2822]) 1818 Status: Standards Track 1819 Author/Change controller: IETF 1820 Specification document(s): RFC XXXX 1822 13. References 1824 13.1. Normative References 1826 [RFC1035] Mockapetris, P., "Domain names - implementation and 1827 specification", STD 13, RFC 1035, November 1987. 1829 [RFC1123] Braden, R., "Requirements for Internet Hosts - Application 1830 and Support", STD 3, RFC 1123, October 1989. 1832 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1833 Requirement Levels", BCP 14, RFC 2119, March 1997. 1835 [RFC2821] Klensin, J., "Simple Mail Transfer Protocol", RFC 2821, 1836 April 2001. 1838 [RFC2822] Resnick, P., "Internet Message Format", RFC 2822, 1839 April 2001. 1841 [RFC3464] Moore, K. and G. Vaudreuil, "An Extensible Message Format 1842 for Delivery Status Notifications", RFC 3464, 1843 January 2003. 1845 [RFC3513] Hinden, R. and S. Deering, "Internet Protocol Version 6 1846 (IPv6) Addressing Architecture", RFC 3513, April 2003. 1848 [RFC3864] Klyne, G., Nottingham, M., and J. Mogul, "Registration 1849 Procedures for Message Header Fields", BCP 90, RFC 3864, 1850 September 2004. 1852 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1853 Resource Identifier (URI): Generic Syntax", STD 66, 1854 RFC 3986, January 2005. 1856 [RFC4234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1857 Specifications: ABNF", RFC 4234, October 2005. 1859 [US-ASCII] 1860 American National Standards Institute (formerly United 1861 States of America Standards Institute), "USA Code for 1862 Information Interchange, X3.4", 1968. 1864 ANSI X3.4-1968 has been replaced by newer versions with 1865 slight modifications, but the 1968 version remains 1866 definitive for the Internet. 1868 13.2. Informative References 1870 [DMP] Fecyk, G., "Designated Mailers Protocol". 1872 Work In Progress 1874 [Green] Green, D., "Domain-Authorized SMTP Mail", 2002. 1876 [RFC1034] Mockapetris, P., "Domain names - concepts and facilities", 1877 STD 13, RFC 1034, November 1987. 1879 [RFC1983] Malkin, G., "Internet Users' Glossary", RFC 1983, 1880 August 1996. 1882 [RFC2440] Callas, J., Donnerhacke, L., Finney, H., and R. Thayer, 1883 "OpenPGP Message Format", RFC 2440, November 1998. 1885 [RFC2554] Myers, J., "SMTP Service Extension for Authentication", 1886 RFC 2554, March 1999. 1888 [RFC3696] Klensin, J., "Application Techniques for Checking and 1889 Transformation of Names", RFC 3696, February 2004. 1891 [RFC3833] Atkins, D. and R. Austein, "Threat Analysis of the Domain 1892 Name System (DNS)", RFC 3833, August 2004. 1894 [RFC3851] Ramsdell, B., "Secure/Multipurpose Internet Mail 1895 Extensions (S/MIME) Version 3.1 Message Specification", 1896 RFC 3851, July 2004. 1898 [RFC4408] Wong, M. and W. Schlitt, "Sender Policy Framework (SPF) 1899 for Authorizing Use of Domains in E-Mail, Version 1", 1900 RFC 4408, April 2006. 1902 [RFC4409] Gellens, R. and J. Klensin, "Message Submission for Mail", 1903 RFC 4409, April 2006. 1905 [RFC4871] Allman, E., Callas, J., Delany, M., Libbey, M., Fenton, 1906 J., and M. Thomas, "DomainKeys Identified Mail (DKIM) 1907 Signatures", RFC 4871, May 2007. 1909 [RFC5598] Crocker, D., "Internet Mail Architecture", RFC 5598, 1910 July 2009. 1912 [RMX] Danisch, H., "The RMX DNS RR Type for light weight sender 1913 authentication". 1915 Work In Progress 1917 [Vixie] Vixie, P., "Repudiating MAIL FROM", 2002. 1919 Appendix A. Collected ABNF 1921 This section is normative and any discrepancies with the ABNF 1922 fragments in the preceding text are to be resolved in favor of this 1923 grammar. 1925 See [RFC4234] for ABNF notation. Please note that as per this ABNF 1926 definition, literal text strings (those in quotes) are case- 1927 insensitive. Hence, "mx" matches "mx", "MX", "mX", and "Mx". 1929 record = version terms *SP 1930 version = "v=spf1" 1932 terms = *( 1*SP ( directive / modifier ) ) 1934 directive = [ qualifier ] mechanism 1935 qualifier = "+" / "-" / "?" / "~" 1936 mechanism = ( all / include 1937 / A / MX / PTR / IP4 / IP6 / exists ) 1939 all = "all" 1940 include = "include" ":" domain-spec 1941 A = "a" [ ":" domain-spec ] [ dual-cidr-length ] 1942 MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] 1943 PTR = "ptr" [ ":" domain-spec ] 1944 IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] 1945 IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] 1946 exists = "exists" ":" domain-spec 1948 modifier = redirect / explanation / unknown-modifier 1949 redirect = "redirect" "=" domain-spec 1950 explanation = "exp" "=" domain-spec 1951 unknown-modifier = name "=" macro-string 1952 ; where name is not any known modifier 1954 ip4-cidr-length = "/" 1*DIGIT 1955 ip6-cidr-length = "/" 1*DIGIT 1956 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] 1958 ip4-network = qnum "." qnum "." qnum "." qnum 1959 qnum = DIGIT ; 0-9 1960 / %x31-39 DIGIT ; 10-99 1961 / "1" 2DIGIT ; 100-199 1962 / "2" %x30-34 DIGIT ; 200-249 1963 / "25" %x30-35 ; 250-255 1964 ; conventional dotted quad notation. e.g., 192.0.2.0 1965 ip6-network = 1966 ; e.g., 2001:DB8::CD30 1968 domain-spec = macro-string domain-end 1969 domain-end = ( "." toplabel [ "." ] ) / macro-expand 1971 toplabel = ( *alphanum ALPHA *alphanum ) / 1972 ( 1*alphanum "-" *( alphanum / "-" ) alphanum ) 1973 ; LDH rule plus additional TLD restrictions 1974 ; (see [RFC3696], Section 2) 1975 alphanum = ALPHA / DIGIT 1977 explain-string = *( macro-string / SP ) 1979 macro-string = *( macro-expand / macro-literal ) 1980 macro-expand = ( "%{" macro-letter transformers *delimiter "}" ) 1981 / "%%" / "%_" / "%-" 1982 macro-literal = %x21-24 / %x26-7E 1983 ; visible characters except "%" 1984 macro-letter = "s" / "l" / "o" / "d" / "i" / "p" / "h" / 1985 "c" / "r" / "t" 1986 transformers = *DIGIT [ "r" ] 1987 delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" 1989 name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) 1991 header-field = "Received-SPF:" [CFWS] result FWS [comment FWS] 1992 [ key-value-list ] CRLF 1994 result = "Pass" / "Fail" / "SoftFail" / "Neutral" / 1995 "None" / "TempError" / "PermError" 1997 key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) 1998 [";"] 2000 key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string ) 2002 key = "client-ip" / "envelope-from" / "helo" / 2003 "problem" / "receiver" / "identity" / 2004 mechanism / "x-" name / name 2006 identity = "mailfrom" ; for the "MAIL FROM" identity 2007 / "helo" ; for the "HELO" identity 2008 / name ; other identities 2010 dot-atom = 2011 quoted-string = 2012 comment = 2013 CFWS = 2014 FWS = 2015 CRLF = 2017 Appendix B. Extended Examples 2019 These examples are based on the following DNS setup: 2021 ; A domain with two mail servers, two hosts 2022 ; and two servers at the domain name 2023 $ORIGIN example.com. 2024 @ MX 10 mail-a 2025 MX 20 mail-b 2026 A 192.0.2.10 2027 A 192.0.2.11 2028 amy A 192.0.2.65 2029 bob A 192.0.2.66 2030 mail-a A 192.0.2.129 2031 mail-b A 192.0.2.130 2032 www CNAME example.com. 2034 ; A related domain 2035 $ORIGIN example.org. 2036 @ MX 10 mail-c 2037 mail-c A 192.0.2.140 2039 ; The reverse IP for those addresses 2040 $ORIGIN 2.0.192.in-addr.arpa. 2041 10 PTR example.com. 2042 11 PTR example.com. 2043 65 PTR amy.example.com. 2044 66 PTR bob.example.com. 2045 129 PTR mail-a.example.com. 2046 130 PTR mail-b.example.com. 2047 140 PTR mail-c.example.org. 2049 ; A rogue reverse IP domain that claims to be 2050 ; something it's not 2051 $ORIGIN 0.0.10.in-addr.arpa. 2052 4 PTR bob.example.com. 2054 B.1. Simple Examples 2056 These examples show various possible published records for 2057 example.com and which values if would cause check_host() to 2058 return "Pass". Note that is "example.com". 2060 v=spf1 +all 2061 -- any passes 2063 v=spf1 a -all 2064 -- hosts 192.0.2.10 and 192.0.2.11 pass 2066 v=spf1 a:example.org -all 2067 -- no sending hosts pass since example.org has no A records 2069 v=spf1 mx -all 2070 -- sending hosts 192.0.2.129 and 192.0.2.130 pass 2072 v=spf1 mx:example.org -all 2073 -- sending host 192.0.2.140 passes 2075 v=spf1 mx mx:example.org -all 2076 -- sending hosts 192.0.2.129, 192.0.2.130, and 192.0.2.140 pass 2078 v=spf1 mx/30 mx:example.org/30 -all 2079 -- any sending host in 192.0.2.128/30 or 192.0.2.140/30 passes 2081 v=spf1 ptr -all 2082 -- sending host 192.0.2.65 passes (reverse DNS is valid and is in 2083 example.com) 2084 -- sending host 192.0.2.140 fails (reverse DNS is valid, but not 2085 in example.com) 2086 -- sending host 10.0.0.4 fails (reverse IP is not valid) 2088 v=spf1 ip4:192.0.2.128/28 -all 2089 -- sending host 192.0.2.65 fails 2090 -- sending host 192.0.2.129 passes 2092 B.2. Multiple Domain Example 2094 These examples show the effect of related records: 2096 example.org: "v=spf1 include:example.com include:example.net -all" 2098 This record would be used if mail from example.org actually came 2099 through servers at example.com and example.net. Example.org's 2100 designated servers are the union of example.com's and example.net's 2101 designated servers. 2103 la.example.org: "v=spf1 redirect=example.org" 2104 ny.example.org: "v=spf1 redirect=example.org" 2105 sf.example.org: "v=spf1 redirect=example.org" 2107 These records allow a set of domains that all use the same mail 2108 system to make use of that mail system's record. In this way, only 2109 the mail system's record needs to be updated when the mail setup 2110 changes. These domains' records never have to change. 2112 B.3. DNSBL Style Example 2114 Imagine that, in addition to the domain records listed above, there 2115 are these: 2117 $ORIGIN _spf.example.com. 2118 mary.mobile-users A 127.0.0.2 2119 fred.mobile-users A 127.0.0.2 2120 15.15.168.192.joel.remote-users A 127.0.0.2 2121 16.15.168.192.joel.remote-users A 127.0.0.2 2123 The following records describe users at example.com who mail from 2124 arbitrary servers, or who mail from personal servers. 2126 example.com: 2128 v=spf1 mx 2129 include:mobile-users._spf.%{d} 2130 include:remote-users._spf.%{d} 2131 -all 2133 mobile-users._spf.example.com: 2135 v=spf1 exists:%{l1r+}.%{d} 2137 remote-users._spf.example.com: 2139 v=spf1 exists:%{ir}.%{l1r+}.%{d} 2141 B.4. Multiple Requirements Example 2143 Say that your sender policy requires both that the IP address is 2144 within a certain range and that the reverse DNS for the IP matches. 2145 This can be done several ways, including the following: 2147 example.com. SPF ( "v=spf1 " 2148 "-include:ip4._spf.%{d} " 2149 "-include:ptr._spf.%{d} " 2150 "+all" ) 2151 ip4._spf.example.com. SPF "v=spf1 -ip4:192.0.2.0/24 +all" 2152 ptr._spf.example.com. SPF "v=spf1 -ptr +all" 2154 This example shows how the "-include" mechanism can be useful, how an 2155 SPF record that ends in "+all" can be very restrictive, and the use 2156 of De Morgan's Law. 2158 Appendix C. Change History 2160 Changes since RFC 4408 (to be removed prior to publication) 2162 Moved to standards track 2164 Authors updated 2166 IESG Note regarding experimental use replaced with discussion of 2167 results 2169 Process errata: 2171 Add %v macro to ABNF grammar 2173 Replace "uric" by "unreserved" 2175 Recommend an SMTP reply code for optional PermError rejections 2177 Correct syntax in Received-SPF examples 2179 Fix unknown-modifier clause is too greedy in ABNF 2181 Correct use of empty domain-spec on exp modifier 2183 Fix minor typo errata 2185 Appendix D. TODO 2187 Finish errata (PermError on invalid domains after macro expansion) 2189 Review DNS RCODE/TempError criteria 2191 Review SPF test suite ambiguous results for additional errata 2193 Review status relative to SPFbis WG issues and update 2195 Author's Address 2197 D. Scott Kitterman 2198 3611 Scheel Dr 2199 Ellicott City, MD 21042 2200 United States of America 2202 Email: scott@kitterman.com