idnits 2.17.1 draft-abarth-cookie-06.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.) ** 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 163: '...ervening gateway MUST NOT fold multipl...' RFC 2119 keyword, line 208: '...tokens. Servers MUST NOT include two ...' RFC 2119 keyword, line 212: '...the user agent and MAY be anything the...' RFC 2119 keyword, line 280: '... Syntax Servers MUST NOT include a va...' RFC 2119 keyword, line 282: '... The user agent SHOULD protect the co...' (29 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 (December 11, 2009) is 5243 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: 'USASCII' is mentioned on line 112, but not defined == Missing Reference: 'TODO' is mentioned on line 480, but not defined == Unused Reference: 'RFC2616' is defined on line 979, but no explicit reference was found in the text ** Obsolete normative reference: RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) Summary: 4 errors (**), 0 flaws (~~), 6 warnings (==), 1 comment (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 http-state A. Barth 3 Internet-Draft U.C. Berkeley 4 Expires: June 14, 2010 December 11, 2009 6 HTTP State Management Mechanism 7 draft-abarth-cookie-06 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 June 14, 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: If you have suggestions for improving the draft, please send 58 email to http-state@ietf.org. Suggestions with test cases are 59 especially appreciated. 61 Table of Contents 63 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 64 1.1. Syntax Notation . . . . . . . . . . . . . . . . . . . . . 4 65 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 5 66 3. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 67 3.1. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 6 68 4. Protocol Description . . . . . . . . . . . . . . . . . . . . . 7 69 4.1. Set-Cookie . . . . . . . . . . . . . . . . . . . . . . . . 7 70 4.1.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . 7 71 4.1.2. Semantics . . . . . . . . . . . . . . . . . . . . . . 8 72 4.2. Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . 9 73 4.2.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . 9 74 4.2.2. Semantics . . . . . . . . . . . . . . . . . . . . . . 10 75 4.3. Controlling Caching . . . . . . . . . . . . . . . . . . . 10 76 5. User Agent Conformance . . . . . . . . . . . . . . . . . . . . 12 77 5.1. Parsing the Set-Cookie Header . . . . . . . . . . . . . . 12 78 5.1.1. The Max-Age Attribute . . . . . . . . . . . . . . . . 14 79 5.1.2. The Expires Attribute . . . . . . . . . . . . . . . . 14 80 5.1.3. The Domain Attribute . . . . . . . . . . . . . . . . . 17 81 5.1.4. The Path Attribute . . . . . . . . . . . . . . . . . . 17 82 5.1.5. The Secure Attribute . . . . . . . . . . . . . . . . . 18 83 5.1.6. The HttpOnly Attribute . . . . . . . . . . . . . . . . 18 84 5.2. Storage Model . . . . . . . . . . . . . . . . . . . . . . 18 85 5.3. The Cookie Header . . . . . . . . . . . . . . . . . . . . 21 86 6. Implementation Considerations . . . . . . . . . . . . . . . . 23 87 6.1. Set-Cookie Content . . . . . . . . . . . . . . . . . . . . 23 88 6.2. Implementation Limits . . . . . . . . . . . . . . . . . . 23 89 7. Security Considerations . . . . . . . . . . . . . . . . . . . 24 90 7.1. Clear Text . . . . . . . . . . . . . . . . . . . . . . . . 24 91 7.2. Weak Isolation . . . . . . . . . . . . . . . . . . . . . . 24 92 7.3. Cookie Spoofing . . . . . . . . . . . . . . . . . . . . . 24 93 8. Other, Similar, Proposals . . . . . . . . . . . . . . . . . . 25 94 9. Normative References . . . . . . . . . . . . . . . . . . . . . 26 95 Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 27 96 Appendix B. Tabled Items . . . . . . . . . . . . . . . . . . . . 28 97 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 29 99 1. Introduction 101 This document defines the HTTP Cookie and Set-Cookie header. 103 1.1. Syntax Notation 105 This specification uses the Augmented Backus-Naur Form (ABNF) 106 notation of [RFC5234]. 108 The following core rules are included by reference, as defined in 109 [RFC5234], Appendix B.1: ALPHA (letters), CR (carriage return), CRLF 110 (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double quote), 111 HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 8-bit 112 sequence of data), SP (space), VCHAR (any visible [USASCII] 113 character), and WSP (whitespace). 115 2. Terminology 117 The terms user agent, client, server, proxy, and origin server have 118 the same meaning as in the HTTP/1.0 specification. 120 Fully-qualified host name (FQHN) means either the fully-qualified 121 domain name (FQDN) of a host (i.e., a completely specified domain 122 name ending in a top-level domain such as .com or .uk), or the 123 numeric Internet Protocol (IP) address of a host. The fully 124 qualified domain name is preferred; use of numeric IP addresses is 125 strongly discouraged. [TODO: What does "strongly discouraged" mean?] 127 The terms request-host and request-URI refer to the values the client 128 would send to the server as, respectively, the host (but not port) 129 and abs_path portions of the absoluteURI (http_URL) of the HTTP 130 request line. Note that request-host must be a FQHN. Hosts names 131 can be specified either as an IP address or a FQHN string. 133 Because it was used in Netscape's original implementation of state 134 management, we will use the term cookie to refer to the state 135 information that passes between an origin server and user agent, and 136 that gets stored by the user agent. 138 3. Overview 140 We outline here a way for an origin server to send state information 141 to the user agent, and for the user agent to return the state 142 information to the origin server. 144 The origin server initiates a session, if it so desires, by including 145 a Set-Cookie header in an HTTP response. (Note that "session" here 146 does not refer to a persistent network connection but to a logical 147 session created from HTTP requests and responses. The presence or 148 absence of a persistent connection should have no effect on the use 149 of cookie-derived sessions). 151 A user agent returns a Cookie request header (see below) to the 152 origin server if it chooses to continue a session. The origin server 153 may ignore it or use it to determine the current state of the 154 session. It may send the client a Set-Cookie response header with 155 the same or different information, or it may send no Set-Cookie 156 header at all. 158 Servers may return a Set-Cookie response headers with any response. 159 User agents should send Cookie request headers, subject to other 160 rules detailed below, with every request. 162 An origin server may include multiple Set-Cookie headers in a 163 response. Note that an intervening gateway MUST NOT fold multiple 164 Set-Cookie headers into a single header. 166 [TODO: Overview the Set-Cookie and Cookie headers.] 168 3.1. Examples 170 [TODO: Put some examples here. 172 4. Protocol Description 174 The cookie protocol consists of two HTTP headers: the Set-Cookie 175 header and the Cookie header. The server sends the Set-Cookie header 176 is to the user agent in an HTTP response, causing the user agent to 177 modify the Cookie header it returns to the server. 179 This section describes the syntax and semantics of the protocol. 180 Detailed conformance requirements for user agents are given in 181 Section [TODO]. 183 4.1. Set-Cookie 185 4.1.1. Syntax 187 Informally, the Set-Cookie response header comprises the token Set- 188 Cookie:, followed by a cookie. Each cookie begins with a name-value- 189 pair, followed by zero or more semi-colon-separated attribute-value 190 pairs. 192 [TODO: Consider replacing this grammar with the one from 2009-11-07- 193 Yui-Naruse.txt.] 195 set-cookie-header = "Set-Cookie:" name-value-pairs 196 name-value-pairs = name-value-pair *(";" name-value-pair) 197 name-value-pair = name ["=" value] ; optional value 198 name = token 199 value = *CHAR 200 token = 202 The valid character for the value production vary depending on the 203 attribute name. 205 [TODO: Investigate what token actually means.] 207 Attributes names are case-insensitive. White space is permitted 208 between tokens. Servers MUST NOT include two attributes with the 209 same name. Note that although the above syntax description shows 210 value as optional, some attributes require values. 212 The cookie-value is opaque to the user agent and MAY be anything the 213 origin server chooses to send, possibly in a server-selected 214 printable ASCII encoding. "Opaque" implies that the content is of 215 interest and relevance only to the origin server. The content may, 216 in fact, be readable by anyone who examines the Set-Cookie header. 218 NOTE: The syntax above allows whitespace between the attribute and 219 the U+3D ("=") character. Servers wishing to interoperate with some 220 legacy user agents might wish to elide this extra white space to 221 maximize compatibility. 223 4.1.2. Semantics 225 When the user agent receives a Set-Cookie header, the user agent 226 stores the cookie in its cookie store. When the user agent makes 227 another HTTP request to the origin server, the user agent returns the 228 cookie in the Cookie header. 230 The server can override the default handling of cookies by specifying 231 cookie attributes. User agents ignore unrecognized cookie 232 attributes. 234 4.1.2.1. Max-Age 236 [TODO: Consider removing Max-Age from the server conformance section 237 because it's not supported by IE.] 239 Syntax A sequence of ASCII numerals. 241 Semantics The value of the Max-Age attribute represents the maximum 242 lifetime of the cookie, measured in seconds from the moment the 243 user agent receives the cookie. If the server does not supply an 244 Expires or a Max-Age attribute, the lifetime of the cookie is 245 limited to the current session (as defined by the user agent). 247 4.1.2.2. Expires 249 Syntax An RFC 1123 date [cite]. (Note that user agents use very 250 forgiving date parers; see Section [TODO]). 252 Semantics The value of the Expires attribute represents the maximum 253 lifetime of the cookie, represented as the point in time at which 254 the cookie expires. If the server does not supply an Expires or a 255 Max-Age attribute, the lifetime of the cookie is limited to the 256 current session (as defined by the user agent). 258 4.1.2.3. Domain 260 [TODO: Test Domain.] The Domain attribute specifies the domain for 261 which the cookie is valid. The leading dot isn't required. If there 262 is no Domain attribute, the default is to return the cookie only to 263 the origin server. [TODO: You can only set cookies for related 264 domains.] 266 4.1.2.4. Path 268 Syntax A sequence of characters beginning with a "/" character. 270 Semantics The Path attribute specifies the scope of the cookie 271 within a given FQDN. The user agent will include a cookie in an 272 HTTP request only if the Request-URI's path matches, or is a 273 subdirectory of, the cookie's Path attribute (where the "/" 274 character is interpreted as a directory separator). The default 275 value for the Path attribute is the directory of the Request-URI 276 when the cookie was received. 278 4.1.2.5. Secure 280 Syntax Servers MUST NOT include a value. 282 Semantics The user agent SHOULD protect the confidentiality of 283 cookies with the Secure attribute by not transmitting Secure 284 cookies over an "insecure" channel (where "insecure" is defined by 285 the user agent). 287 4.1.2.6. HttpOnly 289 Syntax Servers MUST NOT include a value. 291 Semantics The user agent SHOULD protect confidentiality of cookies 292 with the HttpOnly attribute by not revealing their contents via 293 "non-HTTP" APIs. (Note that this document does not define which 294 APIs are "non-HTTP".) 296 4.2. Cookie 298 4.2.1. Syntax 300 The user agent returns stored cookies to the origin server in the 301 Cookie header. The Cookie header shares a common syntax with the 302 Set-Cookie header, but the semantics of the header differ 303 dramatically. 305 cookie-header = "Cookie:" name-value-pairs 306 name-value-pairs = name-value-pair *(";" name-value-pair) 307 name-value-pair = name "=" value 308 name = token 309 value = *CHAR 311 NOTE: If the server supplies a Set-Cookie header that does not 312 conform to the grammar in Section [TODO], the user agent might not 313 supply a Cookie header that conforms to the preceding grammar. 315 4.2.2. Semantics 317 Each name-value-pair represents a cookie stored by the user agent. 318 The cookie name is returned in as the name and the cookie value is 319 returned as the value. 321 The meaning of the cookies in the Cookie header is not defined by 322 this document. Servers are expected to imbue these cookies with 323 server-specific semantics. 325 4.3. Controlling Caching 327 [TODO: Should we go into this much detail here? This seems redundant 328 with the HTTP specs.] 330 An origin server must be cognizant of the effect of possible caching 331 of both the returned resource and the Set-Cookie header. Caching 332 "public" documents is desirable. For example, if the origin server 333 wants to use a public document such as a "front door" page as a 334 sentinel to indicate the beginning of a session for which a Set- 335 Cookie response header must be generated, the page should be stored 336 in caches "pre-expired" so that the origin server will see further 337 requests. "Private documents", for example those that contain 338 information strictly private to a session, should not be cached in 339 shared caches. 341 If the cookie is intended for use by a single user, the Set-Cookie 342 header should not be cached. A Set-Cookie header that is intended to 343 be shared by multiple users may be cached. 345 The origin server should send the following additional HTTP/1.1 346 response headers, depending on circumstances: [TODO: Is this good 347 advice?] 349 o To suppress caching of the Set-Cookie header: Cache-control: no- 350 cache="set-cookie". 352 and one of the following: 354 o To suppress caching of a private document in shared caches: Cache- 355 Control: private. 357 o To allow caching of a document and require that it be validated 358 before returning it to the client: Cache-Control: must-revalidate. 360 o To allow caching of a document, but to require that proxy caches 361 (not user agent caches) validate it before returning it to the 362 client: Cache-Control: proxy-revalidate. 364 o To allow caching of a document and request that it be validated 365 before returning it to the client (by "pre-expiring" it): Cache- 366 Control: max-age=0. Not all caches will revalidate the document 367 in every case. 369 HTTP/1.1 servers must send Expires: old-date (where old-date is a 370 date long in the past) on responses containing Set-Cookie response 371 headers unless they know for certain (by out of band means) that 372 there are no downstream HTTP/1.0 proxies. HTTP/1.1 servers may send 373 other Cache-Control directives that permit caching by HTTP/1.1 374 proxies in addition to the Expires: old-date directive; the Cache- 375 Control directive will override the Expires: old-date for HTTP/1.1 376 proxies. 378 5. User Agent Conformance 380 Not all origin servers conform to the behavior specified in the 381 previous section. To ensure interoperability, user agents MUST 382 process cookies in a manner that is "black-box" indistinguishable 383 from the requirements in this section. 385 5.1. Parsing the Set-Cookie Header 387 Let an LWS character be either a U+20 (SPACE) or a U+09 (TAB) 388 character. 390 When a user agent receives an Set-Cookie header in an HTTP response, 391 the user agent *receives a set-cookie-string* consisting of the value 392 of the header. 394 A user agent MUST use the following algorithm to parse set-cookie- 395 strings: 397 1. [TODO: Deal with "," characters. My current thinking is that we 398 don't actually have to do anything special for them.] 400 2. If the header contains a U+3B (";") character: 402 the name-value-pair string is characters up to, but not 403 including, the first U+3B (";"), and the unparsed-cookie- 404 attributes are the remainder of the header (including the U+3B 405 (";") in question). 407 Otherwise: 409 the name-value-pair string is all the character contained in 410 the header, and the unparsed-cookie-attributes is the empty 411 string. 413 3. If the name-value-pair string contains a U+3D ("=") character: 415 the (possibly empty) name string is the characters up to, but 416 not including, the first U+3D ("=") character, and the 417 (possibly empty) value string is the characters after the 418 first U+3D ("=") character. 420 Otherwise: 422 the name string is empty, and the value string is the entire 423 name-value-pair string. 425 4. Remove any leading or trailing space from the name string and the 426 value string. 428 5. The cookie-name is the name string, and the cookie-value is the 429 value string. 431 The user agent MUST use the following algorithm to parse the 432 unparsed-attributes: 434 1. If the unparsed-attributes string is empty, skip the rest of 435 these steps. 437 2. Consume the first character of the unparsed-attributes (which 438 will be a U+3B (";") character). 440 3. If the remaining unparsed-attributes contains a U+3B (";") 441 character: 443 Consume the characters of the unparsed-attributes up to, but 444 not including, the first U+3B (";") character. 446 Otherwise: 448 Consume the remainder of the unparsed-attributes. 450 The characters consumed in this step comprise the attribute- 451 value-pair string. 453 4. If the attribute-value-pair string contains a U+3D ("=") 454 character: 456 the (possibly empty) name string is the characters up to, but 457 not including, the first U+3D ("=") character, and the 458 (possibly empty) value string is the characters after the 459 first U+3D ("=") character . 461 Otherwise: 463 the name string is the entire attribute-value-pair string, and 464 the value string is empty. (Note that this step differs from 465 the analogous step when parsing the name-value-pair string.) 467 5. Remove any leading or trailing space from the name string and the 468 value string. 470 6. If the name is a ASCII case-insensitive match for an entry in the 471 following table, process the value string as instructed. 473 Attribute | Instruction 474 ------------+--------------------- 475 Max-Age | See Section [TODO] 476 Expires | See Section [TODO] 477 Domain | See Section [TODO] 478 Path | See Section [TODO] 479 Secure | See Section [TODO] 480 HttpOnly | See Section [TODO] 482 7. Return to Step 1. 484 [TODO: Can parsing a cookie ever fail? Doesn't look like it! Well, 485 unless you count "Set-Cookie: " as a fail...] 487 When the user agent finishes parsing the set-cookie-string header, 488 the user agent *receives a cookie* from the origin server with name 489 cookie-name, value cookie-value, and attributes cookie-attribute- 490 list. 492 5.1.1. The Max-Age Attribute 494 When the user agent receives a cookie attribute with a name string 495 that case-insensitively matches the string "Max-Age", the user agent 496 MUST process the value string as follows. 498 If the first character of the value string is not a DIGIT or a "-" 499 character, the user agent MUST ignore the attribute. 501 If the remainder of value string contains a non-DIGIT character, the 502 user agent MUST ignore the attribute. 504 Let delta-seconds be the contents of the value string converted to an 505 integer. 507 If delta-seconds is less than or equal to 0, then append an attribute 508 named Expires (note the name conversion) to the cookie-attribute-list 509 with a value equal to the current date and time. 511 If delta-seconds is strictly greater than 0, then append an attribute 512 named Expires (note the name conversion) to the cookie-attribute-list 513 with a value equal to the current date and time plus delta-seconds 514 seconds. 516 5.1.2. The Expires Attribute 518 Unfortunately, cookie dates are quite complex for historical reasons. 520 When the user agent receives a cookie attribute with a name string 521 that case-insensitively matches the string "Expires", the user agent 522 MUST process the value string as follows. 524 If the attribute lacks a value or the value is the empty string, 525 abort these steps. 527 Using the grammar below, divide the value of the attribute into date- 528 tokens. 530 cookie-date = date-token-list 531 date-token-list = date-token [ delimiter date-token-list ] 532 delimiter = %x09 / %x20 / %x21 / %x22 / %x23 / %x24 / 533 %x25 / %x26 / %x27 / %x28 / %x29 / %x2A / 534 %x2B / %x2C / %x2D / %x2E / %x2F / %x3B / 535 %x3C / %x3D / %x3E / %x3F / %x40 / %x5B / 536 %x5C / %x5D / %x5E / %x5F / %x60 / %x7B / 537 %x7C / %x7D / %x7E 538 date-token = day-of-month / month / year / time / mystery 539 day-of-month = 2DIGIT / DIGIT 540 month = "jan" [ mystery ] / "feb" [ mystery ] / 541 "mar" [ mystery ] / "apr" [ mystery ] / 542 "may" [ mystery ] / "jun" [ mystery ] / 543 "jul" [ mystery ] / "aug" [ mystery ] / 544 "sep" [ mystery ] / "oct" [ mystery ] / 545 "nov" [ mystery ] / "dec" [ mystery ] 546 year = 5DIGIT / 4DIGIT / 3DIGIT / 2DIGIT / DIGIT 547 time = 2DIGIT ":" 2DIGIT ":" 2DIGIT 548 mystery = 550 Process each data-token sequentially in the order the date-tokens 551 appear in the attribute value: 553 1. If the found-day-of-month flag is not set and the token matches 554 the day-of-month production, set the found-day-of-month flag and 555 set the day-of-month-value to the number denoted by the token. 556 Skip the remaining sub-steps and continue to the next token. 558 2. If the found-month flag is not set and the token matches the 559 month production, set the found-month flag and set the month- 560 value to the month denoted by the token. Skip the remaining sub- 561 steps and continue to the next token. 563 3. If the found-year flag is not set and the token matches the year 564 production, set the found-year flag and set the year-value to the 565 number denoted by the token. Skip the remaining sub-steps and 566 continue to the next token. 568 4. If the found-time flag is not set and the token matches the time 569 production, set the found-time flag and set the hour-value, 570 minute-value, and second-value to the numbers denoted by the 571 digits in the token, respectively. Skip the remaining sub-steps 572 and continue to the next token. 574 Abort these steps if 576 o at least one of the found-day-of-month, found-month, found-year, 577 or found-time flags is not set, 579 o the day-of-month-value is less than 1 or greater than 31, 581 o the year-value is less than 1601 or greater than 30827, 583 o the hour-value is greater than 23, 585 o the minute-value is greater than 59, or 587 o the second-value is greater than 59. 589 If the year-value is greater than 68 and less than 100, increment the 590 year-value by 1900. 592 If the year-value is greater than or equal to 0 and less than 69, 593 increment the year-value by 2000. 595 Let the expiry-time be the date whose day-of-month, month, year, 596 hour, minute, and second (in GMT) are the day-of-month-value, the 597 month-value, the year-value, the hour-value, the minute-value, and 598 the second-value, respectively. 600 If the expiry-time is later than the last date the user agent can 601 represent, the user agent MAY replace the expiry-time with the last 602 representable date. 604 If the expiry-time is earlier than the first date the user agent can 605 represent, the user agent MAY replace the expiry-time with the first 606 representable date. 608 Append an attribute named Expires to the cookie-attribute-list with a 609 value equal to expiry-time. 611 5.1.3. The Domain Attribute 613 When the user agent receives a cookie attribute with a name string 614 that case-insensitively matches the string "Domain", the user agent 615 MUST process the value string as follows: 617 o If the value string is empty, then ignore the attribute. [TODO: 618 Add a test for this with multiple Domain attributes.] 620 o If the first character of the value string is ".", then append an 621 attribute named Domain to the cookie-attribute-list with a value 622 equal to value string excluding the leading "." character. 624 o If the first character of the value string is not ".", then append 625 an attribute named Domain to the cookie-attribute-list with a 626 value equal to value string and mark the attribute as host-only. 628 o [TODO: Deal with domains that have an insufficient number of 629 fields.] 631 o Otherwise, ignore the attribute. 633 5.1.4. The Path Attribute 635 The user agent MUST use the following algorithm to compute the 636 default-path of a cookie: 638 1. Let uri-path be the path portion of the URI from which the user 639 agent received the cookie. [TODO: Define this more precisely.] 641 2. If the first character of the uri-path is not a "/" character, 642 output "/" and skip the remaining steps. 644 3. If the uri-path contains only a single "/" character, output "/" 645 and skip the remaining steps. 647 4. Output the characters of the uri-path from the first character up 648 to, and but not including, the right-most "/". 650 A request-path path-matches a cookie-path if the cookie-path is a 651 prefix of the request-path and at least one of the following 652 conditions hold: 654 o The last character of the cookie-path is "/". 656 o The first character of the request-path that is not included in 657 the cookie-path is a "/" character. 659 When the user agent receives a cookie attribute with a name string 660 that case-insensitively matches the string "Path", the user agent 661 MUST process the value string as follows: 663 o If the value string is empty, then append an attribute named Path 664 to the cookie-attribute-list with a value equal to default-path of 665 the cookie. [TODO: Is this right if there are more than one path 666 attribute?] 668 o If the value string is non-empty and the first character is "/", 669 then append an attribute named Path to the cookie-attribute-list 670 with a value equal to value string. 672 o Otherwise, ignore the attribute. 674 [TODO: Test \ ? ; # $ % etc] 676 5.1.5. The Secure Attribute 678 When the user agent receives a cookie attribute with a name string 679 that case-insensitively matches the string "Secure", the user agent 680 MUST append an attribute named Secure to the cookie-attribute-list 681 with an empty value regardless of the value string. 683 5.1.6. The HttpOnly Attribute 685 When the user agent receives a cookie attribute with a name string 686 that case-insensitively matches the string "HttpOnly", the user agent 687 MUST append an attribute named HttpOnly to the cookie-attribute-list 688 with an empty value regardless of the value string. 690 5.2. Storage Model 692 When the user agent receives a cookie, the user agent SHOULD record 693 the cookie in its cookie store as follows. 695 A user agent MAY ignore received cookies in their entirety if the 696 user agent is configured to block receiving cookie for a particular 697 response. For example, the user agent might wish to block receiving 698 cookies from "third-party" responses. 700 The user agent stores the following fields about each cookie: 702 o name (a sequence of bytes) 704 o value (a sequence of bytes) 705 o expiry (a date) 707 o domain (a cookie-domain) 709 o path (a sequence of bytes) 711 o creation (a date) 713 o last-access (a date) 715 o persistent (a Boolean) 717 o host-only (a Boolean) 719 o secure-only (a Boolean) 721 o http-only (a Boolean) 723 When the user agent receives a cookie, the user agent MUST follow the 724 following algorithm: 726 1. Create a new cookie based on the parsed Set-Cookie header: 728 1. Create a new cookie with the following default field values: 730 + name = the cookie-name 732 + value = the cookie-value 734 + expiry = the latest representable date 736 + domain = the request-host 738 + path = the cookie's default-path 740 + last-access = the date and time the cookie was received 742 + persistent = false 744 + host-only = true 746 + secure-only = false 748 + http-only = false 750 2. Update the default field values according to the cookie- 751 attributes: 753 expiry If the cookie-attributes contains at least one valid 754 Expires attribute, store the expiry-value of the last such 755 attribute in the expiry field. Store the value true in 756 the persistent field. [TODO: Test that this really works 757 when mixing Max-Age and Expires.] 759 domain If the cookie-attributes contains at least one Domain 760 attribute, store the value of the last such attribute in 761 the domain field. Store the value false in the host-only 762 field. [TODO: Reject cookies for unrelated domains.] 763 [TODO: If the URL's host is an IP address, let Domain to 764 be an IP address if it matches the URL's host exactly, but 765 set the host-only flag. ] 767 path If the cookie-attributes contains at least one Path 768 attribute, store the value of the last such attribute in 769 the path field. 771 secure-only If the cookie-attributes contains at least one 772 Secure attribute, store the value true in the secure-only 773 field. 775 http-only If the cookie-attributes contains at least one 776 HttpOnly attribute, store the value true in the http-only 777 field. 779 2. Remove from the cookie store all cookies that have the share the 780 same name, domain, path, and host-only fields as the newly 781 created cookie. [TODO: Validate this list!] [TODO: There's some 782 funny business around http-only here.] 784 3. Insert the newly created cookie into the cookie store. 786 The user agent MUST evict a cookie from the cookie store if A cookie 787 exists in the cookie store with an expiry date in the past. 789 The user agent MAY evict a cookie from the cookie store if the number 790 of cookies sharing a domain field exceeds some predetermined upper 791 bound (such as 50 cookies). [TODO: Explain where 50 comes from.] 793 The user agent MAY evict cookies from the cookie store if the cookie 794 store exceeds some maximum storage bound (such as 3000 cookies). 795 [TODO: Explain where 3000 comes from.] 797 When the user agent evicts cookies from the cookie store, the user 798 agent MUST evict cookies in the following priority order: 800 1. Cookies with an expiry date in the past. 802 2. Cookies that share a domain field more than a predetermined 803 number of other cookies. 805 3. All other cookies. 807 If two cookies have the same removal priority, the user agent MUST 808 evict the cookie with the least recent last-access date first. 810 When "the current session is over", the user agent MUST remove from 811 the cookie store all cookies with the persistent field set to false. 813 NOTE: This document does not define when "the current session is 814 over." Many user agents remove non-persistent cookies when they 815 exit. However, other user agent expire non-persistent cookies 816 using other heuristics. 818 5.3. The Cookie Header 820 When the user agent generates an HTTP request for a particular URI, 821 the user agent SHOULD attach exactly one HTTP header named Cookie if 822 the cookie-string (defined below) for that URI is non-empty. 824 A user agent MAY elide the Cookie header in its entirety if the user 825 agent is configured to block sending cookie for a particular request. 826 For example, the user agent might wish to block sending cookies 827 during "third-party" requests. 829 The user agent MUST use the following algorithm to compute the 830 cookie-string from a cookie store and a URI: 832 1. Let cookie-list be the set of cookies from the cookie store that 833 meet the following requirements: 835 * The cookie's domain field must domain-match the URI's host. 836 [TODO: Spec me] 838 * The cookie's path field must path-match the URI's path. 840 * If the cookie's host-only flag is set, the cookie's domain 841 field must denote exactly the same FQDN as the URI's host. 842 [TODO: Internet Explorer does not implement this requirement 843 but most other major implementations do.] 845 * If the cookie's secure-only field is true, then the URI's 846 scheme must denote a "secure" protocol. 848 NOTE: The notion of an "secure" protocol is not defined by 849 this document. Typically, user agents consider a protocol 850 secure if the protocol makes use of transport-layer 851 security, such as TLS. For example, most user agents 852 consider "https" to be a scheme that denotes a secure 853 protocol. 855 * If the cookie's http-only field is true, then include the 856 cookie unless the cookie-string is begin generated for a "non- 857 HTTP" API. (Note that this document does not define which 858 APIs are "non-HTTP".) 860 NOTE: The Cookie header will not contain any expired cookies 861 because cookies past their expiry date are removed from the 862 cookie store immediately. 864 2. Sort the cookie-list in the following order: 866 * Cookies with longer path fields are listed before cookies with 867 shorter path field. 869 * Among cookies that have equal length path fields, cookies with 870 earlier creation dates are listed before cookies with later 871 creation dates. 873 3. Update the last-access field of each cookie in the cookie-list to 874 the current date. 876 4. Serialize the cookie-list into a cookie-string by processing each 877 cookie in the cookie-list in order: 879 1. If the cookie's name and value fields are both empty, skip 880 the remaining steps for this cookie and continue to the next 881 cookie, if any. 883 2. If the cookie's name field is non-empty, output the cookie's 884 name field followed by the character U+3D ("="). 886 3. Output the cookie's value field. 888 4. If there is an unprocessed cookie in the cookie-list, output 889 the characters U+3B and U+20 ("; ") 891 6. Implementation Considerations 893 6.1. Set-Cookie Content 895 An origin server's content should probably be divided into disjoint 896 application areas, some of which require the use of state 897 information. The application areas can be distinguished by their 898 request URLs. The Set-Cookie header can incorporate information 899 about the application areas by setting the Path attribute for each 900 one. 902 The session information can obviously be clear or encoded text that 903 describes state. However, if it grows too large, it can become 904 unwieldy. Therefore, an implementor might choose for the session 905 information to be a key to a server-side resource. [TODO: Describe 906 briefly how to generate a decent session key.] 908 [TODO: We could recommend that servers encrypt and mac their cookie 909 data.] 911 [TODO: Mention issues that arise from having multiple concurrent 912 sessions.] 914 6.2. Implementation Limits 916 Practical user agent implementations have limits on the number and 917 size of cookies that they can store. General-use user agents SHOULD 918 provide each of the following minimum capabilities: 920 o At least 4096 bytes per cookie (as measured by the size of the 921 characters that comprise the cookie non-terminal in the syntax 922 description of the Set-Cookie header). [TODO: Validate] 924 o At least 50 cookies per domain. [TODO: History lesson] 926 o At least 3000 cookies total. 928 The information in a Set-Cookie response header must be retained in 929 its entirety. If for some reason there is inadequate space to store 930 the cookie, the cookie must be discarded, not truncated. 932 Applications should use as few and as small cookies as possible, and 933 they should cope gracefully with the loss of a cookie. [TODO: Could 934 mention latency issues that arise from having tons of cookies.] 936 7. Security Considerations 938 7.1. Clear Text 940 The information in the Set-Cookie and Cookie headers is transmitted 941 in the clear. Three consequences are: 943 1. Any sensitive information that is conveyed in in the headers is 944 exposed to an eavesdropper. 946 2. A malicious intermediary could alter the headers as they travel 947 in either direction, with unpredictable results. 949 3. A malicious client could alter the Cookie header before 950 transmission, with unpredictable results. 952 These facts imply that information of a personal and/or financial 953 nature should be sent over a secure channel. For less sensitive 954 information, or when the content of the header is a database key, an 955 origin server should be vigilant to prevent a bad Cookie value from 956 causing failures. 958 7.2. Weak Isolation 960 [TODO: Weak isolation by port.] 962 [TODO: Weak isolation by scheme (e.g., ftp, gopher, etc).] 964 7.3. Cookie Spoofing 966 [TODO: Mention integrity issue where a sibling domain can inject 967 cookies.] 969 [TODO: Mention integrity issue where a HTTP can inject cookies into 970 HTTPS.] 972 8. Other, Similar, Proposals 974 [TODO: Describe relation to the Netscape Cookie Spec, RFC 2109, RFC 975 2629, and cookie-v2.] 977 9. Normative References 979 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 980 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 981 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 983 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 984 Specifications: ABNF", STD 68, RFC 5234, January 2008. 986 Appendix A. Acknowledgements 988 This document borrows heavily from RFC 2109. [TODO: Figure out the 989 proper way to credit the authors of RFC 2109.] 991 Appendix B. Tabled Items 993 Tabled items: 995 o Public suffix. 997 Author's Address 999 Adam Barth 1000 University of California, Berkeley 1002 Email: abarth@eecs.berkeley.edu 1003 URI: http://www.adambarth.com/