RFC 7873
Domain Name System (DNS) Cookies
RFC 7873: Domain Name System (DNS) Cookies โจ
okay bestie, this one is RFC 7873, all about DNS Cookies ๐ช It's a Standards Track doc from the IETF (Internet Engineering Task Force) stream, published as RFC 7873 back in May 2016. It was written by D. Eastlake 3rd (from Huawei) and M. Andrews (from ISC), and the ISSN is 2070-1721. The header doesn't list any "Obsoletes" or "Updates" lines, so it isn't marked as replacing or changing any other RFC ๐ธ
Abstract
okay so DNS Cookies are a lightweight security mechanism for DNS transactions ๐ฆ They give DNS servers and clients limited protection against denial-of-service attacks, amplification attacks, and forgery or cache poisoning attacks, which are all getting more common, and they're usually pulled off by off-path attackers (people who can't see the messages going back and forth). The mechanism works fine with NAT, NAT-PT (Network Address Translation - Protocol Translation), and anycast, and you can roll it out bit by bit ๐ Also, because a cookie only gets sent back to the IP address it first came from, it can't be used to generally track Internet users. Not creepy at all, iykyk ๐ซถ
Status of This Memo
This is an Internet Standards Track document ๐
It's a product of the IETF, it reflects what the IETF community agreed on, it got public review, and the Internet Engineering Steering Group (IESG) approved it for publication. If you want more on Internet Standards, check Section 2 of RFC 7841 ๐
For the current status, any errata, and how to send feedback, go to http://www.rfc-editor.org/info/rfc7873 ๐
Copyright Notice
Copyright (c) 2016 IETF Trust and the persons identified as the document authors. All rights reserved. ๐
This document falls under BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info), as they stood on the publication date. Read those carefully, because they spell out what you're allowed to do with this doc ๐ง Any Code Components pulled out of this document have to include the Simplified BSD License text, as described in Section 4.e of the Trust Legal Provisions. They come with no warranty, same as the Simplified BSD License says โจ
Table of Contents
1. Introduction ....................................................4
1.1. Contents of This Document ..................................4
1.2. Definitions ................................................5
2. Threats Considered ..............................................5
2.1. Denial-of-Service Attacks ..................................6
2.1.1. DNS Amplification Attacks ...........................6
2.1.2. DNS Server Denial of Service ........................6
2.2. Cache Poisoning and Answer Forgery Attacks .................7
3. Comments on Existing DNS Security ...............................7
3.1. Existing DNS Data Security .................................7
3.2. DNS Message/Transaction Security ...........................8
3.3. Conclusions on Existing DNS Security .......................8
4. DNS COOKIE Option ...............................................8
4.1. Client Cookie .............................................10
4.2. Server Cookie .............................................10
5. DNS Cookies Protocol Specification .............................11
5.1. Originating a Request .....................................11
5.2. Responding to a Request ...................................11
5.2.1. No OPT RR or No COOKIE Option ......................12
5.2.2. Malformed COOKIE Option ............................12
5.2.3. Only a Client Cookie ...............................12
5.2.4. A Client Cookie and an Invalid Server Cookie .......13
5.2.5. A Client Cookie and a Valid Server Cookie ..........13
5.3. Processing Responses ......................................14
5.4. Querying for a Server Cookie ..............................14
6. NAT Considerations and Anycast Server Considerations ...........15
7. Operational and Deployment Considerations ......................17
7.1. Client and Server Secret Rollover .........................17
7.2. Counters ..................................................18
8. IANA Considerations ............................................18
9. Security Considerations ........................................19
9.1. Cookie Algorithm Considerations ...........................20
10. Implementation Considerations .................................20
11. References ....................................................20
11.1. Normative References .....................................20
11.2. Informative References ...................................21
Appendix A. Example Client Cookie Algorithms ......................23
A.1. A Simple Algorithm ........................................23
A.2. A More Complex Algorithm ..................................23
Appendix B. Example Server Cookie Algorithms ......................23
B.1. A Simple Algorithm ........................................23
B.2. A More Complex Algorithm ..................................24
Acknowledgments ...................................................25
Authors' Addresses ................................................25
1. Introduction โจ
so, like a lot of core Internet protocols, DNS was built back when the Internet was a tiny club of trusted users ๐ซฃ Then the Internet blew up into a global information utility, and DNS started getting abused a lot ๐
This doc describes DNS Cookies, a lightweight DNS transaction security mechanism that's specified as an OPT [RFC6891] option ๐ They give DNS servers and clients limited protection against a bunch of common abuses by off-path attackers. They're compatible with other DNS transaction forgery resistance measures, like the ones in [RFC5452], and you can use them together with those ๐ซถ (Same iykyk thing again: cookies only go back to the IP address they came from, so no general tracking.)
Okay, the vibe here is basically the same as using TCP for DNS transactions ๐ฆ To get past TCP's weak protection, an off-path attacker has to, among other things, guess the 32-bit TCP sequence number in use. To get past DNS Cookies' weak protection, that attacker has to guess a 64-bit pseudorandom "cookie" value instead. So if DNS Cookies aren't available but TCP is, falling back to TCP is a reasonable move ๐
Here's the deal with compatibility. If only one party in a DNS transaction supports DNS Cookies, nothing much happens: no benefit, but no real interference either. If both support them, the extra security kicks in automatically ๐ธ
DNS Cookies were designed to work even when NAT and NAT-PT (Network Address Translation - Protocol Translation) boxes are in the way, and this doc also gives guidance on supporting DNS Cookies in anycast servers ๐
1.1. Contents of This Document
Section 2 covers the threats that DNS Cookies give some protection against ๐
Section 3 looks at existing DNS security mechanisms and explains why they aren't adequate substitutes for DNS Cookies ๐ง
Section 4 describes the COOKIE option ๐
Section 5 gives the protocol description ๐
Section 6 talks about NAT considerations and anycast-related DNS Cookies design considerations ๐ง
Section 7 covers incremental deployment considerations ๐ฆ
Sections 8 and 9 are IANA considerations and security considerations, respectively ๐
1.2. Definitions
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119] ๐
Here are the terms we're using, bestie ๐
"Off-path attacker": for a particular DNS client and server, this is an attacker who cannot observe the DNS request and response messages between that client and server ๐
"Soft state": this is info that a host learns or derives, which it may throw away when its own policies say so, but which can be rebuilt later if it's needed. For example, it could get dropped after a while, or when the storage for caching this stuff gets full. If operations that need soft state keep going after the info is gone, the info is automatically regenerated, though it costs something to do that ๐
"Silently discarded": this just means there are no DNS protocol message consequences ๐คซ
"IP address": used here as a length-independent term that covers both IPv4 and IPv6 addresses ๐
2. Threats Considered ๐
DNS Cookies are meant to give significant but limited protection against certain attacks by off-path attackers, which we'll go through below. These attacks include denial of service, cache poisoning, and answer forgery ๐ซถ
2.1. Denial-of-Service Attacks
The typical denial-of-service attack in this doc is sending DNS requests with forged source IP addresses to a server ๐ The goal might be to take down that server, or some other host they picked, as described below.
There are also on-path denial-of-service attacks that try to flood a server with DNS requests that have correct source addresses. Cookies don't protect against those, BUT successful cookie validation makes it more likely that the correct source IP address for the requests is known ๐ That helps when you want to contact the managers of the networks the requests came from, or take other actions for those networks.
2.1.1. DNS Amplification Attacks
So a request with a forged source IP address usually gets its response sent to that forged IP address. That means if someone forges a ton of requests with the same source IP address, enough traffic can pile up at that address to mess with service for whatever host lives there ๐ญ Making it worse, it's generally easy in DNS to craft short requests that get much longer responses, which amplifies the attack ๐
The DNS Cookie mechanism can seriously limit the traffic amplification an attacker gets from requests when they're off the path between the server and the request's source address โจ With enforced DNS Cookies, it's hard for an off-path attacker to make the server send anything beyond rate-limited short error responses to a forged IP address. So the attack gets attenuated instead of amplified ๐ก๏ธ DNS Cookies also make it more effective to rate-limit error responses from the server, and that scheme would further restrict selected host denial-of-service traffic from that server ๐ฅ
2.1.2. DNS Server Denial of Service โจ
okay bestie, every DNS request that gets accepted makes DNS servers do actual WORK ๐ญ and recursive servers feel it the most. They may have to send out one or more requests of their own and then process all the replies, just to figure out what to answer. It can get even worse for recursive servers doing DNSSEC [RFC4033] [RFC4034] [RFC4035], because they might get tricked into doing heavy cryptographic math while trying to check that the data they fetched is legit ๐
The computational or communications burden from these requests may not depend on a forged source IP address, but using forged addresses makes things messier ๐
- the source of the requests causing the denial-of-service attack harder to find, and
- restricting which IP addresses should be honored for such requests hard or impossible to specify or verify.
DNS Cookies should let a server bounce forged requests from an off-path attacker with relative ease, and before any recursive queries or public key cryptographic operations happen. That's the whole glow-up ๐ซถ
2.2. Cache Poisoning and Answer Forgery Attacks
so the cache poisoning attacks we're looking at are all about sending forged replies to a resolver ๐ With modern network speeds on well-connected hosts, if you forge replies that look like they come from a DNS server's IP address, for names the resolver was induced to resolve, or for common names with short time-to-live values, the odds of randomly landing a reply that gets accepted become unacceptably high. Then the resolver caches totally false DNS information (this is the Dan Kaminsky attack [Kaminsky]). That can be used to facilitate phishing attacks and other diversions of legitimate traffic to a compromised or malicious host, like a web server. ๐ญ
With the use of DNS Cookies, a resolver can generally reject such forged replies ๐
3. Comments on Existing DNS Security
Two forms of security have been added to DNS: data security and message/transaction security. Let's break it down ๐
3.1. Existing DNS Data Security
DNS data security is one part of DNSSEC. It's described in [RFC4033], [RFC4034], [RFC4035], and updates thereto. It gives you data origin authentication and authenticated denial of existence. DNSSEC is being deployed and can provide strong protection against forged data and cache poisoning. Lowkey though, it has an unintended side effect of making some denial-of-service attacks worse, because of the cryptographic computational load it can require and the increased size of DNS response packets it tends to produce ๐ฉ
3.2. DNS Message/Transaction Security
The second form of security added to DNS provides "transaction" security through TSIG [RFC2845] or SIG(0) [RFC2931]. TSIG could provide strong protection against the attacks that the DNS Cookie mechanism protects against more weakly. However, TSIG is non-trivial to deploy across the general Internet because of the burdens it imposes. Those burdens include pre-agreement and key distribution between client and server, keeping track of server-side key state, and required time synchronization between client and server ๐ฅฒ
TKEY [RFC2930] can solve the problem of key distribution for TSIG. But some modes of TKEY impose a substantial cryptographic computation load and can be dependent on the deployment of DNS data security (see Section 3.1).
SIG(0) [RFC2931] provides less denial-of-service protection than TSIG or, in one way, even DNS Cookies, because it authenticates complete transactions but does not authenticate requests. In any case, it also depends on the deployment of DNS data security and requires computationally burdensome public key cryptographic operations ๐
3.3. Conclusions on Existing DNS Security
The existing DNS security mechanisms do not provide the services that the DNS Cookie mechanism provides: lightweight message authentication of DNS requests and responses, with no requirement for pre-configuration or per-client server-side state. That's the gap cookies fill ๐ฆ
4. DNS COOKIE Option โจ
The DNS COOKIE option is an OPT RR [RFC6891] option that can be included in the RDATA portion of an OPT RR in DNS requests and responses. Its length varies depending on the circumstances it's being used in. There are two cases, described below. Both use the same OPTION-CODE, and they're told apart by their length ๐ง
When a client sends a request to a server and does not know the server's cookie, the length is 8. That's just an 8-byte Client Cookie, as shown in Figure 1 ๐
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| OPTION-CODE = 10 | OPTION-LENGTH = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+-+- Client Cookie (fixed size, 8 bytes) -+-+-+-+
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 1: COOKIE Option, Unknown Server Cookie
When a client sends a request and a Server Cookie is known, and in all responses to such a request, the length is variable: anywhere from 16 to 40 bytes. That's an 8-byte Client Cookie followed by a variable-length (8 bytes to 32 bytes) Server Cookie, as shown in Figure 2 ๐ธ The length keeps changing because the Server Cookie's size does. The Server Cookie is an integer number of bytes, with a minimum size of 8 bytes for security and a maximum size of 32 bytes for convenience of implementation ๐
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| OPTION-CODE = 10 | OPTION-LENGTH >= 16, <= 40 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+-+- Client Cookie (fixed size, 8 bytes) -+-+-+-+
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ Server Cookie (variable size, 8 to 32 bytes) /
/ /
+-+-+-+-...
Figure 2: COOKIE Option, Known Server Cookie
4.1. Client Cookie
The Client Cookie SHOULD be a pseudorandom function of the Client IP Address, the Server IP Address, and a secret quantity known only to the client. This Client Secret SHOULD have at least 64 bits of entropy [RFC4086] and be changed periodically (see Section 7.1). Which pseudorandom function you pick is a matter private to the client, since only the client needs to recognize its own DNS Cookies ๐
The Client IP Address is included so that the Client Cookie cannot be used to (1) track a client if the Client IP Address changes due to privacy mechanisms, or (2) impersonate the client by some network device that was formerly on path but is no longer on path when the Client IP Address changes due to mobility. However, if the Client IP Address is changing very often, it may be necessary to fix the Client Cookie for a particular server for several requests, to avoid undue inefficiency from retries caused by that server not recognizing the Client Cookie ๐ฆ
For further discussion of the Client Cookie field, see Section 5.1. For example methods of determining a Client Cookie, see Appendix A.
In order to provide minimal authentication, a client MUST send Client Cookies that will usually be different for any two servers at different IP addresses. ๐
4.2. Server Cookie
The Server Cookie SHOULD consist of or include a 64-bit or larger pseudorandom function of the request source (client) IP address, a secret quantity known only to the server, and the request Client Cookie. (See Section 6 for a discussion of why the Client Cookie is used as input to the Server Cookie but the Server Cookie is not used as an input to the Client Cookie.) This Server Secret SHOULD have at least 64 bits of entropy [RFC4086] and be changed periodically (see Section 7.1). The selection of the pseudorandom function is a matter private to the server, as only the server needs to recognize its own DNS Cookies ๐ง
For further discussion of the Server Cookie field, see Section 5.2. For example methods of determining a Server Cookie, see Appendix B. When implemented as recommended, the server need not maintain any cookie-related per-client state ๐
In order to provide minimal authentication, a server MUST send Server Cookies that will usually be different for clients at any two different IP addresses or with different Client Cookies. ๐
5. DNS Cookies Protocol Specification
This section discusses using DNS Cookies in the DNS protocol. The cycle of originating a request, responding to that request, and processing responses is covered in Sections 5.1, 5.2, and 5.3. A de facto extension to QUERY to allow the prefetching of a Server Cookie is specified in Section 5.4. Rollover of the Client Secrets and Server Secrets, and transient retention of the old cookie or secret, are covered in Section 7.1 โจ
DNS clients and servers SHOULD implement DNS Cookies to decrease their vulnerability to the threats discussed in Section 2. Main character energy for security ๐
5.1. Originating a Request
A DNS client that implements DNS Cookies includes one DNS COOKIE option containing a Client Cookie in every DNS request it sends, unless DNS Cookies are disabled ๐
If the client has a cached Server Cookie for the server against its IP address, it uses the longer cookie form and includes that Server Cookie in the option along with the Client Cookie (Figure 2). Otherwise, it just sends the shorter-form option with a Client Cookie (Figure 1) ๐ซถ
5.2. Responding to a Request โจ
okay so the Server Cookie ๐ช, when it shows up in a COOKIE option in a request, is basically there to weakly assure the server that the request came from a client that is both at the source IP address of the request and using the Client Cookie in that option ๐ซถ. The assurance comes from the Server Cookie the server handed that client in an earlier response, which is now coming back in the Server Cookie field of the request. it's giving full circle ๐ฆ
At a server where DNS Cookies are not implemented and enabled, the COOKIE option just gets ignored ๐ and the server responds as if there was no COOKIE option in the request at all. no drama, no cap.
When DNS Cookies are implemented and enabled, there are five possibilities:
- There is no OPT RR at all in the request, or there is an OPT RR but the COOKIE option is absent from the OPT RR.
- A COOKIE option is present but is not a legal length or is otherwise malformed.
- There is a COOKIE option of valid length in the request with no Server Cookie.
- There is a COOKIE option of valid length in the request with a Server Cookie, but that Server Cookie is invalid.
- There is a COOKIE option of valid length in the request with a correct Server Cookie.
These five possibilities get their own subsections below, so keep scrolling bestie ๐
In all cases of multiple COOKIE options in a request, only the first (the one closest to the DNS header) is considered. All others are ignored. one option to rule them all ๐
5.2.1. No OPT RR or No COOKIE Option
if there's no OPT record or no COOKIE option in the request, the server responds as if it doesn't implement the COOKIE option at all. very simple, very chill โจ
5.2.2. Malformed COOKIE Option
if the COOKIE option is too short to hold a Client Cookie, the server generates FORMERR ๐. if it's longer than what's needed for a COOKIE option with just a Client Cookie (8 bytes) but shorter than the minimum COOKIE option with both a Client Cookie and a Server Cookie (16 bytes), that's also FORMERR ๐ญ. and if it's longer than the maximum valid COOKIE option (40 bytes), yep, FORMERR again ๐
โโ๏ธ
so the vibe check is: valid cookie lengths are 8 and 16 to 40 inclusive ๐
5.2.3. Only a Client Cookie
the server gets to pick based on its own policy (rate limiting included ๐). it can choose one of these:
- Silently discard the request.
- Send a
BADCOOKIEerror response. - Process the request and provide a normal response. The RCODE is
NOERROR, unless some non-cookie error occurs in processing the request.
if the server goes with (2) or (3), it SHALL generate its own COOKIE option containing both the Client Cookie copied from the request and a Server Cookie it has generated ๐ช, and it will add that COOKIE option to the response's OPT record. Servers MUST, at least occasionally, respond to these requests so the client learns the correct Server Cookie. this is super important because it's how a client bootstraps up to the more secure state where requests and responses have recognized Server Cookies and Client Cookies ๐. a server doesn't need to keep per-client state to pull this off. for example, it could answer every Nth request across all clients ๐ง
if the request came in over TCP, the server SHOULD take the authentication TCP provides into account and SHOULD choose (3) ๐ . but if it's not willing to accept TCP's security as a substitute for DNS Cookies and goes with (2) instead, there's some danger of an indefinite loop of retries (see Section 5.3). yikes ๐ฌ
5.2.4. A Client Cookie and an Invalid Server Cookie
the server checks whether the Server Cookie is one it generated before ๐. usually that means recalculating the Server Cookie (or the Hash part of it) from the Server Secret (or the previous Server Secret, if it just changed), the received Client Cookie, the Client IP Address, and possibly other fields. see Appendix B.2 for an example ๐ธ. if the cookie turns out invalid, it could be because:
- it is too old
- a client's IP address or Client Cookie changed, and the DNS server is not aware of the change
- an anycast cluster of servers is not consistently configured, or
- an attempt to spoof the client has occurred ๐ต๏ธโโ๏ธ
The server SHALL process the request as if the invalid Server Cookie was not present, as described in Section 5.2.3. no cookie, no problem, we just follow 5.2.3 like it never happened ๐
5.2.5. A Client Cookie and a Valid Server Cookie
when a valid Server Cookie is in the request, the server can assume the request is from a client it has talked to before ๐ฅฐ. any defensive measures against spoofed UDP requests (if it has any) are no longer required. iconic behavior honestly ๐
The server SHALL process the request and include a COOKIE option in the response by (a) copying the complete COOKIE option from the request or (b) generating a new COOKIE option containing both the Client Cookie copied from the request and a valid Server Cookie it has generated. so it can either copy the whole thing back or make a fresh one, your call ๐
5.3. Processing Responses
okay the Client Cookie, when it shows up in a COOKIE option in a DNS reply, is there to weakly assure the client that the reply came from a server at the source IP address used in the response packet ๐ฆ. that's because the Client Cookie value is exactly what that client would send to that server in a request. in a DNS reply with multiple COOKIE options, all but the first (the one closest to the DNS header) get ignored ๐
A DNS client where DNS Cookies are implemented and enabled checks the response for DNS Cookies and MUST discard the response if it contains an illegal COOKIE option length or an incorrect Client Cookie value ๐ซ. if the client expects a COOKIE option in the response and it's missing, the response MUST be discarded too ๐. but if the COOKIE option's Client Cookie is correct, the client caches the Server Cookie it got, even if the response is an error response (RCODE non-zero) ๐ง (that's the cache it anyway, babe energy).
if the extended RCODE in the reply is BADCOOKIE and the Client Cookie in the reply matches what was sent, it means the server refused to process the request because the Server Cookie in it wasn't correct ๐
โโ๏ธ. the client SHOULD retry the request using the new Server Cookie from the response ๐. repeated BADCOOKIE responses to requests using the Server Cookie from the previous response might mean the shared secrets, or the way secrets get generated in an anycast cluster of servers, are inconsistent ๐ค. and if the reply to a retried request with a fresh Server Cookie is still BADCOOKIE, the client SHOULD retry using TCP as the transport ๐, since the server will likely process the request normally based on the security TCP provides (see Section 5.2.3). TCP to the rescue!! ๐
if the RCODE is some value other than BADCOOKIE, including zero, further processing of the response just proceeds normally โจ
5.4. Querying for a Server Cookie
in lots of cases, a client picks up the Server Cookie for a server as a "side effect" of some other transaction ๐. but sometimes that's not what you want, so there's a way to get a Server Cookie on purpose: an extension to the QUERY opcode ๐ฎ. most existing implementations require QDCOUNT to be one (1) for that opcode (see Section 4.1.2 of [RFC1035]), so this is a bit of a special case.
For servers with DNS Cookies enabled, the QUERY opcode behavior is extended to support queries with an empty Question Section (a QDCOUNT of zero (0)), provided that an OPT record is present with a COOKIE option ๐ซง. these servers send back a reply with an empty Answer Section and a COOKIE option containing the Client Cookie and a valid Server Cookie ๐.
If such a query provided just a Client Cookie and no Server Cookie, the response SHALL have the RCODE NOERROR ๐ฅณ.
This mechanism can also confirm or re-establish an existing Server Cookie by sending a cached Server Cookie along with the Client Cookie ๐. in that case, the response SHALL have the RCODE BADCOOKIE if the Server Cookie sent with the query was invalid, and the RCODE NOERROR if it was valid ๐
.
Servers that don't support the COOKIE option will normally send FORMERR in response to such a query ๐, though REFUSED, NOTIMP, and NOERROR without a COOKIE option are also possible in such responses. the server's vibe is just "idk what that is" and it's valid to say so ๐
6. NAT Considerations and Anycast Server Considerations โจ
okay so bestie, let's talk about the messy real world ๐ because the classic Internet was honestly so clean. DNS Cookies could just be a pseudorandom function of the Client IP Address and a Server Secret, or the Server IP Address and a Client Secret. ๐ You'd compute the Server Cookie that way so a client could cache its Server Cookie for a particular server for an indefinite amount of time, and the server could easily regenerate and check it. โจ You could even think of the Client Cookie as a weak client signature over the Server IP Address that the client checks in replies, and you could extend that signature to cover the request ID, for example, or any other info that comes back unchanged in the reply. ๐
But then we have this reality called "NAT" [RFC3022] ๐ (and, for the purposes of this doc, NAT-PT, which has been declared Historic [RFC4966]). There's no problem with DNS transactions between clients and servers behind a NAT box that use local IP addresses. ๐ธ Also no problem with NAT translating internal addresses to external ones, or translating between IPv4 and IPv6, as long as the address mapping is relatively stable. If the external IP address an internal client is mapped to changes occasionally, the disruption is basically the same as when a client rolls over its COOKIE secret. ๐ฆ And external access to a DNS server behind a NAT box is normally handled by a fixed mapping that forwards externally received DNS requests to one specific host. ๐
BUT, NAT devices sometimes also map ports. ๐ญ That means multiple DNS requests and responses from multiple internal hosts can get mapped to a smaller number of external IP addresses, like just one. So there could be lots of clients behind a NAT box that all appear to come from the same source IP address to a server outside that box. ๐ If one of them were an attacker (think "zombie" or "botnet") ๐, that attacker could get the Server Cookie for some server for the outgoing IP address by just making a random request to that server. Then it could put that Server Cookie in the COOKIE option of requests to the server, using the forged local IP address of some other host or client behind the NAT box. ๐ (Having this Server Cookie won't help an attacker forge responses for cache poisoning, though, because those responses are protected by the required Client Cookie. ๐ก๏ธ)
To fix this potential defect, we have to tell apart different clients behind a NAT box from the server's point of view. ๐ฅ This is why the Server Cookie is specified as a pseudorandom function of both the request source IP address and the Client Cookie. ๐ Because the Client Cookie goes into the Server Cookie calculation, it follows that, for any particular server, a stable Client Cookie is needed. ๐ง If the request ID were included in the Client Cookie calculation, it would normally change with every request to a particular server. ๐ฉ That would mean every request has to be sent twice: first to learn the new Server Cookie based on the new Client Cookie (based on the new ID), and then again using that new Client Cookie to actually get an answer. So the input to the Client Cookie computation must be limited to the Server IP Address and one or more things that change slowly, such as the Client Secret. ๐
In principle, servers can have a similar problem, not because of NAT but because of mechanisms like anycast, which may cause requests to a DNS server at an IP address to be delivered to any one of several machines. ๐ (External requests to a DNS server behind a NAT box usually happen via port forwarding, so all of them go to one host.) However, this can't be solved the way the NATed client problem was solved. ๐ซ If the Server Cookie were included in the Client Cookie calculation the same way the Client Cookie is included in the Server Cookie, you'd just get an almost infinite series of errors as a request kept getting retried. ๐ตโ๐ซ
For servers accessed via anycast, to successfully support DNS Cookies, either (1) the server clones must all use the same Server Secret, or (2) the mechanism that distributes requests to the server clones must send requests from a particular client to a particular server for a long enough period that the extra requests caused by changing Server Cookies (from hitting different server machines) aren't unduly burdensome. ๐ฏ (When anycast-accessed servers act as recursive servers or otherwise act as clients, they normally use a different unique address as the source of their requests, so responses aren't delivered to the wrong place. ๐ฌ)
For simplicity, it is RECOMMENDED that the same Server Secret be used by each DNS server in a set of anycast servers. ๐ซถ If there's limited time skew in updating this secret across the anycast servers, a server can handle it by accepting requests containing a Server Cookie based on either its old or new secret for the maximum likely period of such skew (see also Section 7.1). โณ
7. Operational and Deployment Considerations ๐ ๏ธ
The DNS Cookie mechanism is designed for incremental deployment, and it complements the orthogonal techniques in [RFC5452]. ๐ท Either or both techniques can be deployed independently at each DNS server and client, so installing at the client and server ends doesn't need to be synchronized. ๐
In particular, a DNS server or client that implements the DNS Cookie mechanism can interoperate successfully with a DNS client or server that doesn't implement it. โจ Of course, in that case it won't get the benefit of the mechanism, and the server involved might choose to severely rate-limit responses. ๐ฌ When such a server or client interoperates with a client or server that also implements DNS Cookies, they both get the security benefits. ๐
7.1. Client and Server Secret Rollover ๐
The longer a secret is used, the higher the probability that it has been compromised. ๐ต๏ธโโ๏ธ So clients and servers are configured with a lifetime setting for their secret, and they roll over to a new secret when that lifetime expires, or earlier due to deliberate jitter (described below). The default lifetime is one day, and the maximum permitted is one month. ๐ To be precise, and to keep things practical despite long holiday weekends, daylight saving time shifts, and the like, clients and servers MUST NOT continue to use the same secret in new requests and responses for more than 36 days, and SHOULD NOT continue to do so for more than 26 hours. โฐ
Many clients rolling over their secret at the same time could briefly increase server traffic, and exactly predictable rollover times for clients or servers might make guessing attacks easier. ๐ค For example, an attacker might prioritise attacking the secrets they think will be in effect for a long time. ๐ฏ To avoid rollover synchronisation and predictability, it is RECOMMENDED that pseudorandom jitter in the range of plus zero to minus at least 40% be applied to the time until a scheduled rollover of a COOKIE secret. ๐ฒ
It is RECOMMENDED that a client keep the Client Cookie it is expecting in a reply until there is no longer an outstanding request associated with that Client Cookie that the client is tracking. ๐ฆ This avoids rejecting replies because of a bad Client Cookie right after a change in the Client Secret. ๐
It is RECOMMENDED that a server retain its previous secret after a rollover to a new secret for a configurable period of time, not less than 1 second or more than 300 seconds, with a default configuration of 150 seconds. ๐ฐ๏ธ Requests with Server Cookies based on its previous secret are treated as a correct Server Cookie during that time. ๐ซ When a server responds to a request containing an old Server Cookie that the server is treating as correct, the server MUST include a new Server Cookie in its response. ๐ฐ
7.2. Counters ๐
It is RECOMMENDED that implementations include counters of the occurrences of the various types of requests and responses described in Section 5. ๐งฎ
8. IANA Considerations ๐
IANA has assigned the following DNS EDNS0 option code: ๐ท๏ธ
Value Name Status Reference
-------- ------ -------- ---------------
10 COOKIE Standard RFC 7873
IANA has assigned the following DNS error code as an early allocation per [RFC7120]: ๐
RCODE Name Description Reference
-------- --------- ------------------------- ---------------
23 BADCOOKIE Bad/missing Server Cookie RFC 7873
9. Security Considerations ๐
โ ๏ธ Serious security moment, bestie! DNS Cookies provide only a weak form of authentication for DNS requests and responses. ๐ฑ
DNS Cookies provide a weak form of authentication of DNS requests and responses. ๐ In particular, they provide no protection against "on-path" adversaries. That means no protection against any adversary that can observe the plaintext DNS traffic, like an on-path router, bridge, or any device on an on-path shared link (unless the DNS traffic on that path is encrypted). ๐๏ธ
For example, if a host is connected via an unsecured IEEE Std. 802.11 link (Wi-Fi), any device nearby that could receive and decode the 802.11 transmissions must be considered "on path". ๐ก On the other hand, in a similar situation where 802.11 Robust Security (WPA2, also called "Wi-Fi Protected Access 2") is properly deployed on the Wi-Fi network nodes, only the Access Point the host is connecting through is "on path" as far as the 802.11 link is concerned. ๐
Despite these limitations, deployment of DNS Cookies on the global Internet is expected to provide a significant reduction in the available launch points for the traffic amplification and denial-of-service forgery attacks described in Section 2 above. ๐๐ฅ
Work is underway in the IETF DPRIVE working group to provide confidentiality for DNS requests and responses that would be compatible with DNS Cookies. ๐ง
Should stronger message or transaction security be desired, it is suggested that TSIG or SIG(0) security be used (see Section 3.2). However, it may be useful to use DNS Cookies in conjunction with these features. ๐ค In particular, DNS Cookies could screen out many DNS messages before the cryptographic computations of TSIG or SIG(0) are required. And if SIG(0) is in use, DNS Cookies could usefully screen out many requests, given that SIG(0) does not screen requests but only authenticates the response of complete transactions. ๐ง
An attacker that does not know the Server Cookie could do a variety of things, such as omitting the COOKIE option or sending a random Server Cookie. ๐คทโโ๏ธ In general, DNS servers need to take other measures, including rate-limiting responses, to protect against abuse in such cases. ๐ง See further information in Section 5.2. ๐
When a server or client starts receiving an increased level of requests with bad Server Cookies, or replies with bad Client Cookies, it would be reasonable for it to believe that it is likely under attack, and it should consider a more frequent rollover of its secret. ๐จ More rapid rollover decreases the benefit to a cookie-guessing attacker if they succeed in guessing a cookie. ๐โโ๏ธ๐จ
9.1. Cookie Algorithm Considerations ๐
okay so the cookie algorithm for DNS Cookies SHOULD be based on a pseudorandom function at least as strong as 64-bit FNV (Fowler/Noll/Vo [FNV]). bestie, if the algorithm is excessively weak or trivial, adversaries could literally guess cookies ๐
BUT, and this is the lowkey important part, DNS Cookies are a lightweight plaintext token, so a strong cryptographic hash may not be warranted in many cases ๐ง it would just add a heavier computational burden for no real reason. still, there is nothing wrong with going stronger! โจ For example, HMAC-SHA-256 [RFC6234] truncated to 64 bits is a totally valid choice, as long as the DNS processor has enough computational resources available ๐ช
DNS implementations or applications that want somewhat stronger security without a big jump in computational load should consider changing their client and/or Server Secret more often ๐ the catch is that this means generating a cryptographically strong random number more frequently [RFC4086]. see Appendices A and B for specific examples of cookie computation algorithms ๐
10. Implementation Considerations ๐ ๏ธ
the DNS COOKIE option specified herein is implemented in BIND 9.10 using an experimental option code ๐งช BIND 9.10.3 (and later) use the allocated option code ๐ the glow-up is real ๐ธ
11. References ๐
11.1. Normative References ๐
[RFC1035]Mockapetris, P., "Domain names - implementation and specification", STD 13, RFC 1035, DOI 10.17487/RFC1035, November 1987,http://www.rfc-editor.org/info/rfc1035.[RFC2119]Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997,http://www.rfc-editor.org/info/rfc2119.[RFC4086]Eastlake 3rd, D., Schiller, J., and S. Crocker, "Randomness Requirements for Security", BCP 106, RFC 4086, DOI 10.17487/RFC4086, June 2005,http://www.rfc-editor.org/info/rfc4086.[RFC6891]Damas, J., Graff, M., and P. Vixie, "Extension Mechanisms for DNS (EDNS(0))", STD 75, RFC 6891, DOI 10.17487/RFC6891, April 2013,http://www.rfc-editor.org/info/rfc6891.[RFC7120]Cotton, M., "Early IANA Allocation of Standards Track Code Points", BCP 100, RFC 7120, DOI 10.17487/RFC7120, January 2014,http://www.rfc-editor.org/info/rfc7120.
11.2. Informative References ๐ฆ
[FNV]Fowler, G., Noll, L., Vo, K., and D. Eastlake 3rd, "The FNV Non-Cryptographic Hash Algorithm", Work in Progress, draft-eastlake-fnv-10, October 2015.[Kaminsky]Olney, M., Mullen, P., and K. Miklavcic, "Dan Kaminsky's 2008 DNS Vulnerability", July 2008,https://www.ietf.org/mail-archive/web/dnsop/current/pdf2jgx6rzxN4.pdf.[RFC2845]Vixie, P., Gudmundsson, O., Eastlake 3rd, D., and B. Wellington, "Secret Key Transaction Authentication for DNS (TSIG)", RFC 2845, DOI 10.17487/RFC2845, May 2000,http://www.rfc-editor.org/info/rfc2845.[RFC2930]Eastlake 3rd, D., "Secret Key Establishment for DNS (TKEY RR)", RFC 2930, DOI 10.17487/RFC2930, September 2000,http://www.rfc-editor.org/info/rfc2930.[RFC2931]Eastlake 3rd, D., "DNS Request and Transaction Signatures ( SIG(0)s )", RFC 2931, DOI 10.17487/RFC2931, September 2000,http://www.rfc-editor.org/info/rfc2931.[RFC3022]Srisuresh, P. and K. Egevang, "Traditional IP Network Address Translator (Traditional NAT)", RFC 3022, DOI 10.17487/RFC3022, January 2001,http://www.rfc-editor.org/info/rfc3022.[RFC4033]Arends, R., Austein, R., Larson, M., Massey, D., and S. Rose, "DNS Security Introduction and Requirements", RFC 4033, DOI 10.17487/RFC4033, March 2005,http://www.rfc-editor.org/info/rfc4033.[RFC4034]Arends, R., Austein, R., Larson, M., Massey, D., and S. Rose, "Resource Records for the DNS Security Extensions", RFC 4034, DOI 10.17487/RFC4034, March 2005,http://www.rfc-editor.org/info/rfc4034.[RFC4035]Arends, R., Austein, R., Larson, M., Massey, D., and S. Rose, "Protocol Modifications for the DNS Security Extensions", RFC 4035, DOI 10.17487/RFC4035, March 2005,http://www.rfc-editor.org/info/rfc4035.[RFC4966]Aoun, C. and E. Davies, "Reasons to Move the Network Address Translator - Protocol Translator (NAT-PT) to Historic Status", RFC 4966, DOI 10.17487/RFC4966, July 2007,http://www.rfc-editor.org/info/rfc4966.[RFC5452]Hubert, A. and R. van Mook, "Measures for Making DNS More Resilient against Forged Answers", RFC 5452, DOI 10.17487/RFC5452, January 2009,http://www.rfc-editor.org/info/rfc5452.[RFC6234]Eastlake 3rd, D. and T. Hansen, "US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)", RFC 6234, DOI 10.17487/RFC6234, May 2011,http://www.rfc-editor.org/info/rfc6234.
Appendix A. Example Client Cookie Algorithms ๐ง
A.1. A Simple Algorithm ๐
a simple example for computing Client Cookies is the FNV64 [FNV] of the Client IP Address, the Server IP Address, and the Client Secret โจ
Client Cookie =
FNV64( Client IP Address | Server IP Address | Client Secret )
where "|" indicates concatenation. some computational resources can be saved by pre-computing FNV64 through the Client IP Address. (if the order of the items concatenated above is changed to put the Server IP Address last, it might be possible to further reduce the computational effort by pre-computing FNV64 through the bytes of both the Client IP Address and the Client Secret, but this would reduce the strength of the Client Cookie and is NOT RECOMMENDED. ๐ not it.)
A.2. A More Complex Algorithm ๐
a more complex algorithm for calculating Client Cookies is shown below. it uses more computational resources than the simpler algorithm in Appendix A.1 ๐
Client Cookie =
HMAC-SHA256-64( Client IP Address | Server IP Address,
Client Secret )
Appendix B. Example Server Cookie Algorithms ๐
B.1. A Simple Algorithm ๐ง
an example of a simple method that produces a 64-bit Server Cookie is the FNV64 [FNV] of the request IP address, the Client Cookie, and the Server Secret โจ
Server Cookie =
FNV64( Client IP Address | Client Cookie | Server Secret )
where "|" represents concatenation. (if the order of the items concatenated was changed, it might be possible to reduce the computational effort by pre-computing FNV64 through the bytes of the Server Secret and Client Cookie, but this would reduce the strength of the Server Cookie and is NOT RECOMMENDED. ๐)
B.2. A More Complex Algorithm ๐ฅ
since the Server Cookie has a variable size, the server can store various information in that field, as long as it is hard for an adversary to guess the entire quantity used for authentication ๐ซถ there should be 64 bits of entropy in the Server Cookie. for example, it could have a sub-field of 64 bits computed pseudorandomly, with the Server Secret as one of the inputs to the pseudorandom function. Types of additional information that could be stored include a timestamp and/or a nonce โฐ
the example below is one variation of the Server Cookie that has been implemented in BIND 9.10.3 (and later) releases, where the Server Cookie is 128 bits, composed as follows:
Sub-field Size
--------- ---------
Nonce 32 bits
Time 32 bits
Hash 64 bits
with this algorithm, the server sends a new 128-bit cookie back with every request. The Nonce field keeps the chance of a duplicate super low ๐
The Time field gives the server time and makes it easy to reject old cookies โณ
The Hash part of the Server Cookie is the part that is hard to guess ๐ In BIND 9.10.3 (and later), its computation can be configured to use AES, HMAC-SHA-1, or, as shown below, HMAC-SHA-256:
hash =
HMAC-SHA256-64( Server Secret,
(Client Cookie | Nonce | Time | Client IP Address) )
where "|" represents concatenation.
Acknowledgments ๐ซถ
the suggestions and contributions of the following are gratefully acknowledged:
Alissa Cooper, Bob Harold, Paul Hoffman, David Malone, Yoav Nir,
Gayle Noble, Dan Romascanu, Tim Wicinski, and Peter Yee
Authors' Addresses ๐
Donald E. Eastlake 3rd
Huawei Technologies
155 Beaver Street
Milford, MA 01757
United States
Phone: +1-508-333-2270
Email: d3e3e3@gmail.com
Mark Andrews
Internet Systems Consortium
950 Charter Street
Redwood City, CA 94063
United States
Email: marka@isc.org
๐ฆ where this page comes from
- ietf: rfc7873 2016-05
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms