MARID Meng Weng Wong Internet-Draft Mark Lentczner Expires: January 9, 2005 July 11, 2004 The SPF Record Format and Test Protocol draft-ietf-marid-protocol-00 Status of this Memo By submitting this Internet-Draft, I certify that any applicable patent or other IPR claims of which I am aware have been disclosed, or will be disclosed, and any of which I become aware will be disclosed, in accordance with RFC 3668. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents as Internet-Drafts. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." The list of current Internet-Drafts can be accessed at http://www.ietf.org/ietf/1id-abstracts.txt. The list of Internet-Draft Shadow Directories can be accessed at http://www.ietf.org/shadow.html. This Internet-Draft will expire on January 9, 2005. Abstract This document defines the format of a record that domains publish to authorize a set of hosts to send mail on its behalf. This document also defines the check_host() function that mail receivers evaluate to see if a particular host is authorized to submit a particular piece of mail. This document only describes the particulars of the syntax and the algorithm of the function. See the MARID Core draft (draft-ietf-marid-core) for how these are used in the context of sending and receiving Internet mail. Wong & Lentczner Expires January 9, 2005 [Page 1] Internet-Draft The SPF Record Format and Test Protocol July 2004 Table of Contents 1. Introduction 1.1 Earlier Work 1.2 Terminology 2. Permitted Sender Records 2.1 Publishing 2.1.1 DNS Record Type 2.1.2 Multiple Records 2.1.3 Additional Records 2.1.4 Multiple Strings 3 The check_host() Function 3.1 Arguments 3.2 Results 3.3 Initial Processing 3.4 Record Lookup 3.4.1 Matching Version 3.5. Record Evaluation 3.5.1 Term Evaluation 3.5.2 Mechanisms 3.5.3 Modifiers 3.6 Default result 4. Mechanism Definitions 4.1 "all" 4.2 "include" 4.3 "a" 4.4 "mx" 4.5 "ptr" 4.6 "ip4" and "ip6" 4.7 "exists" 5. Modifier Definitions 5.1 redirect: Redirected Query 5.2 exp: Explanation 6. Miscellaneous 6.1 Unrecognized Mechanisms and Modifiers 6.2 Processing Limits 7. Macros 7.1 Macro definitions 7.2 Expansion Examples 8. Security Considerations 9. IANA Considerations 9.1 Registration Template 10. Contributors and Acknowledgements Normative References Informative References Authors' Addresses Comments Wong & Lentczner Expires January 9, 2005 [Page 2] Internet-Draft The SPF Record Format and Test Protocol July 2004 Appendix A. Collected ABNF Appendix B. Extended Examples B.1 Simple Examples B.2 Multiple Domain Example B.3 RBL Style Example Intellectual Property Statement Disclaimer of Validity Copyright Statement Acknowledgment 1. Introduction Owners of domain names publish SPF records to make declarations about hosts that are and are not permitted to use their domain names while sending mail. Mail receivers perform tests, which read published records to determine how a domain's declarations apply to particular hosts in during mail reception. The format of the records, and the mechanics of using them to perform the tests must be rigorously defined if domain owners and mail receivers are to agree on what the declarations mean. The intended audience for this document includes administrators of the Domain Name System and developers of Mail Transfer Agents (MTAs), Mail Delivery Agents (MDAs), and Mail User Agents (MUAs). They are assumed to be familiar with the workings of SMTP and DNS. See [RFC 2821] and [RFC 1034]. 1.1 Earlier Work This design is an evolution of work done under the name SPF. The record format and test presented here has been intentionally designed to be generally backward compatible with the currently deployed base of records and code. 1.2 Terminology The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119]. 2. Permitted Sender Records Domains publish records to declare which hosts are and are not permitted to use their names when sending mail. Loosely, the record Wong & Lentczner Expires January 9, 2005 [Page 3] Internet-Draft The SPF Record Format and Test Protocol July 2004 partitions all hosts into permitted and not-permitted sets. (Though some hosts might fall into other categories.) The record is a single string of text: record = version *( 1*SP ( directive / modifier ) ) *SP An example record is: v=spf1 +mx +a:colo.example.com/28 -all This record has a version of "v=spf1" and three directives: "+mx", "+a:colo.example.com/28", and "-all". Mail receivers read these records to allow them to perform checks for a given host in a given context. They do so by evaluating the check_host() function (described below), and the directives of a domain's record direct the evaluation. 2.1 Publishing A domain publishes its record in DNS. The record is placed in the DNS tree at the level of the domain name it pertains to. An example published record could be: v=spf1 +mx +a:colo.example.com/28 -all This might be published easily via this line in a domain file: example.com. IN TXT "v=spf1 +mx +a:colo.example.com/28 -all" 2.1.1 DNS Record Type The record type is a textual RR type to be allocated by the IANA for this purpose. However, because there is a large number of domains with these records already deployed as TXT type records, and because there are a number of DNS server and resolver implementations in common use that cannot handle new RR types, the record type can be TXT. Domains SHOULD publish records under both types. If a domain does publish under both types, then they MUST have the same content. Mail receivers SHOULD query for both types of records. If both are Wong & Lentczner Expires January 9, 2005 [Page 4] Internet-Draft The SPF Record Format and Test Protocol July 2004 returned, then the new RR type MUST be preferred. It is recognized that the current practice (using a TXT type record), is not optimal, but a practical reality due to the state of deployed records and software. The two record type scheme provides a forward path to the better solution of using a RR type reserved for this purpose. For either type, the character content of the record is encoded as US-ASCII. 2.1.2 Multiple Records A domain MUST NOT publish multiple records of the same type (TXT or new RR) that begin with the version defined in this document ("v=spf1"). If a domain does, this will constitute permanent error. 2.1.3 Additional Records Some records contain directives that require the creation of additional DNS records. It is suggested that those records be placed under an "_spf" subdomain. See Appendix B for examples. 2.1.4 Multiple Strings Text DNS records (both TXT and text RR types) can be composed of more than one string. If a published record contains multiple strings, then record MUST be treated as if those strings are concatenated together without adding spaces. For example: TXT "v=spf1 .... first" "second string..." MUST be treated as equivalent to TXT "v=spf1 .... firstsecond string..." TXT records containing multiple strings are useful in order to construct longer records which would otherwise exceed the maximum length of a string within a TXT or text RR record. It is STRONGLY ENCOURAGED that published records remain under 400 characters of text in order to keep DNS queries from falling over to TCP. [[ This limit needs to be checked. ]] Note: Many nameserver implementations will silently split long strings in TXT records into several shorter strings. 3 The check_host() Function Wong & Lentczner Expires January 9, 2005 [Page 5] Internet-Draft The SPF Record Format and Test Protocol July 2004 The check_host() function fetches published records, parses them, and interprets them to evaluate if a particular host is or is not permitted to send mail in a given context. Mail receivers that perform this check MUST correctly implement the check_host() function as described by the canonical algorithm defined here. Implementations MAY use a different algorithm, so long as the results are the same. 3.1 Arguments The function check_host() take three arguments: - the IP address of the host under test - the domain to check - the full sending mailbox address See [MARID Core] for how these arguments are determined. The domain portion of will usually be the same as the argument when check_host() is initially evaluated. However, it will generally not be the same during recursive evaluations (see "include" below) Note: The IP address may be either v4 or v6. 3.2 Results The function check_host() can result in one of seven results described here. Possible actions to be taken based on these results are decided by the checks a mail receiver is performing (see [MARID Core]) and by the local policies of the receiver. Results from interpreting valid records: Neutral (?): published data is explicitly inconclusive Pass (+): the is in the permitted set Fail (-): the is in the not permitted set SoftFail (~): the may be in the not permitted set Results from error conditions: None: no published data TempError: transient error during DNS lookup or other processing PermError: unrecoverable error during processing, such as an error in the record format If the result is "Fail", then an additional reason is returned. The reason may be one of: Not Permitted Wong & Lentczner Expires January 9, 2005 [Page 6] Internet-Draft The SPF Record Format and Test Protocol July 2004 Malformed Domain Domain Does Not Exist If the reason is "Not Permitted", then an explanation string is also returned. The explanation string may be empty. 3.3 Initial Processing If the is not an FQDN, the check_host() immediately returns the result "Fail" and a reason of "Malformed Domain". If the has no localpart, substitute the string "postmaster" for the localpart. 3.4 Record Lookup The record for is fetched. If the record is in a cache, and has not expired, then it may simply be used. Otherwise, the record must be fetched from DNS as follows: In accordance with how the records are published, (see 2.1 above), a DNS query needs to be made for the name. If no matching records are returned, check_host() exits immediately with the result "None". If the domain does not exist (NXDOMAIN), check_host() exits immediately with the result "Fail" and a reason of "Domain Does Not Exist" If the DNS lookup returns a server failure (SERVFAIL) or the query times out, check_host() exits immediately with the result "TempError" 3.4.1 Matching Version Only records which begin with a proper version section are considered. The version section is defined as: version = "v=spf1" The version section is terminated either by a SP character, or the end of the TXT record. Hence, a records that start "v=spf10", or "v=spf1.0" are not considered records with proper versions. If there is only one such record, it is used. If there are two such records, one TXT and one new text RR, then the later MUST be used. If two or more such records exist of the same type, then check_host() exists immediately with the error "PermError". Wong & Lentczner Expires January 9, 2005 [Page 7] Internet-Draft The SPF Record Format and Test Protocol July 2004 3.5. Record Evaluation After the record has been retrieved, the check_host() function parses and interprets it to find a result for the current test. If at any point a syntax error is encountered, check_host() returns immediately with the result "PermError". Implementations MAY choose to parse the entire record first and return "PermError" if the record is not well formed. See section 6.1. 3.5.1 Term Evaluation There are two types of terms: mechanisms and modifiers. A given mechanism type may always appear multiple times in a record. Modifiers may be constrained to appear at most once per record, depending on the definition of the modifier. Unknown mechanisms cause processing to abort with the result "PermError". Unknown modifiers are ignored. An record contains an ordered list of mechanisms and modifiers: record = version *( 1*SP ( directive / modifier ) ) *SP version = "v=spf1" directive = [ prefix ] mechanism prefix = "+" / "-" / "?" / "~" mechanism = name [ ":" macro-string ] *[ "/" *DIGIT ] modifier = name "=" macro-string name = alpha *( alpha / digit / "-" / "_" / "." ) Mechanisms usually contain a ":" or "/" character after the name. Modifiers always contain an equals ('=') character immediately after the name, and before any ":" or "/" characters that may be part of the macro-string. Terms that do not contain any of "=", ":" or "/" are mechanisms. Mechanism and modifier names are case-insensitive. A mechanism "INCLUDE" is equivalent to "include". 3.5.2 Mechanisms Each mechanism is considered in turn from left to right. Wong & Lentczner Expires January 9, 2005 [Page 8] Internet-Draft The SPF Record Format and Test Protocol July 2004 When a mechanism is evaluated, one of three things can happen: it can match, it can not match, or it can throw an exception. If it matches, processing ends and the prefix value is returned as the result of that record. (The default prefix value is "+".) If it does not match, processing continues with the next mechanism. If no mechanisms remain, the default result is specified in section 3.6. If it throws an exception, mechanism processing ends and the exception value is returned. The possible prefixes, and the results they return are: "+" Pass "-" Fail "~" SoftFail "?" Neutral A missing prefix for a mechanism is the same as a prefix of "+". When a mechanism matches, and the prefix is "-" so that a "Fail" result is returned, the reason is Not Permitted, and the explanation string is computed as described in section 5.2. Specific mechanisms are described in Section 4. 3.5.3 Modifiers Modifiers are either global or positional: Global modifiers MAY appear anywhere in the record, but SHOULD appear at the end, after all mechanisms and positional modifiers. Positional modifiers apply only to the mechanism they follow. It is a syntax error for a positional modifier to appear before the first mechanism. Modifiers of either type are also either singular or multiple: Singular modifiers may appear only once in the record if they are global, or once after each mechanism if they are positional. Multiple modifiers may appear multiple times in the record if they are global, or multiple times after each mechanism if they are positional. The definition of each specific modifier (see Section 5) states Wong & Lentczner Expires January 9, 2005 [Page 9] Internet-Draft The SPF Record Format and Test Protocol July 2004 whether it is global or positional, and whether it is singular or multiple. A modifier is not allowed to be defined as both global and positional. Ordering of modifiers does not matter, except: 1) positional modifiers must appear after the mechanism they affect and before any subsequent mechanisms. and 2) when a multiple modifier appears more than one time, the ordering of the appearances may be significant. Other than these constraints, implementations MUST treat different orders of modifiers the same. An intended side effect of these rules is modifiers cannot be defined that modify other modifiers. These rules allow an implementation to correctly preparse a record. Furthermore, they are crafted to allow the parsing algorithm to be stable, even when new modifiers are introduced. Modifiers which are unrecognized MUST be ignored. This allows older implementations to handle records with modifiers that were defined after they were written. 3.6 Default result If none of the mechanisms match and there is no redirect modifier, then the check_host() exists with a result of "Neutral". If there is a redirect modifier, check_host() proceeds as defined in section 5.1. Note that records SHOULD always either use a redirect modifier or an "all" mechanism to explicitly terminate processing. For example: v=spf1 +mx -all or v=spf1 +mx redirect=_spf.example.com 4. Mechanism Definitions This section defines two types of mechanisms. Basic mechanisms contribute to the language framework. They do not specify a particular type of authorization scheme. all include Designated sender mechanisms are used to designate a set of Wong & Lentczner Expires January 9, 2005 [Page 10] Internet-Draft The SPF Record Format and Test Protocol July 2004 address as being permitted or not to use the for sending mail. a ip4 mx ip6 ptr exists Other mechanisms may be defined in the future. Mechanisms either match, do not match, or throw an exception. If they match, their prefix value is returned. If they do not match, processing continues. If they throw an exception, the exception value is returned. Several of these mechanisms take an optional argument. If the is present, then it is macro expanded (see Section 7) and becomes the . If the is not provided, the is used as the . The following conventions apply to all mechanisms that perform an comparison between and an IP address at any point: If no CIDR-length is given in the directive, then and the IP address are compared for equality. If a CIDR-length is specified, then only the specified number of high-order bits of and the IP address are compared for equality. When any mechanisms fetchs host addresses to compare with , when is an IPv4 address, A records are fetched, when is an IPv6 address, AAAA records are fetched. 4.1 "all" all = "all" The "all" mechanism is a test that always matches. It is used as the rightmost mechanism in a record to provide an explicit default. For example: v=spf1 +mx +a -all Mechanisms after "all" will never be tested. 4.2 "include" include = "include" ":" domain-spec Wong & Lentczner Expires January 9, 2005 [Page 11] Internet-Draft The SPF Record Format and Test Protocol July 2004 The "include" mechanism triggers a recursive evaluation of check_host(). The domain-spec is expanded as per section 7. Then check_host() is evaluated with the resulting string as the . The and arguments remain the same as current evaluation of check_host(). "Include" makes it possible for one domain to designate multiple administratively independent domains. For example, a vanity domain "example.net" might send mail using the servers of administratively independent domains example.com and example.org. Example.net could say "v=spf1 include:example.com include:example.org -all". That would direct check_host() to, in effect, check the records of example.com and example.org for a "pass" result. Only if the host were not permitted for either of those domains would the result be "Fail". This mechanism matches when the recursive check_host() result returns a "Pass", and doesn't match when the result is "Fail", "SoftFail", or "Neutral". If the result is "TempError", "PermError" or "None", then processing of the current check_host() stops immediately and returns either "TempError" in the first case, or "PermError" in the second two.. recursive include check_host() mechanism result result processing --------- -- ---------------- ----------------------------------- Pass => match, return based on prefix of "include" Fail => no match, continue processing SoftFail => no match, continue processing Neutral => no match, continue processing TempError => throw TempError, abort processing, return TempError PermError => throw PermError, abort processing, return PermError None => throw PermError, abort processing, return PermError The Include mechanism is intended for crossing administrative boundaries. While it is possible to use includes to consolidate multiple domains that share the same set of designated hosts, domains are encouraged to use redirects where possible, and to minimize the number of includes within a single administrative domain. For example, if example.com and example.org were managed by the same entity, and if the permitted set of hosts for both domains were Wong & Lentczner Expires January 9, 2005 [Page 12] Internet-Draft The SPF Record Format and Test Protocol July 2004 "mx:example.com", it would be possible for example.org to specify "include:example.com", but it would be preferable to specify "redirect=example.com" or even "mx:example.com". 4.3 "a" This mechanism matches if is one of the 's IP addresses. A = "a" [ ":" domain-spec ] [ dual-cidr-length ] The is compared to the IP address(es) of the . If any address matches, the mechanism matches. 4.4 "mx" This mechanism matches if is one of the MX hosts for a domain name. MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] check_host() first performs an MX lookup on the . Then perform an A lookup on each MX name returned, in order of MX priority. The is compared to each returned IP address. If any address matches, the mechanism matches. Note Regarding Implicit MXes: If the has no MX records, check_host() MUST NOT pretend the target is its single MX, and MUST NOT default to an A lookup on the directly. This behavior breaks with the legacy "implicit MX" rule. See [RFC 2821] Section 5. If such behavior is desired, the publisher should specify an "a" directive. 4.5 "ptr" This mechanism tests if 's name is within a particular domain. PTR = "ptr" [ ":" domain-spec ] First the 's name is looked up using this procedure: perform a PTR lookup against . For each record returned, validate the host name by looking up its IP address. If is among the returned IP addresses, then that host name is validated. In pseudocode: sending-host_names := ptr_lookup(sending-host_IP); for each name in (sending-host_names) { IP_addresses := a_lookup(name); if the sending-host_IP is one of the IP_addresses { Wong & Lentczner Expires January 9, 2005 [Page 13] Internet-Draft The SPF Record Format and Test Protocol July 2004 validated_sending-host_names += name; } } Check all validated hostnames to see if they end in the domain. If any do, this mechanism matches. If no validated hostname can be found, or if none of the validated hostnames end in the , this mechanism fails to match. Pseudocode: for each name in (validated_sending-host_names) { if name ends in , return match. if name is , return match. } return no-match. This mechanism matches if the is an ancestor of the name of , or if the and the name of are the same. For example: "mail.example.com" is within the domain "example.com", but "mail.bad-example.com" is not. If a validated hostname is the , a match results. Note: This mechanism represents a burden on the reverse DNS tree. Therefore, it should be used only as a last resort, if domain policy cannot be expressed using alternative mechanisms. If a domain decides to use it, it should ensure it has the proper PTR records in place for its hosts. 4.6 "ip4" and "ip6" These mechanisms test if falls into a given IP network. IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] ip4-cidr-length = "/" 1*DIGIT ip6-cidr-length = "/" 1*DIGIT ip4-network = as per conventional dotted quad notation, e.g. 192.0.2.0 ip6-network = as per [RFC 3513], section 2.2, e.g. 12AB:0:0::CD30 The is compared to the given network. If they match, the mechanism matches. If the cidr-length is omitted, the ip4-cidr-length is taken to be "/32" and the ip6-cidr-length is taken to be "/128". Note: These mechanisms do not require any additional DNS lookups, and represent the least burden on the DNS. They are recommended. 4.7 "exists" This mechanism is used to construct an arbitrary host name that is Wong & Lentczner Expires January 9, 2005 [Page 14] Internet-Draft The SPF Record Format and Test Protocol July 2004 used for a DNS A record query. It allows for complicated schemes involving arbitrary parts of the mail envelope to determine what is legal. exists = "exists" ":" domain-spec The domain-spec is expanded as per Section 7. The resulting domain name is used for a DNS A lookup. If any A record is returned, this mechanism matches. The lookup type is 'A' even when the connection type is IPv6. Domains can use this mechanism to specify arbitrarily complex queries. For example, suppose example.com publishes the record: v=spf1 exists:%{ir}.%{l1r+-}._spf.%{d} -all The target-name might expand to "1.2.0.192.someuser._spf.example.com". This makes fine-grained decisions possible at the level of the user and client IP address. This mechanism enable queries that mimic the style of tests that existing RBL lists use. 5. Modifier Definitions Modifiers are not mechanisms: they do not return match or no-match. Instead they provide additional information or alter check_host() processing. Global modifiers affect the entire record, whereas positional modifiers only affect the preceeding mechanism in the record. While unrecognized mechanisms cause an immediate "PermError" abort, unrecognized modifiers MUST be simply ignored. Modifiers therefore provide an way to extend the record format in the future with backward compatibility. Only two modifiers are currently defined: "redirect" and "exp". Implementations of check_host() MUST support them both. This document reserves two modifiers for future definition: "accredit" and "match_subdomains". Until these are defined, implementations SHOULD ignore them. There is also one deprecated modifier: "default". Implementations MUST ignore it. 5.1 redirect: Redirected Query The "redirect" modifier is global and singular. Wong & Lentczner Expires January 9, 2005 [Page 15] Internet-Draft The SPF Record Format and Test Protocol July 2004 If all mechanisms fail to match, and a redirect modifier is present, then processing proceeds as follows. redirect = "redirect" "=" domain-spec The domain-spec portion of the redirect section is expanded as per the macro rules in section 7. Then check_host() is evaluated with the resulting string as the . The and arguments remain the same as current evaluation of check_host(). The result of this new evaluation of check_host() is then considered the result of current evaluation. Note that the newly queried domain may itself specify redirect processing. This facility is intended for use by organizations that wish to apply the same record to multiple domains. For example: la.example.com. TXT "v=spf1 redirect=_spf.example.com" ny.example.com. TXT "v=spf1 redirect=_spf.example.com" sf.example.com. TXT "v=spf1 redirect=_spf.example.com" _spf.example.com. TXT "v=spf1 mx:example.com -all" In this example, mail from any of the three domains is described by the same record. This can be an administrative advantage. Note: In general, a domain A cannot reliably use a redirect to another domain B not under the same administrative control. Since the stays the same, there is no guarantee that the record at domain B will correctly work for addresses in domain A, especially if domain B uses mechanisms involving localparts. An "include" directive may be more appropriate. For clarity it is RECOMMENDED that any redirect modifier appear as the very last term in a record. 5.2 exp: Explanation The "exp" modifier is global and singular. explanation = "exp" "=" domain-spec If check_host() results in a "Fail" due to a mechanism match (such as "-all"), and the exp modifier is present, then the explanation string returned is computed as described below. If no exp modifier is present, then an empty explanation string is returned. Wong & Lentczner Expires January 9, 2005 [Page 16] Internet-Draft The SPF Record Format and Test Protocol July 2004 The argument to the explanation modifier is a domain-spec. The DNS TXT record for that domain is fetched either from a cache or via a query to DNS. If there are any processing errors, temporary (such as SERVFAIL) or permanent (such as NXDOMAIN), or if no records are returned, or if more than one record is returned, then the explanation string empty with no further computation. The fetched TXT record's strings are concatenated with no spaces, and then treated as a macro-string that is macro-expanded. This final result is the explanation string. Software evaluating check_host() can use this string when the result is "Fail" with a reason of "Not Permitted", to communicate information from the publishing domain in the form of a short message or URL. See [MARID Core]. Implementations MAY limit the length of the resulting explanation string to allow for other protocol constraints and/or reasonable processing limits. Suppose example.com has this record v=spf1 mx -all exp=explain._spf.%{d} Here are some examples of possible explanation TXT records at explain._spf.example.com: Example.com mail should only be sent by its own servers. -- a simple, constant message %{i} is not one of %{d}'s designated mail servers. -- a message with a little more info, including the -- IP address that failed the check See http://%{d}/why.html?s=%{S}&i=%{I} -- a complicated example that constructs a URL with -- the parameters check_host() so that a web page can -- be generated with detailed, custom instructions Note: During recursion into an Include mechanism, explanations do not propagate out. But during execution of a Redirect modifier, the explanation string from the target of the redirect is used. 6. Miscellaneous 6.1 Unrecognized Mechanisms and Modifiers Future extensions to this standard may introduce new mechanisms and Wong & Lentczner Expires January 9, 2005 [Page 17] Internet-Draft The SPF Record Format and Test Protocol July 2004 modifiers. Unrecognized mechanisms cause processing to abort: If, during evaluation of a record, check_host() encounters a mechanism which it does not understand, then it terminates processing and returns "PermError", without evaluating any further mechanisms. Mechanisms listed before the unknown mechanism MUST, however, be evaluated. For example, consider the record: v=spf1 a mx ptr foo:_foo.%{d} -all If, during the evaluation of check_host(), any of the "a", "mx", or "ptr" directives match, then check_host() would return a "Pass" result. If none of those directives resulted in a match, then an implementation that did not recognize the "foo" mechanism would return "PermError". An implementation that did recognize the "foo" mechanism would be able to perform an extended evaluation. Note: "foo" is an example of an unknown extension mechanism that could be defined in future versions of this standard. It is NOT defined by this proposal. Unrecognized modifiers are ignored: if an implementation encounters modifiers which it does not recognize, it MUST ignore them. 6.2 Processing Limits During processing, an check_host() may require additional evaluations of check_host() due to the Include mechanism and/or the Redirect modifier. Implementations must be prepared to handle records that are set up incorrectly or maliciously. Implementations MUST perform loop detection, limit additional evaluations, or both. If an implementation chooses to limit additional evaluations, then at least a total of 10 evaluations of check_host() for a single query MUST be supported. (This number should be enough for even the most complicated configurations.) If a loop is detected, or evaluation limit of an implementation is reached, check_host() MUST abort processing and return the result "PermError". MTAs or other processors MAY also impose a limit on the maximum amount of elapsed time to evaluate check_host(). Such a limit SHOULD allow at least 20 seconds. If such a limit is exceeded, the result of authentication SHOULD be "TempError". Wong & Lentczner Expires January 9, 2005 [Page 18] Internet-Draft The SPF Record Format and Test Protocol July 2004 Domains publishing records SHOULD try keep the number of include directives, and chained redirect modifiers to a minimum. Domains SHOULD also try to minimize the amount of other DNS information needed to evaluate a record. This can be done by choosing directives that require less DNS information. For example, consider a domain set up as: example.com. IN MX 10 mx.example.com. mx.example.com. IN A 192.0.2.1 a.example.com. IN TXT "v=spf1 +mx:example.com -all" b.example.com. IN TXT "v=spf1 +a:mx.example.com -all" c.example.com. IN TXT "v=spf1 +ip4:192.0.2.1 -all" Evaluating check_host() for the domain "a.example.com" requires the MX records for "example.com", and then the A for records for the listed hosts. Evaluating for "b.example.com" only requires the A records. Evaluating for "c.example.com" requries none. However, there may be administrative considerations: Using "a" over "ip4" allows hosts to be renumbered easily. Using "mx" over "a" allows the set of mail hosts to be changed easily. 7. Macros 7.1 Macro definitions Certain terms perform macro interpolation on their arguments. macro-string = *( macro-char / VCHAR ) macro-char = ( "%{" ALPHA transformer *delimiter "}" ) / "%%" / "%_" / "%-" transformer = [ *DIGIT ] [ "r" ] delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" A literal "%" is expressed by "%%". "%_" expands to a single " " space. "%-" expands to a URL-encoded space, viz. "%20". The following macro letters are expanded in term arguments: s = l = local-part of o = domain of d = i = v = the string "in-addr" for if is ipv4, Wong & Lentczner Expires January 9, 2005 [Page 19] Internet-Draft The SPF Record Format and Test Protocol July 2004 or "ip6" if is ipv6 The following macro letters are only allowed in "exp" text: c = SMTP client IP (in easily readable format) r = domain name of host performing the check t = current timestamp in UTC epoch seconds notation The uppercase versions of all these macros are URL-encoded. A '%' character not followed by a '{', '%', '-', or '_' character MUST be interpreted as a literal. Domains SHOULD NOT rely on this feature; they MUST escape % literals. For example, an explanation TXT record Your spam volume has increased by 581% is incorrect. Instead, say Your spam volume has increased by 581%% Legal optional transformers are: *DIGIT ; zero or more digits 'r' ; reverse value, splitting on dots by default If transformers or delimiters are provided, the macro strings are split into parts. After performing any reversal operation or removal of left-hand parts, the parts are rejoined using "." and not the original splitting characters. By default, strings are split on "." (dots). Macros may specify delimiter characters which are used instead of ".". Delimiters MUST be one or more of the characters: "." / "-" / "+" / "," / "/" / "_" / "=" The 'r' transformer indicates a reversal operation: if the client IP address were 192.0.2.1, the macro %{i} would expand to "192.0.2.1" and the macro %{ir} would expand to "1.2.0.192". The DIGIT transformer indicates the number of right-hand parts to use, after optional reversal. If a DIGIT is specified, the value MUST be nonzero. If no DIGITs are specified, or if the value specifies more parts than are available, all the available parts are used. If the DIGIT was 5, and only 3 parts were available, the macro interpreter would pretend the DIGIT was 3. Implementations MUST support at least a value of 128, as that is the maximum number of labels in a domain name. The "s" macro expands to the argument. It is an email Wong & Lentczner Expires January 9, 2005 [Page 20] Internet-Draft The SPF Record Format and Test Protocol July 2004 address with a localpart, an "@" character, and a domain. The "l" macro expands to just the localpart. The "o" macro expands to just the domain part. Note that these values remain the same during a recursive and chained evaluations due to "include" and/or "redirect". Note also that if the original had no localpart, the localpart was set to "postmaster" in initial processing (see section 3.3). For IPv4 addresses, both the "i" and "c" macros expand to the standard dotted-quad format. For IPv6 addresses, the "i" macro expands to dot-format address; it is intended for use in %{ir}. The "c" macro may expand to any of the hexadecimal colon-format addresses specified in [RFC 3513] section 2.2. It is intended for humans to read. The "r" macro expands to the name of the receiving MTA. This SHOULD be a fully qualified domain name, but if one does not exist (as when the checking is done by a script) or if policy restrictions dictate otherwise, the word "unknown" SHOULD be substituted. The domain name MAY be different than the name found in the MX record that the client MTA used to locate the receiving MTA. Any unrecognized macro letters are expanded as the string "unknown". There are two deprecated macro letters: "p" and "h". These are expanded as the string "deprecated". When the result of macro expansion is used in a domain name query, if the expanded domain name exceeds 255 characters (the maximum length of a domain name), the left side is truncated to fit, by removing successive subdomains until the total length falls below 255 characters. Uppercased macros expand exactly as their lower case equiavalents, and are then URL escaped. URL escaping is described in [RFC 2396]. Note: Domains should avoid, where possible, the "s", "l" or "o" macros in conjunction with any mechanism directive. While these macros are powerful and allow per-user records to be published, they severely limit the ability of implementations to cache results of check_host() and they reduce the effectiveness of DNS caches. Implementations should be aware that if no directive processed during the evaluation of check_host() contains an "s", "l", or "o" macro, then the results of the evaluation can be cached on the basis of and alone for as long as the shortest TTL of all the DNS records involved. Wong & Lentczner Expires January 9, 2005 [Page 21] Internet-Draft The SPF Record Format and Test Protocol July 2004 7.2 Expansion Examples The is strong-bad@email.example.com. The IPv4 SMTP client IP is 192.0.2.3. The IPv6 SMTP client IP is 5f05:2000:80ad:5800::1. The PTR domain name of the client IP is mx.example.org. macro expansion ------- ---------------------------- %{s} strong-bad@email.example.com %{o} email.example.com %{d} email.example.com %{d4} email.example.com %{d3} email.example.com %{d2} example.com %{d1} com %{dr} com.example.email %{d2r} example.email %{l} strong-bad %{l-} strong.bad %{lr} strong-bad %{lr-} bad.strong %{l1r-} strong macro-string expansion --------------------------------------------------------------------- %{ir}.%{v}._spf.%{d2} 3.2.0.192.in-addr._spf.example.com %{lr-}.lp._spf.%{d2} bad.strong.lp._spf.example.com %{lr-}.lp.%{ir}.%{v}._spf.%{d2} bad.strong.lp.3.2.0.192.in-addr._spf.example.com %{ir}.%{v}.%{l1r-}.lp._spf.%{d2} 3.2.0.192.in-addr.strong.lp._spf.example.com %{d2}.trusted-domains.example.net example.com.trusted-domains.example.net IPv6: %{ir}.%{v}._spf.%{d2} 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8. 5.d.a.0.8.0.0.0.2.5.0.f.5.ip6._spf.example.com 8. Security Considerations There are two aspects of this protocol that malicious parties could exploit to undermine the validity of the check_host() function: The evaluation of check_host() relies heavily on DNS. A malicious Wong & Lentczner Expires January 9, 2005 [Page 22] Internet-Draft The SPF Record Format and Test Protocol July 2004 attacker could poison a target's DNS cache with spoofed DNS data, and cause check_host() to return incorrect results, including "Pass" for an value where the actual domain's record would evaluate to "Fail". The client IP address, , is assumed to be true and correct. A malicious attacker could spoof TCP sequences to make mail appear to come from a permitted host for a domain that the attacker is impersonating. As with most aspects of mail, there are a number of ways that malicious parties could use the protocol as an avenue of a distributed denial of service attack: While implementations of check_host() need to limit the number of includes and redirects and/or check for loops, malicious domains could published records that exercise or exceed these limits in an attempt to waste computation effort at their targets when they send them mail. Malicious parties could send large volume mail purporting to come from the intended target to a wide variety of legitimate mail hosts. These legitimate machines would then present a DNS load on the target as they fetched the relevant records. While these distributed denial of service attacks are possible, they seem more convoluted to mount, and have less of an impact, than other simpler attacks. 9. IANA Considerations The IANA will need to maintain one registry in support of this specification. The registry consists of the modifiers as described in section 3.5.3 and section 5. [[Missing application review policy]] 9.1 Registration Template To: ietf-types@iana.org Subject: Registration of SPF Modifier XXX Modifier name: Type: (Global or Positional) Appearance: (Single or Multiple) Wong & Lentczner Expires January 9, 2005 [Page 23] Internet-Draft The SPF Record Format and Test Protocol July 2004 Security considerations: Interoperability considerations: Published specification: Person & email address to contact for further information: Author/Change controller: (Any other information that the author deems interesting may be added below this line.) [[This template needs to be reviewed]] 10. Contributors and Acknowledgements This design owes a debt of parentage to RMX (by Hadmut Danisch in 2003) and to DMP (by Gordon Fecyk in 2003). It traces its ancestry farther back through "Repudiating Mail-From" by Paul Vixie in 2002 to a suggestion by Jim Miller in 1998. Philip Gladstone contributed macros to the specification, multiplying the expressiveness of the language and making per-user and per-IP lookups possible. The authors would also like to thank the literally hundreds of individuals who have participated in the development of this design. There are far too numerous to name, but they include: The folks on the SPAM-L mailing list. The folks on the ASRG and MARID/MXCOMP mailing lists. The folks on the spf-discuss mailing list. The folks on the mailing list that shall not be named. The folks on #perl and #spf. Normative References [RFC 1034] Mockapetris, P., "Domain names - concepts and facilities", RFC 1034, November 1987. [RFC 2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", RFC 2119, March 1997. [RFC 2234] Crocker, D.H. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", RFC 2234, November 1997. [RFC 2396] Berners-Lee, T., R.T. Fielding and L. Masinter, Wong & Lentczner Expires January 9, 2005 [Page 24] Internet-Draft The SPF Record Format and Test Protocol July 2004 "Uniform Resource Identifiers (URI): Generic Syntax", RFC 2396, August 1998. [RFC 3513] Hinden, R. and S. Deering, "Internet Protocol Version 6 (IPv6) Addressing Architecture", RFC 3513, April 2003. Informative References [RFC 2821] Klensin, J., "Simple Mail Transfer Protocol", RFC 2821, April 2001. [RFC 3668] Bradner, S., "Intellectual Property Rights in IETF Technology", RFC 3668, February 2004. [MARID Core] Lyon, J. and M. Wong, "MTA Authentication Records in DNS", Work In Progress, to be published as draft-ietf-marid-core-02.txt, expected July 2004. [RMX] Danisch, Hadmut., "The RMX DNS RR Type for light weight sender authentication", Work In Progress, http://www.danisch.de/work/security/antispam.html, October 2003. [DMP] Fecyk, Gordon., "Designated Mailers Protocol", http://www.pan-am.ca/dmp/, Work In Progress, December 2003. [Vixie] Vixie, Paul., "Repudiating Mail-From", http://ops.ietf.org/lists/namedroppers/ namedroppers.2002/msg00658.html Authors' Addresses Meng Weng Wong Singapore mengwong+spf@pobox.com Mark Lentczner 1209 Villa Street Mountain View, CA 94041 United States of America markl@glyphic.com Comments Comments on this draft are welcome. In the interests of openness, rather than contacting the authors directly, please post to either: Wong & Lentczner Expires January 9, 2005 [Page 25] Internet-Draft The SPF Record Format and Test Protocol July 2004 the ietf-mxcomp mailing list http://www.imc.org/ietf-mxcomp/index.html or the spf-discuss mailing list. http://spf.pobox.com/mailinglist.html Appendix A. Collected ABNF This section is normative and any discrepancies with the ABNF fragments in the preceding text are to be resolved in favor of this grammar. See [RFC 2234] for ABNF notation. record = version *( 1*SP ( directive / modifier ) ) *SP version = "v=spf1" directive = [ prefix ] mechanism prefix = "+" / "-" / "?" / "~" mechanism = ( all / include / A / MX / PTR / IP4 / IP6 / exists / unknown-mechanism ) all = "all" include = "include" ":" domain-spec A = "a" [ ":" domain-spec ] [ dual-cidr-length ] MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ] PTR = "ptr" [ ":" domain-spec ] IP4 = "ip4" ":" ip4-network [ ip4-cidr-length ] IP6 = "ip6" ":" ip6-network [ ip6-cidr-length ] exists = "exists" ":" domain-spec unknown-mechanism = name [ ":" macro-string ] *[ "/" *DIGIT ] modifier = redirect / explanation / unknown-modifier redirect = "redirect" "=" domain-spec explanation = "exp" "=" domain-spec unknown-modifier = name "=" macro-string domain-spec = domain-name / macro-string domain-name = domain-part *( "." domain-part ) [ "." ] domain-part = as defined in [RFC 1034] ip4-network = as per conventional dotted quad notation, Wong & Lentczner Expires January 9, 2005 [Page 26] Internet-Draft The SPF Record Format and Test Protocol July 2004 e.g. 192.0.2.0 ip6-network = as per [RFC 3513], section 2.2, e.g. 12AB:0:0::CD30 dual-cidr-length = [ ip4-cidr-length ] [ "/" ip6-cidr-length ] ip4-cidr-length = "/" 1*DIGIT ip6-cidr-length = "/" 1*DIGIT macro-string = *( macro-char / VCHAR ) macro-char = ( "%{" ALPHA transformer *delimiter "}" ) / "%%" / "%_" / "%-" transformer = [ *DIGIT ] [ "r" ] name = ALPHA *( ALPHA / DIGIT / "-" / "_" / "." ) delimiter = "." / "-" / "+" / "," / "/" / "_" / "=" Appendix B. Extended Examples These examples are based on the following DNS setup: ; A domain with two mail servers, two hosts ; and two servers at the domain name $ORIGIN example.com. @ MX 10 mail-a MX 20 mail-b A 192.0.2.10 A 192.0.2.11 amy A 192.0.2.65 bob A 192.0.2.66 mail-a A 192.0.2.129 mail-b A 192.0.2.130 www CNAME example.com. ; A related domain $ORIGIN example.org @ MX 10 mail-c mail-c A 192.0.2.140 ; The reverse IP for those addresses $ORIGIN 2.0.192.in-addr.arpa. 10 PTR example.com. 11 PTR example.com. 65 PTR amy.example.com. 66 PTR bob.example.com. 129 PTR mail-a.example.com. Wong & Lentczner Expires January 9, 2005 [Page 27] Internet-Draft The SPF Record Format and Test Protocol July 2004 130 PTR mail-b.example.com. 140 PTR mail-c.example.org. ; A rogue reverse IP domain that claims to be ; something it's not $ORIGIN 0.0.10.in-addr.arpa. 4 PTR bob.example.com. B.1 Simple Examples These examples show various possible published records for example.com and which values if would cause check_host() to return "Pass". Note that is "example.com". v=spf1 +all -- any passes v=spf1 a -all -- hosts 192.0.2.10 and 192.0.2.11 pass v=spf1 a:example.org -all -- no sending hosts pass since example.org has no A records v=spf1 mx -all -- sending hosts 192.0.2.129 and 192.0.2.130 pass v=spf1 mx:example.org -all -- sending host 192.0.2.140 passes v=spf1 mx mx:example.org -all -- sending hosts 192.0.2.129, 192.0.2.130, and 192.0.2.140 pass v=spf1 mx/8 mx:example.org/8 -all -- any sending host in 192.0.2.128/24 or 192.168.2.136/8 passes v=spf1 ptr -all -- sending host 192.0.2.65 passes (reverse IP is valid and in example.com) -- sending host 192.0.2.140 fails (reverse IP is valid, but not in example.com) -- sending host 10.0.0.4 fails (reverse IP is not valid) v=spf1 ip4:192.0.2.128/28 -all -- sending host 192.0.2.65 fails -- sending host 192.0.2.129 passes Wong & Lentczner Expires January 9, 2005 [Page 28] Internet-Draft The SPF Record Format and Test Protocol July 2004 B.2 Multiple Domain Example These examples show the effect of related records: example.org: "v=spf1 include:example.com include:example.net -all" This record would be used if mail from example.org actually came through servers at example.com and example.net. Example.org's designated servers are the union of example.com and example.net's designated servers. la.example.org: "v=spf1 redirect=example.org" ny.example.org: "v=spf1 redirect=example.org" sf.example.org: "v=spf1 redirect=example.org" These records allow a set of domains that all use the same mail system to make use of that mail system's record. In this way, only the mail system's record needs to updated when the mail setup changes. These domains' records never have to change. B.3 RBL Style Example Imagine that, in addition to the domain records listed above, there are these: $Origin _spf.example.com. mary.mobile-users A 127.0.0.2 fred.mobile-users A 127.0.0.2 15.15.168.192.joel.remote-users A 127.0.0.2 16.15.168.192.joel.remote-users A 127.0.0.2 The following records describe users at example.com who mail from arbitrary servers, or who mail from personal servers. example.com: "v=spf1 mx include:mobile-users._spf.%{d} include:remote-users._spf.%{d} -all" mobile-users._spf.example.com: "v=spf1 exists:%{l1r+}.%{d}" remote-users._spf.example.com: "v=spf1 exists:%{ir}.%{l1r+}.%{d}" Intellectual Property Statement Wong & Lentczner Expires January 9, 2005 [Page 29] Internet-Draft The SPF Record Format and Test Protocol July 2004 The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79. Copies of IPR disclosures made to the IETF Secretariat and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr. The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at ietf-ipr@ietf.org. Disclaimer of Validity This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Copyright Statement Copyright (C) The Internet Society (2004). This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights. Acknowledgment Funding for the RFC Editor function is currently provided by the Internet Society. Wong & Lentczner Expires January 9, 2005 [Page 30]