idnits 2.17.1 draft-abarth-cookie-01.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** The document seems to lack a License Notice according IETF Trust Provisions of 28 Dec 2009, Section 6.b.ii or Provisions of 12 Sep 2009 Section 6.b -- however, there's a paragraph with a matching beginning. Boilerplate error? (You're using the IETF Trust Provisions' Section 6.b License Notice from 12 Feb 2009 rather than one of the newer Notices. See https://trustee.ietf.org/license-info/.) Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- == No 'Intended status' indicated for this document; assuming Proposed Standard Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** There is 1 instance of too long lines in the document, the longest one being 2 characters in excess of 72. ** The document seems to lack a both a reference to RFC 2119 and the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. RFC 2119 keyword, line 212: '...ervening gateway MUST NOT fold multipl...' RFC 2119 keyword, line 238: '...the user agent and MAY be anything the...' RFC 2119 keyword, line 302: '... The user agent SHOULD protect the co...' RFC 2119 keyword, line 309: '... The user agent SHOULD protect confid...' RFC 2119 keyword, line 394: '...ure interoperability, user agents MUST...' (16 more instances...) Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document seems to contain a disclaimer for pre-RFC5378 work, but was first submitted on or after 10 November 2008. The disclaimer is usually necessary only for documents that revise or obsolete older RFCs, and that take significant amounts of text from those RFCs. If you can contact all authors of the source material and they are willing to grant the BCP78 rights to the IETF Trust, you can and should remove the disclaimer. Otherwise, the disclaimer is needed and you can ignore this comment. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (August 15, 2009) is 5367 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Missing reference section? 'RFC 2068' on line 182 looks like a reference -- Missing reference section? 'TODO' on line 277 looks like a reference Summary: 4 errors (**), 0 flaws (~~), 3 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 http-state Working Group A. Barth 3 Internet-Draft U.C. Berkeley 4 Expires: February 16, 2010 August 15, 2009 6 HTTP State Management Mechanism 7 draft-abarth-cookie-01 9 Status of this Memo 11 This Internet-Draft is submitted to IETF in full conformance with the 12 provisions of BCP 78 and BCP 79. This document may contain material 13 from IETF Documents or IETF Contributions published or made publicly 14 available before November 10, 2008. The person(s) controlling the 15 copyright in some of this material may not have granted the IETF 16 Trust the right to allow modifications of such material outside the 17 IETF Standards Process. Without obtaining an adequate license from 18 the person(s) controlling the copyright in such materials, this 19 document may not be modified outside the IETF Standards Process, and 20 derivative works of it may not be created outside the IETF Standards 21 Process, except to format it for publication as an RFC or to 22 translate it into languages other than English. 24 Internet-Drafts are working documents of the Internet Engineering 25 Task Force (IETF), its areas, and its working groups. Note that 26 other groups may also distribute working documents as Internet- 27 Drafts. 29 Internet-Drafts are draft documents valid for a maximum of six months 30 and may be updated, replaced, or obsoleted by other documents at any 31 time. It is inappropriate to use Internet-Drafts as reference 32 material or to cite them other than as "work in progress." 34 The list of current Internet-Drafts can be accessed at 35 http://www.ietf.org/ietf/1id-abstracts.txt. 37 The list of Internet-Draft Shadow Directories can be accessed at 38 http://www.ietf.org/shadow.html. 40 This Internet-Draft will expire on February 16, 2010. 42 Copyright Notice 44 Copyright (c) 2009 IETF Trust and the persons identified as the 45 document authors. All rights reserved. 47 This document is subject to BCP 78 and the IETF Trust's Legal 48 Provisions Relating to IETF Documents in effect on the date of 49 publication of this document (http://trustee.ietf.org/license-info). 50 Please review these documents carefully, as they describe your rights 51 and restrictions with respect to this document. 53 Abstract 55 This document defines the HTTP Cookie and Set-Cookie headers. 57 NOTE: 59 This document is currently a "straw-man" cookie proposal. Much of 60 the text herein is completely wrong. If you have suggestions for 61 improving the draft, please send email to http-state@ietf.org. 62 Suggestions with test cases are especially appreciated. 64 Table of Contents 66 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5 67 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 6 68 3. State and Sessions . . . . . . . . . . . . . . . . . . . . . . 7 69 4. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 70 4.1. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 8 71 5. Server Conformance . . . . . . . . . . . . . . . . . . . . . . 9 72 5.1. General . . . . . . . . . . . . . . . . . . . . . . . . . 9 73 5.2. Set-Cookie . . . . . . . . . . . . . . . . . . . . . . . . 9 74 5.2.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . 9 75 5.3. Semantics . . . . . . . . . . . . . . . . . . . . . . . . 10 76 5.3.1. Cookie Attributes . . . . . . . . . . . . . . . . . . 10 77 5.4. Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . 11 78 5.4.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . 11 79 5.4.2. Semantics . . . . . . . . . . . . . . . . . . . . . . 12 80 5.5. Controlling Caching . . . . . . . . . . . . . . . . . . . 12 81 6. User Agent Conformance . . . . . . . . . . . . . . . . . . . . 14 82 6.1. Parsing the Set-Cookie Header . . . . . . . . . . . . . . 14 83 6.2. Parsing Cookie Dates . . . . . . . . . . . . . . . . . . . 15 84 6.3. Storage Model . . . . . . . . . . . . . . . . . . . . . . 15 85 6.4. The Cookie Header . . . . . . . . . . . . . . . . . . . . 18 86 7. Caching Proxy Conformance . . . . . . . . . . . . . . . . . . 21 87 8. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 88 9. Implementation Considerations . . . . . . . . . . . . . . . . 23 89 9.1. Set-Cookie Content . . . . . . . . . . . . . . . . . . . . 23 90 9.2. Implementation Limits . . . . . . . . . . . . . . . . . . 23 91 9.2.1. Denial of Service Attacks . . . . . . . . . . . . . . 24 92 10. Privacy . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 93 10.1. User Agent Control . . . . . . . . . . . . . . . . . . . . 25 94 10.2. Protocol Design . . . . . . . . . . . . . . . . . . . . . 26 95 11. Security Considerations . . . . . . . . . . . . . . . . . . . 27 96 11.1. Clear Text . . . . . . . . . . . . . . . . . . . . . . . . 27 97 11.2. Cookie Spoofing . . . . . . . . . . . . . . . . . . . . . 27 98 11.3. Unexpected Cookie Sharing . . . . . . . . . . . . . . . . 27 99 12. Other, Similar, Proposals . . . . . . . . . . . . . . . . . . 28 100 Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 29 101 Appendix B. Tabled Items . . . . . . . . . . . . . . . . . . . . 30 102 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 31 104 1. Introduction 106 This document defines the HTTP Cookie and Set-Cookie header. 108 2. Terminology 110 The terms user agent, client, server, proxy, and origin server have 111 the same meaning as in the HTTP/1.0 specification. 113 Fully-qualified host name (FQHN) means either the fully-qualified 114 domain name (FQDN) of a host (i.e., a completely specified domain 115 name ending in a top-level domain such as .com or .uk), or the 116 numeric Internet Protocol (IP) address of a host. The fully 117 qualified domain name is preferred; use of numeric IP addresses is 118 strongly discouraged. [TODO: What does "strongly discouraged" mean?] 120 The terms request-host and request-URI refer to the values the client 121 would send to the server as, respectively, the host (but not port) 122 and abs_path portions of the absoluteURI (http_URL) of the HTTP 123 request line. Note that request-host must be a FQHN. Hosts names 124 can be specified either as an IP address or a FQHN string. Sometimes 125 we compare one host name with another. Host A's name domain-matches 126 host B's if 128 o both host names are IP addresses and their host name strings match 129 exactly; or 131 o both host names are FQDN strings and their host name strings match 132 exactly; or 134 o A is a FQDN string and has the form NB, where N is a non-empty 135 name string, B has the form .B, and B is a FQDN string. (So, 136 x.y.com domain-matches .y.com but not y.com.) 138 Note that domain-match is not a commutative operation: a.b.c.com 139 domain-matches .c.com, but not the reverse. 141 Because it was used in Netscape's original implementation of state 142 management, we will use the term cookie to refer to the state 143 information that passes between an origin server and user agent, and 144 that gets stored by the user agent. 146 3. State and Sessions 148 This document describes a way to create stateful sessions with HTTP 149 requests and responses. HTTP servers respond to each client request 150 without relating that request to previous or subsequent requests; the 151 technique allows clients and servers that wish to exchange state 152 information to place HTTP requests and responses within a larger 153 context, which we term a "session". This context might be used to 154 create, for example, a "shopping cart", in which user selections can 155 be aggregated before purchase, or a magazine browsing system, in 156 which a user's previous reading affects which offerings are 157 presented. 159 There are, of course, many different potential contexts and thus many 160 different potential types of session. The designers' paradigm for 161 sessions created by the exchange of cookies has these key attributes: 163 1. Each session has a beginning and an end. 165 2. Each session is relatively short-lived. 167 3. Either the user agent or the origin server may terminate a 168 session. 170 4. The session is implicit in the exchange of state information. 172 4. Overview 174 We outline here a way for an origin server to send state information 175 to the user agent, and for the user agent to return the state 176 information to the origin server. 178 The two state management headers, Set-Cookie and Cookie, have common 179 syntactic properties involving attribute-value pairs. The following 180 grammar uses the notation, and tokens DIGIT (decimal digits) and 181 token (informally, a sequence of non-special, non-white space 182 characters) from the HTTP/1.1 specification [RFC 2068] to describe 183 their syntax. 185 4.1. Examples 186 5. Server Conformance 188 5.1. General 190 The origin server initiates a session, if it so desires. (Note that 191 "session" here does not refer to a persistent network connection but 192 to a logical session created from HTTP requests and responses. The 193 presence or absence of a persistent connection should have no effect 194 on the use of cookie-derived sessions). To initiate a session, the 195 origin server returns an extra response header to the client, Set- 196 Cookie. (The details follow later.) 198 A user agent returns a Cookie request header (see below) to the 199 origin server if it chooses to continue a session. The origin server 200 may ignore it or use it to determine the current state of the 201 session. It may send the client a Set-Cookie response header with 202 the same or different information, or it may send no Set-Cookie 203 header at all. The origin server effectively ends a session by 204 sending the client a Set-Cookie header with Max-Age=0. [TODO: Need 205 to say something about Expires here.] 207 Servers may return a Set-Cookie response headers with any response. 208 User agents should send Cookie request headers, subject to other 209 rules detailed below, with every request. 211 An origin server may include multiple Set-Cookie headers in a 212 response. Note that an intervening gateway MUST NOT fold multiple 213 Set-Cookie headers into a single header. [TODO: Investigate how UAs 214 cope with folded headers.] 216 5.2. Set-Cookie 218 5.2.1. Syntax 220 Informally, the Set-Cookie response header comprises the token Set- 221 Cookie:, followed by a comma-separated list of one or more cookies. 222 Each cookie begins with a name-value-pair, followed by zero or more 223 semi-colon-separated attribute-value pairs. The NAME=VALUE 224 attribute-value pair must come first in each cookie. 226 set-cookie-header = "Set-Cookie:" name-value-pairs 227 name-value-pairs = name-value-pair *(";" name-value-pair) 228 name-value-pair = name ["=" value] ; optional value 229 name = token 230 value = token 232 [TODO: Investigate what token actually means.] 234 Attributes names are case-insensitive. White space is permitted 235 between tokens. Note that although the above syntax description 236 shows value as optional, some attributes require values. 238 The cookie-value is opaque to the user agent and MAY be anything the 239 origin server chooses to send, possibly in a server-selected 240 printable ASCII encoding. "Opaque" implies that the content is of 241 interest and relevance only to the origin server. The content may, 242 in fact, be readable by anyone who examines the Set-Cookie header. 244 NOTE: The syntax above allows whitespace between the attribute and 245 the = sign. Servers wishing to interoperate with some legacy user 246 agents might wish to elide this extra white space to maximize 247 compatibility. 249 5.3. Semantics 251 When the user agent receives a Set-Cookie header, the user agent 252 stores the cookie in its cookie store. When the user agent makes 253 another HTTP request to the origin server, the user agent will return 254 the cookie in the Cookie header. 256 The server can override the default handling of cookies by specifying 257 a number of cookie attributes. User agents ignore unrecognized 258 cookie attributes. 260 5.3.1. Cookie Attributes 262 This section describes the semantics of a number of cookie 263 attributes. 265 5.3.1.1. Max-Age 267 Syntax A sequence of ASCII numerals. 269 Semantics The value of the Max-Age attribute represents the maximum 270 lifetime of the cookie, measured in seconds from the moment the 271 user agent receives the cookie. If the server does not supply an 272 Expires or a Max-Age attribute, the lifetime of the cookie is 273 limited to the current session (as defined by the user agent). 275 5.3.1.2. Expires 276 Syntax An RFC 1123 date [cite]. (User agents use a very forgiving 277 date parers; see Section [TODO]). 279 Semantics The value of the Expires attribute represents the maximum 280 lifetime of the cookie, represented as the point in time at which 281 the cookie expires. If the server does not supply an Expires or a 282 Max-Age attribute, the lifetime of the cookie is limited to the 283 current session (as defined by the user agent). 285 5.3.1.3. Domain 287 [TODO: Test Domain.] The Domain attribute specifies the domain for 288 which the cookie is valid. The leading dot isn't required. If there 289 is no Domain attribute, the default is to return the cookie only to 290 the origin server. [TODO: You can only set cookies for related 291 domains.] 293 5.3.1.4. Path 295 [TODO: Test path.] The Path attribute specifies the subset of URLs 296 to which this cookie applies. 298 5.3.1.5. Secure 300 Syntax The empty string. 302 Semantics The user agent SHOULD protect the confidentiality of 303 cookies with the Secure attribute. 305 5.3.1.6. HttpOnly 307 Syntax The empty string. 309 Semantics The user agent SHOULD protect confidentiality of cookies 310 with the HttpOnly attribute by including HttpOnly cookies only 311 when generating cookie strings for use in HTTP requests. 313 5.4. Cookie 315 5.4.1. Syntax 317 The user agent returns stored cookies to the origin server in the 318 cookie header. The Cookie header shares a common syntax with the 319 Set-Cookie header, but the semantics of the header differ 320 dramatically. 322 cookie-header = "Cookie:" name-value-pairs 323 name-value-pairs = name-value-pair *(";" name-value-pair) 324 name-value-pair = name "=" value 325 name = token 326 value = token 328 NOTE: If the server supplies a Set-Cookie header that does not 329 conform to the grammar in Section TODO, the user agent might not 330 supply a Cookie header that conforms to the grammar in this Section. 332 5.4.2. Semantics 334 Each name-value-pair represents a cookie stored by the user agent. 335 The cookie name is returned in as the name and the cookie value is 336 returned as the value. 338 5.5. Controlling Caching 340 [TODO: Should we go into this much detail here? This seems redundant 341 with the HTTP specs.] 343 An origin server must be cognizant of the effect of possible caching 344 of both the returned resource and the Set-Cookie header. Caching 345 "public" documents is desirable. For example, if the origin server 346 wants to use a public document such as a "front door" page as a 347 sentinel to indicate the beginning of a session for which a Set- 348 Cookie response header must be generated, the page should be stored 349 in caches "pre-expired" so that the origin server will see further 350 requests. "Private documents", for example those that contain 351 information strictly private to a session, should not be cached in 352 shared caches. 354 If the cookie is intended for use by a single user, the Set-Cookie 355 header should not be cached. A Set-Cookie header that is intended to 356 be shared by multiple users may be cached. 358 The origin server should send the following additional HTTP/1.1 359 response headers, depending on circumstances: [TODO: Is this good 360 advice?] 362 o To suppress caching of the Set-Cookie header: Cache-control: no- 363 cache="set-cookie". 365 and one of the following: 367 o To suppress caching of a private document in shared caches: Cache- 368 Control: private. 370 o To allow caching of a document and require that it be validated 371 before returning it to the client: Cache-Control: must-revalidate. 373 o To allow caching of a document, but to require that proxy caches 374 (not user agent caches) validate it before returning it to the 375 client: Cache-Control: proxy-revalidate. 377 o To allow caching of a document and request that it be validated 378 before returning it to the client (by "pre-expiring" it): Cache- 379 Control: max-age=0. Not all caches will revalidate the document 380 in every case. 382 HTTP/1.1 servers must send Expires: old-date (where old-date is a 383 date long in the past) on responses containing Set-Cookie response 384 headers unless they know for certain (by out of band means) that 385 there are no downsteam HTTP/1.0 proxies. HTTP/1.1 servers may send 386 other Cache-Control directives that permit caching by HTTP/1.1 387 proxies in addition to the Expires: old-date directive; the Cache- 388 Control directive will override the Expires: old-date for HTTP/1.1 389 proxies. 391 6. User Agent Conformance 393 Not all origin servers conform to the behavior specified in the 394 previous section. To ensure interoperability, user agents MUST 395 process cookies in a manner that is "black-box" indistinguishable 396 from the requirements in this section. 398 6.1. Parsing the Set-Cookie Header 400 Let an LWS character be either a U+20 (SPACE) or a U+09 (TAB) 401 character. 403 A user agent MUST use the following algorithm to parse the Set-Cookie 404 header: 406 1. [TODO: Deal with ',' characters.] 408 2. If the header contains a ';' character: 410 the name-value string is characters up to, but not including, 411 the first ';', and the unparsed-cookie-attributes are the 412 remainder of the header (including the ';' in question). 414 Otherwise: 416 the name-value string is all the character contained in the 417 header, and the unparsed-cookie-attributes is the empty 418 string. 420 3. If the first non-LWS character of the name-value string is '=', 421 remove it. 423 4. If the name-value string contains a '=' character: 425 the name string is the characters up to, but not including, 426 the first '=' character, and the value string is the 427 characters after the first '=' character . 429 Otherwise: 431 the name string is empty, and the value string is the entire 432 name-value string. 434 5. Remove any leading or trailing space from the name string. 436 6. Remove any leading or trailing space from the value string. 438 7. The cookie-name is the name string. 440 8. The cookie-value is the value string. 442 The user agent MUST use the following algorithm to parse the 443 unparsed-attributes: 445 1. [TODO: Figure out how to parse cookie attributes.] 447 [TODO: Can parsing a cookie ever fail?] 449 [TODO: Convert Max-Age to a date during parsing.] 451 When the user agent finishes parsing the Set-Cookie header, the user 452 agent *receives a cookie* from the origin server with name cookie- 453 name, value cookie-value, and attributes cookie-attributes. 455 6.2. Parsing Cookie Dates 457 Basically, cookie dates are a mess for historical reasons. 459 To be compatible with legacy servers, however, user agents should 460 accept dates formated according to this grammar: 462 cookie-date = rfc1123-like-date / mystery-date 463 rfc1123-like-date = weekday "," SP rfc1123-like-dmy SP time SP "GMT" 464 weekday = "Monday" / "Mon" / "Tuesday" / "Tue" / ... 465 rfc1123-like-dmy = day dmy-div month dmy-div year 466 dmy-div = SP / "-" 467 day = 2DIGIT / *1SP DIGIT 468 month = "Jan" / "Feb" / ... 469 year = 2DIGIT / 4DIGIT 470 time = 2DIGIT ":" 2DIGIT ":" 2DIGIT 472 mystery-date = *CHAR ; see below 474 [TODO: More information about mystery-date.] 476 6.3. Storage Model 478 When the user agent receives a cookie, the user agent SHOULD record 479 the cookie in its cookie store as follows. 481 A user agent MAY ignore received cookies in their entirety if the 482 user agent is configured to block receiving cookie for a particular 483 response. For example, the user agent might wish to block receiving 484 cookies from "third-party" responses. 486 The user agent stores the following fields about each cookie: 488 o name (a sequence of bytes) 490 o value (a sequence of bytes) 492 o expiry (a date) 494 o domain (a cookie-domain) 496 o path (a cookie-path) 498 o creation (a date) 500 o last-access (a date) 502 o persistent (a Boolean) 504 o host-only (a Boolean) 506 o secure-only (a Boolean) 508 o http-only (a Boolean) 510 When the user agent receives a cookie, the user agent MUST follow the 511 following algorithm: 513 1. Create a new cookie based on the parsed Set-Cookie header: 515 1. Create a new cookie with the following default field values: 517 + name = the cookie-name 519 + value = the cookie-value 521 + expiry = the latest representable date 523 + domain = the request-host 525 + path = the path of the request URL that generated the Set- 526 Cookie response, up to, but not including, the right-most 527 / [TODO: Test! This seems wrong for paths that are just a 528 single slash] 530 + last-access = the date and time the cookie was received 531 + last-access = the date and time the cookie was received 533 + persistent = false 535 + host-only = true 537 + secure-only = false 539 + http-only = false 541 2. Update the default field values according to the cookie- 542 attributes: 544 expiry If the cookie-attributes contains at least one 545 Expires or a Max-Age attribute, store the value of the 546 [TODO: first] such attribute in the expiry field. Store 547 the value true in the persistent field. 549 domain If the cookie-attributes contains at least one Domain 550 attribute, store the value of the [TODO: first] such 551 attribute in the domain field. Store the value false in 552 the host-only field. [TODO: Reject cookies for unrelated 553 domains.] [TODO: If the URL's host is an IP address, let 554 Domain to be an IP address if it matches the URL's host 555 exactly, but set the host-only flag. ] 557 path If the cookie-attributes contains at least one Path 558 attribute, store the value of the [TODO: first] such 559 attribute in the path field. 561 secure-only If the cookie-attributes contains at least one 562 Secure attribute, store the value true in the secure-only 563 field. 565 http-only If the cookie-attributes contains at least one 566 HttpOnly attribute, store the value true in the http-only 567 field. 569 2. Remove from the cookie store all cookies that have the share the 570 same name, domain, path, and host-only fields as the newly 571 created cookie. [TODO: Valiate this list!] [TODO: There's some 572 funny business around http-only here.] 574 3. Insert the newly created cookie into the cookie store. 576 The user agent MUST evict a cookie from the cookie store if either of 577 the following conditions are met: 579 o A cookie exists in the cookie store with an expiry date in the 580 past. 582 o More than 50 cookies exist in the cookie store with the same 583 domain field. 585 The user agent MAY evict cookies from the cookie store if the cookie 586 store exceeds some maximum storage bound (such as 3000 cookies). 588 When the user agent evicts cookies from the cookie store, the user 589 agent MUST evict cookies in the following priority order: 591 1. A cookie with an expiry date in the past. 593 2. A cookie that shares a domain field with more than 50 other 594 cookies in the cookie store. 596 3. All other cookies. 598 If two cookies have the same removal priority, the user agent MUST 599 evict the cookie with the least recent last-access date first. 601 When the user agent exits, the user agent MUST remove from the cookie 602 store all cookies with the persistent field set to false. 604 6.4. The Cookie Header 606 When the user agent generates an HTTP request for a particular URI, 607 the user agent SHOULD attach exactly one HTTP named Cookie if the 608 cookie-string (defined below) for that URI is non-empty. 610 A user agent MAY elide the Cookie header in its entirety if the user 611 agent is configured to block sending cookie for a particular request. 612 For example, the user agent might wish to block sending cookies 613 during "third-party" requests. 615 When generating a cookie-string from a URI with a "secure" scheme, 616 the user agent MUST set the SECURE flag to true. Otherwise, the user 617 agent MUST set the SECURE flag to false. 619 NOTE: The notion of an "secure" scheme is not defined by this 620 document. Typically, user agents consider a scheme secure if the 621 scheme refers to a protocol that makes use of transport-layer 622 security, such as TLS. For example, most user agents consider 623 "https" to be a secure scheme. 625 When generating a cookie-string for use in an HTTP request, the user 626 agent MUST set the HTTP flag to true. Otherwise, the user agent MUST 627 set the HTTP flag to false. 629 The user agent MUST use the following algorithm to compute the 630 cookie-string from a cookie store and from a URI: 632 1. Let cookie-list be the set of cookies from the cookie store that 633 meet the following requirements: 635 * The cookie's domain field must domain-match the URI's host. 636 [TODO: Spec me] 638 * The cookie's path field must path-match the URI's path. 639 [TODO: Spec me] 641 * If the cookie's host-only flag is set, the cookie's domain 642 field must denote exactly the same FQDN as the URI's host. 643 [TODO: Internet Explorer does not implement this requirement 644 but most other major implementations do.] 646 * If the cookie's secure-only field is true, then the SECURE 647 flag must be true. 649 * If the cookie's http-only field is true, then the HTTP flag 650 must be true. 652 NOTE: The Cookie header will not contain any expired cookies 653 because cookies past their expiry date are removed from the 654 cookie store immediately. 656 2. Sort the cookie-list in the following order: 658 * Cookies with longer path fields are listed before cookies with 659 shorter path field. 661 * Among cookies that have equal length path fields, cookies with 662 earlier creation dates are listed before cookies with later 663 creation dates. 665 3. Update the last-access field of each cookie in the cookie-list to 666 the current date. 668 4. Serialize the cookie-list into a cookie-string by processing each 669 cookie in the cookie-list in order: 671 1. Output the cookie's name field. 673 2. Output the character U+3D ("=") 674 3. Output the cookie's value field. 676 4. If there is an unprocessed cookie in the cookie-list, output 677 the characters U+3B and U+20 ("; ") 679 7. Caching Proxy Conformance 681 One reason for separating state information from both a URL and 682 document content is to facilitate the scaling that caching permits. 683 To support cookies, a caching proxy must obey these rules already in 684 the HTTP specification [TODO: If they're already in the HTTP 685 specification, aren't they redundant here?]: 687 o Honor requests from the cache, if possible, based on cache 688 validity rules. 690 o Pass along a Cookie request header in any request that the proxy 691 must make of another server. 693 o Return the response to the client. Include any Set-Cookie 694 response header. 696 o Cache the received response subject to the control of the usual 697 headers, such as Expires, Cache-Control: no-cache, and Cache- 698 Control: private. 700 o Cache the Set-Cookie subject to the control of the usual header, 701 Cache-Control: no-cache="set-cookie". (The Set-Cookie header 702 should usually not be cached.) 704 Proxies must not introduce Set-Cookie (Cookie) headers of their own 705 in proxy responses (requests). 707 8. Examples 709 [TODO: Write sensible examples.] 711 9. Implementation Considerations 713 Here we speculate on likely or desirable details for an origin server 714 that implements state management. 716 9.1. Set-Cookie Content 718 An origin server's content should probably be divided into disjoint 719 application areas, some of which require the use of state 720 information. The application areas can be distinguished by their 721 request URLs. The Set-Cookie header can incorporate information 722 about the application areas by setting the Path attribute for each 723 one. 725 The session information can obviously be clear or encoded text that 726 describes state. However, if it grows too large, it can become 727 unwieldy. Therefore, an implementor might choose for the session 728 information to be a key to a server-side resource. [TODO: Describe 729 briefly how to generate a decent session key.] 731 [TODO: We could recommend that servers encrypt and mac their cookie 732 data.] 734 [TODO: Mention issues that arise from having multiple concurrent 735 sessions.] 737 9.2. Implementation Limits 739 Practical user agent implementations have limits on the number and 740 size of cookies that they can store. In general, user agents' cookie 741 support should have no fixed limits. [TODO: Why not?] They should 742 strive to store as many frequently-used cookies as possible. 743 Furthermore, general-use user agents should provide each of the 744 following minimum capabilities individually, although not necessarily 745 simultaneously: [TODO: Where do these numbers come from?] 747 o at least 4096 bytes per cookie (as measured by the size of the 748 characters that comprise the cookie non-terminal in the syntax 749 description of the Set-Cookie header) 751 User agents created for specific purposes or for limited-capacity 752 devices should provide at least 50 cookies of 4096 bytes, to ensure 753 that the user can interact with a session-based origin server. 755 The information in a Set-Cookie response header must be retained in 756 its entirety. If for some reason there is inadequate space to store 757 the cookie, it must be discarded, not truncated. 759 Applications should use as few and as small cookies as possible, and 760 they should cope gracefully with the loss of a cookie. [TODO: Could 761 mention latency issues that arise from having tons of cookies.] 763 9.2.1. Denial of Service Attacks 765 User agents may choose to set an upper bound on the number of cookies 766 to be stored from a given host or domain name or on the size of the 767 cookie information. Otherwise, a malicious server could attempt to 768 flood a user agent with many cookies, or large cookies, on successive 769 responses, which would force out cookies the user agent had received 770 from other servers. However, the minima specified above should still 771 be supported. [TODO: These minima still let an attacker exhaust the 772 entire cookie store. There's not much we can do about it though.] 774 10. Privacy 776 10.1. User Agent Control 778 An origin server could create a Set-Cookie header to track the path 779 of a user through the server. Users may object to this behavior as 780 an intrusive accumulation of information, even if their identity is 781 not evident. (Identity might become evident if a user subsequently 782 fills out a form that contains identifying information.) This state 783 management specification therefore requires that a user agent give 784 the user control over such a possible intrusion, although the 785 interface through which the user is given this control is left 786 unspecified. However, the control mechanisms provided shall at least 787 allow the user 789 o to completely disable the sending and saving of cookies, 791 o to determine whether a stateful session is in progress, and 793 o to control the saving of a cookie on the basis of the cookie's 794 Domain attribute. 796 Such control could be provided by, for example, mechanisms 798 o to notify the user when the user agent is about to send a cookie 799 to the origin server, offering the option not to begin a session, 801 o to display a visual indication that a stateful session is in 802 progress, 804 o to let the user decide which cookies, if any, should be saved when 805 the user concludes a window or user agent session, or 807 o to let the user examine the contents of a cookie at any time. 809 A user agent usually begins execution with no remembered state 810 information. It should be possible to configure a user agent never 811 to send Cookie headers, in which case it can never sustain state with 812 an origin server. (The user agent would then behave like one that is 813 unaware of how to handle Set-Cookie response headers.) 815 When the user agent terminates execution, it should let the user 816 discard all state information. Alternatively, the user agent may ask 817 the user whether state information should be retained. If the user 818 chooses to retain state information, it would be restored the next 819 time the user agent runs. 821 10.2. Protocol Design 823 The restrictions on the value of the Domain attribute are meant to 824 reduce the ways that cookies can "leak" to the "wrong" site. The 825 intent is to restrict cookies to one, or a closely related set of 826 hosts. Therefore a request-host is limited as to what values it can 827 set for Domain. 829 11. Security Considerations 831 11.1. Clear Text 833 The information in the Set-Cookie and Cookie headers is transmitted 834 in the clear. Three consequences are: 836 1. Any sensitive information that is conveyed in in the headers is 837 exposed to an easedropper. 839 2. A malicious intermediary could alter the headers as they travel 840 in either direction, with unpredictable results. 842 3. A malicious client could alter the Cookie header before 843 transmission, with unpredictable results. 845 These facts imply that information of a personal and/or financial 846 nature should be sent over a secure channel. For less sensitive 847 information, or when the content of the header is a database key, an 848 origin server should be vigilant to prevent a bad Cookie value from 849 causing failures. 851 11.2. Cookie Spoofing 853 [TODO: Mention integrity issue where a sibling domain can inject 854 cookies.] 856 [TODO: Mention integrity issue where a HTTP can inject cookies into 857 HTTPS.] 859 11.3. Unexpected Cookie Sharing 861 A user agent should make every attempt to prevent the sharing of 862 session information between hosts that are in different domains. 863 Embedded or inlined objects may cause particularly severe privacy 864 problems if they can be used to share cookies between disparate 865 hosts. For example, a malicious server could embed cookie 866 information for host a.com in a URI for host b.com. User agent 867 implementors are strongly encouraged to prevent this sort of exchange 868 whenever possible. [TODO: How are they supposed to do this? This 869 section makes little sense.] 871 12. Other, Similar, Proposals 873 [TODO: Describe relation to the Netscape Cookie Spec, RFC 2109, RFC 874 2629, and cookie-v2.] 876 Appendix A. Acknowledgements 878 This document borrows heavily from RFC 2109. [TODO: Figure out the 879 proper way to credit the authors of RFC 2109.] 881 Appendix B. Tabled Items 883 Tabled items: 885 o Public suffix. 887 Author's Address 889 Adam Barth 890 University of California, Berkeley 892 Email: abarth@eecs.berkeley.edu 893 URI: http://www.adambarth.com/