RFC 7873

Domain Name System (DNS) Cookies

๐Ÿ“… published May 2016, from ietf

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 (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 ๐Ÿฆ‹

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

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. ๐Ÿ’–

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:

  1. 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.
  2. A COOKIE option is present but is not a legal length or is otherwise malformed.
  3. There is a COOKIE option of valid length in the request with no Server Cookie.
  4. There is a COOKIE option of valid length in the request with a Server Cookie, but that Server Cookie is invalid.
  5. 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 ๐Ÿ‘‘

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 โœจ

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 ๐ŸŽ€

the server gets to pick based on its own policy (rate limiting included ๐Ÿ‘€). it can choose one of these:

  1. Silently discard the request.
  2. Send a BADCOOKIE error response.
  3. 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 ๐Ÿ˜ฌ

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 ๐ŸŒˆ

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 โœจ

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. ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ

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 ๐Ÿ’œ

11.2. Informative References ๐Ÿฆ‹


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 )

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