idnits 2.17.1 draft-abarth-cookie-04.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 150: '...ervening gateway MUST NOT fold multipl...' RFC 2119 keyword, line 191: '...tokens. Servers MUST NOT include two ...' RFC 2119 keyword, line 195: '...the user agent and MAY be anything the...' RFC 2119 keyword, line 262: '... Syntax Servers MUST NOT include a va...' RFC 2119 keyword, line 264: '... The user agent SHOULD protect the co...' (26 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 (November 11, 2009) is 5278 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? 'TODO' on line 583 looks like a reference Summary: 3 errors (**), 0 flaws (~~), 3 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 None (yet) A. Barth 3 Internet-Draft U.C. Berkeley 4 Expires: May 15, 2010 November 11, 2009 6 HTTP State Management Mechanism 7 draft-abarth-cookie-04 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 May 15, 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: Much of the text herein is completely wrong. If you have 58 suggestions for improving the draft, please send email to 59 http-state@ietf.org. Suggestions with test cases are especially 60 appreciated. 62 Table of Contents 64 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 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 . . . . . . . . . . . . . . . . . 16 81 5.1.4. The Path Attribute . . . . . . . . . . . . . . . . . . 16 82 5.1.5. The Secure Attribute . . . . . . . . . . . . . . . . . 17 83 5.1.6. The HttpOnly Attribute . . . . . . . . . . . . . . . . 17 84 5.2. Storage Model . . . . . . . . . . . . . . . . . . . . . . 18 85 5.3. The Cookie Header . . . . . . . . . . . . . . . . . . . . 20 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 Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 26 95 Appendix B. Tabled Items . . . . . . . . . . . . . . . . . . . . 27 96 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 28 98 1. Introduction 100 This document defines the HTTP Cookie and Set-Cookie header. 102 2. Terminology 104 The terms user agent, client, server, proxy, and origin server have 105 the same meaning as in the HTTP/1.0 specification. 107 Fully-qualified host name (FQHN) means either the fully-qualified 108 domain name (FQDN) of a host (i.e., a completely specified domain 109 name ending in a top-level domain such as .com or .uk), or the 110 numeric Internet Protocol (IP) address of a host. The fully 111 qualified domain name is preferred; use of numeric IP addresses is 112 strongly discouraged. [TODO: What does "strongly discouraged" mean?] 114 The terms request-host and request-URI refer to the values the client 115 would send to the server as, respectively, the host (but not port) 116 and abs_path portions of the absoluteURI (http_URL) of the HTTP 117 request line. Note that request-host must be a FQHN. Hosts names 118 can be specified either as an IP address or a FQHN string. 120 Because it was used in Netscape's original implementation of state 121 management, we will use the term cookie to refer to the state 122 information that passes between an origin server and user agent, and 123 that gets stored by the user agent. 125 3. Overview 127 We outline here a way for an origin server to send state information 128 to the user agent, and for the user agent to return the state 129 information to the origin server. 131 The origin server initiates a session, if it so desires, by including 132 a Set-Cookie header in an HTTP response. (Note that "session" here 133 does not refer to a persistent network connection but to a logical 134 session created from HTTP requests and responses. The presence or 135 absence of a persistent connection should have no effect on the use 136 of cookie-derived sessions). 138 A user agent returns a Cookie request header (see below) to the 139 origin server if it chooses to continue a session. The origin server 140 may ignore it or use it to determine the current state of the 141 session. It may send the client a Set-Cookie response header with 142 the same or different information, or it may send no Set-Cookie 143 header at all. 145 Servers may return a Set-Cookie response headers with any response. 146 User agents should send Cookie request headers, subject to other 147 rules detailed below, with every request. 149 An origin server may include multiple Set-Cookie headers in a 150 response. Note that an intervening gateway MUST NOT fold multiple 151 Set-Cookie headers into a single header. 153 [TODO: Overview the Set-Cookie and Cookie headers.] 155 3.1. Examples 157 [TODO: Put some examples here. 159 4. Protocol Description 161 The cookie protocol consists of two HTTP headers: the Set-Cookie 162 header and the Cookie header. The server sends the Set-Cookie header 163 is to the user agent in an HTTP response, causing the user agent to 164 modify the Cookie header it returns to the server. 166 This section describes the syntax and semantics of the protocol. 167 Detailed conformance requirements for user agents are given in 168 Section [TODO]. 170 4.1. Set-Cookie 172 4.1.1. Syntax 174 Informally, the Set-Cookie response header comprises the token Set- 175 Cookie:, followed by a cookie. Each cookie begins with a name-value- 176 pair, followed by zero or more semi-colon-separated attribute-value 177 pairs. 179 set-cookie-header = "Set-Cookie:" name-value-pairs 180 name-value-pairs = name-value-pair *(";" name-value-pair) 181 name-value-pair = name ["=" value] ; optional value 182 name = token 183 value = *CHAR 185 The valid character for the value production vary depending on the 186 attribute name. 188 [TODO: Investigate what token actually means.] 190 Attributes names are case-insensitive. White space is permitted 191 between tokens. Servers MUST NOT include two attributes with the 192 same name. Note that although the above syntax description shows 193 value as optional, some attributes require values. 195 The cookie-value is opaque to the user agent and MAY be anything the 196 origin server chooses to send, possibly in a server-selected 197 printable ASCII encoding. "Opaque" implies that the content is of 198 interest and relevance only to the origin server. The content may, 199 in fact, be readable by anyone who examines the Set-Cookie header. 201 NOTE: The syntax above allows whitespace between the attribute and 202 the U+3D ("=") character. Servers wishing to interoperate with some 203 legacy user agents might wish to elide this extra white space to 204 maximize compatibility. 206 4.1.2. Semantics 208 When the user agent receives a Set-Cookie header, the user agent 209 stores the cookie in its cookie store. When the user agent makes 210 another HTTP request to the origin server, the user agent returns the 211 cookie in the Cookie header. 213 The server can override the default handling of cookies by specifying 214 cookie attributes. User agents ignore unrecognized cookie 215 attributes. 217 4.1.2.1. Max-Age 219 [TODO: Consider removing Max-Age from the server conformance section 220 because it's not supported by IE.] 222 Syntax A sequence of ASCII numerals. 224 Semantics The value of the Max-Age attribute represents the maximum 225 lifetime of the cookie, measured in seconds from the moment the 226 user agent receives the cookie. If the server does not supply an 227 Expires or a Max-Age attribute, the lifetime of the cookie is 228 limited to the current session (as defined by the user agent). 230 4.1.2.2. Expires 232 Syntax An RFC 1123 date [cite]. (Note that user agents use very 233 forgiving date parers; see Section [TODO]). 235 Semantics The value of the Expires attribute represents the maximum 236 lifetime of the cookie, represented as the point in time at which 237 the cookie expires. If the server does not supply an Expires or a 238 Max-Age attribute, the lifetime of the cookie is limited to the 239 current session (as defined by the user agent). 241 4.1.2.3. Domain 243 [TODO: Test Domain.] The Domain attribute specifies the domain for 244 which the cookie is valid. The leading dot isn't required. If there 245 is no Domain attribute, the default is to return the cookie only to 246 the origin server. [TODO: You can only set cookies for related 247 domains.] 249 4.1.2.4. Path 250 Syntax A sequence of characters beginning with a "/" character. 252 Semantics The Path attribute specifies the scope of the cookie 253 within a given FQDN. The user agent will include a cookie in an 254 HTTP request only if the Request-URI's path matches, or is a 255 subdirectory of, the cookie's Path attribute (where the "/" 256 character is interpreted as a directory separator). The default 257 value for the Path attribute is the directory of the Request-URI 258 when the cookie was received. 260 4.1.2.5. Secure 262 Syntax Servers MUST NOT include a value. 264 Semantics The user agent SHOULD protect the confidentiality of 265 cookies with the Secure attribute by not transmitting Secure 266 cookies over an "insecure" channel (where "insecure" is defined by 267 the user agent). 269 4.1.2.6. HttpOnly 271 Syntax Servers MUST NOT include a value. 273 Semantics The user agent SHOULD protect confidentiality of cookies 274 with the HttpOnly attribute by not revealing their contents via 275 "non-HTTP" APIs. (Note that this document does not define which 276 APIs are "non-HTTP".) 278 4.2. Cookie 280 4.2.1. Syntax 282 The user agent returns stored cookies to the origin server in the 283 Cookie header. The Cookie header shares a common syntax with the 284 Set-Cookie header, but the semantics of the header differ 285 dramatically. 287 cookie-header = "Cookie:" name-value-pairs 288 name-value-pairs = name-value-pair *(";" name-value-pair) 289 name-value-pair = name "=" value 290 name = token 291 value = *CHAR 293 NOTE: If the server supplies a Set-Cookie header that does not 294 conform to the grammar in Section [TODO], the user agent might not 295 supply a Cookie header that conforms to the preceding grammar. 297 4.2.2. Semantics 299 Each name-value-pair represents a cookie stored by the user agent. 300 The cookie name is returned in as the name and the cookie value is 301 returned as the value. 303 The meaning of the cookies in the Cookie header is not defined by 304 this document. Servers are expected to imbue these cookies with 305 server-specific semantics. 307 4.3. Controlling Caching 309 [TODO: Should we go into this much detail here? This seems redundant 310 with the HTTP specs.] 312 An origin server must be cognizant of the effect of possible caching 313 of both the returned resource and the Set-Cookie header. Caching 314 "public" documents is desirable. For example, if the origin server 315 wants to use a public document such as a "front door" page as a 316 sentinel to indicate the beginning of a session for which a Set- 317 Cookie response header must be generated, the page should be stored 318 in caches "pre-expired" so that the origin server will see further 319 requests. "Private documents", for example those that contain 320 information strictly private to a session, should not be cached in 321 shared caches. 323 If the cookie is intended for use by a single user, the Set-Cookie 324 header should not be cached. A Set-Cookie header that is intended to 325 be shared by multiple users may be cached. 327 The origin server should send the following additional HTTP/1.1 328 response headers, depending on circumstances: [TODO: Is this good 329 advice?] 331 o To suppress caching of the Set-Cookie header: Cache-control: no- 332 cache="set-cookie". 334 and one of the following: 336 o To suppress caching of a private document in shared caches: Cache- 337 Control: private. 339 o To allow caching of a document and require that it be validated 340 before returning it to the client: Cache-Control: must-revalidate. 342 o To allow caching of a document, but to require that proxy caches 343 (not user agent caches) validate it before returning it to the 344 client: Cache-Control: proxy-revalidate. 346 o To allow caching of a document and request that it be validated 347 before returning it to the client (by "pre-expiring" it): Cache- 348 Control: max-age=0. Not all caches will revalidate the document 349 in every case. 351 HTTP/1.1 servers must send Expires: old-date (where old-date is a 352 date long in the past) on responses containing Set-Cookie response 353 headers unless they know for certain (by out of band means) that 354 there are no downstream HTTP/1.0 proxies. HTTP/1.1 servers may send 355 other Cache-Control directives that permit caching by HTTP/1.1 356 proxies in addition to the Expires: old-date directive; the Cache- 357 Control directive will override the Expires: old-date for HTTP/1.1 358 proxies. 360 5. User Agent Conformance 362 Not all origin servers conform to the behavior specified in the 363 previous section. To ensure interoperability, user agents MUST 364 process cookies in a manner that is "black-box" indistinguishable 365 from the requirements in this section. 367 5.1. Parsing the Set-Cookie Header 369 Let an LWS character be either a U+20 (SPACE) or a U+09 (TAB) 370 character. 372 When a user agent recieves an Set-Cookie header in an HTTP response, 373 the user agent *receives a set-cookie-string* consisting of the value 374 of the header. 376 A user agent MUST use the following algorithm to parse set-cookie- 377 strings: 379 1. [TODO: Deal with "," characters. My current thinking is that we 380 don't actually have to do anything special for them.] 382 2. If the header contains a U+3B (";") character: 384 the name-value-pair string is characters up to, but not 385 including, the first U+3B (";"), and the unparsed-cookie- 386 attributes are the remainder of the header (including the U+3B 387 (";") in question). 389 Otherwise: 391 the name-value-pair string is all the character contained in 392 the header, and the unparsed-cookie-attributes is the empty 393 string. 395 3. If the name-value-pair string contains a U+3D ("=") character: 397 the (possibly empty) name string is the characters up to, but 398 not including, the first U+3D ("=") character, and the 399 (possibly empty) value string is the characters after the 400 first U+3D ("=") character. 402 Otherwise: 404 the name string is empty, and the value string is the entire 405 name-value-pair string. 407 4. Remove any leading or trailing space from the name string and the 408 value string. 410 5. The cookie-name is the name string, and the cookie-value is the 411 value string. 413 The user agent MUST use the following algorithm to parse the 414 unparsed-attributes: 416 1. If the unparsed-attributes string is empty, skip the rest of 417 these steps. 419 2. Consume the first character of the unparsed-attributes (which 420 will be a U+3B (";") character). 422 3. If the remaining unparsed-attributes contains a U+3B (";") 423 character: 425 Consume the characters of the unparsed-attributes up to, but 426 not including, the first U+3B (";") character. 428 Otherwise: 430 Consume the remainder of the unparsed-attributes. 432 The characters consumed in this step comprise the attribute- 433 value-pair string. 435 4. If the attribute-value-pair string contains a U+3D ("=") 436 character: 438 the (possibly empty) name string is the characters up to, but 439 not including, the first U+3D ("=") character, and the 440 (possibly empty) value string is the characters after the 441 first U+3D ("=") character . 443 Otherwise: 445 the name string is the entire attribute-value-pair string, and 446 the value string is empty. (Note that this step differs from 447 the analogous step when parsing the name-value-pair string.) 449 5. Remove any leading or trailing space from the name string and the 450 value string. 452 6. If the name is a ASCII case-insensitive match for an entry in the 453 following table, process the value string as instructed. 455 Attribute | Instruction 456 ------------+--------------------- 457 Max-Age | See Section [TODO] 458 Expires | See Section [TODO] 459 Domain | See Section [TODO] 460 Path | See Section [TODO] 461 Secure | See Section [TODO] 462 HttpOnly | See Section [TODO] 464 7. Return to Step 1. 466 [TODO: Can parsing a cookie ever fail? Doesn't look like it! Well, 467 unless you count "Set-Cookie: " as a fail...] 469 When the user agent finishes parsing the set-cookie-string header, 470 the user agent *receives a cookie* from the origin server with name 471 cookie-name, value cookie-value, and attributes cookie-attribute- 472 list. 474 5.1.1. The Max-Age Attribute 476 When the user agent receives a cookie attribute with a name string 477 that case-insensitively matches the string "Max-Age", the user agent 478 MUST process the value string as follows. 480 If the first character of the value string is not a DIGIT or a "-" 481 character, the user agent MUST ignore the attribute. 483 If the remainder of value string contains a non-DIGIT character, the 484 user agent MUST ignore the attribute. 486 Let delta-seconds be the contents of the value string converted to an 487 integer. 489 If delta-seconds is less than or equal to 0, then append an attribute 490 named Expires (note the name conversion) to the cookie-attribute-list 491 with a value equal to the current date and time. 493 If delta-seconds is strictly greater than 0, then append an attribute 494 named Expires (note the name conversion) to the cookie-attribute-list 495 with a value equal to the current date and time plus delta-seconds 496 seconds. 498 5.1.2. The Expires Attribute 500 Unfortunately, cookie dates are quite complex for historical reasons. 502 When the user agent receives a cookie attribute with a name string 503 that case-insensitively matches the string "Expires", the user agent 504 MUST process the value string as follows. 506 If the attribute lacks a value or the value is the empty string, 507 abort these steps. 509 Using the grammar below, divide the value of the attribute into date- 510 tokens. 512 cookie-date = date-token-list 513 date-token-list = date-token [ delimiter date-token-list ] 514 delimiter = U+09 / U+20 / U+21 / U+22 / U+23 / U+24 / 515 U+25 / U+26 / U+27 / U+28 / U+29 / U+2A / 516 U+2B / U+2C / U+2D / U+2E / U+2F / U+3B / 517 U+3C / U+3D / U+3E / U+3F / U+40 / U+5B / 518 U+5C / U+5D / U+5E / U+5F / U+60 / U+7B / 519 U+7C / U+7D / U+7E 520 date-token = day-of-month / month / year / time / mystery 521 day-of-month = 2DIGIT / DIGIT 522 month = "jan" [mystery] / "feb" [mystery] / 523 "mar" [mystery] / "apr" [mystery] / 524 "may" [mystery] / "jun" [mystery] / 525 "jul" [mystery] / "aug" [mystery] / 526 "sep" [mystery] / "oct" [mystery] / 527 "nov" [mystery] / "dec" [mystery] 528 year = 5DIGIT / 4DIGIT / 3DIGIT / 2DIGIT / DIGIT 529 time = 2DIGIT ":" 2DIGIT ":" 2DIGIT 530 mystery = (anything except a delimiter) 532 Process each data-token sequentially in the order the date-tokens 533 appear in the attribute value. 535 If the found-day-of-month flag is not set and the token matches the 536 day-of-month production, set the found-day-of-month flag and set the 537 day-of-month-value to the number denoted by the token. 539 If the found-month flag is not set and the token matches the month 540 production, set the found-month flag and set the month-value to the 541 month denoted by the token. 543 If the found-year flag is not set and the token matches the year 544 production, set the found-year flag and set the year-value to the 545 number denoted by the token. 547 If the found-time flag is not set and the token matches the time 548 production, set the found-time flag and set the hour-value, minute- 549 value, and second-value to the numbers denoted by the digits in the 550 token, respectively. 552 Abort these steps if 554 o at least one of the found-day-of-month, found-month, found-year, 555 or found-time flags is not set, 557 o the day-of-month-value is less than 1 or greater than 31, 559 o the year-value is less than 1601 or greater than 30827, 561 o the hour-value is greater than 23, 563 o the minute-value is greater than 59, or 565 o the second-value is greater than 59. 567 If the year-value is greater than 68 and less than 100, increment the 568 year-value by 1900. 570 If the year-value is greater than or equal to 0 and less than 69, 571 increment the year-value by 2000. 573 Let the expiry-time be the date whose day-of-month, month, year, 574 hour, minute, and second (in GMT) are the day-of-month-value, the 575 month-value, the year-value, the hour-value, the minute-value, and 576 the second-value, respectively. 578 Append an attribute named Expires to the cookie-attribute-list with a 579 value equal to expiry-time. 581 5.1.3. The Domain Attribute 583 [TODO] 585 5.1.4. The Path Attribute 587 The user agent MUST use the following algorithm to compute the 588 default-path of a cookie: 590 1. Let uri-path be the path portion of the URI from which the user 591 agent received the cookie. [TODO: Define this more precisely.] 593 2. If the first character of the uri-path is not a "/" character, 594 output "/" and skip the remaining steps. 596 3. If the uri-path contains only a single "/" character, output "/" 597 and skip the remaining steps. 599 4. Output the characters of the uri-path from the first character up 600 to, and but not including, the right-most "/". 602 A request-path path-matches a cookie-path if the cookie-path is a 603 prefix of the request-path and at least one of the following 604 conditions hold: 606 o The last character of the cookie-path is "/". 608 o The first character of the request-path that is not included in 609 the cookie-path is a "/" character. 611 When the user agent receives a cookie attribute with a name string 612 that case-insensitively matches the string "Path", the user agent 613 MUST process the value string as follows: 615 o If the value string is empty, then append an attribute named Path 616 to the cookie-attribute-list with a value equal to default-path of 617 the cookie. 619 o If the value string is non-empty and the first character is "/", 620 then append an attribute named Path to the cookie-attribute-list 621 with a value equal to value string. 623 o Otherwise, ignore the attribute. 625 [TODO: Test \ ? ; # $ % etc] 627 5.1.5. The Secure Attribute 629 When the user agent receives a cookie attribute with a name string 630 that case-insensitively matches the string "Secure", the user agent 631 MUST append an attribute named Secure to the cookie-attribute-list 632 with an empty value regardless of the value string. 634 5.1.6. The HttpOnly Attribute 636 When the user agent receives a cookie attribute with a name string 637 that case-insensitively matches the string "HttpOnly", the user agent 638 MUST append an attribute named HttpOnly to the cookie-attribute-list 639 with an empty value regardless of the value string. 641 5.2. Storage Model 643 When the user agent receives a cookie, the user agent SHOULD record 644 the cookie in its cookie store as follows. 646 A user agent MAY ignore received cookies in their entirety if the 647 user agent is configured to block receiving cookie for a particular 648 response. For example, the user agent might wish to block receiving 649 cookies from "third-party" responses. 651 The user agent stores the following fields about each cookie: 653 o name (a sequence of bytes) 655 o value (a sequence of bytes) 657 o expiry (a date) 659 o domain (a cookie-domain) 661 o path (a sequence of bytes) 663 o creation (a date) 665 o last-access (a date) 667 o persistent (a Boolean) 669 o host-only (a Boolean) 671 o secure-only (a Boolean) 673 o http-only (a Boolean) 675 When the user agent receives a cookie, the user agent MUST follow the 676 following algorithm: 678 1. Create a new cookie based on the parsed Set-Cookie header: 680 1. Create a new cookie with the following default field values: 682 + name = the cookie-name 684 + value = the cookie-value 686 + expiry = the latest representable date 687 + domain = the request-host 689 + path = the cookie's default-path 691 + last-access = the date and time the cookie was received 693 + persistent = false 695 + host-only = true 697 + secure-only = false 699 + http-only = false 701 2. Update the default field values according to the cookie- 702 attributes: 704 expiry If the cookie-attributes contains at least one valid 705 Expires attribute, store the expiry-value of the last such 706 attribute in the expiry field. Store the value true in 707 the persistent field. [TODO: Test that this really works 708 when mixing Max-Age and Expires.] 710 domain If the cookie-attributes contains at least one Domain 711 attribute, store the value of the last such attribute in 712 the domain field. Store the value false in the host-only 713 field. [TODO: Reject cookies for unrelated domains.] 714 [TODO: If the URL's host is an IP address, let Domain to 715 be an IP address if it matches the URL's host exactly, but 716 set the host-only flag. ] 718 path If the cookie-attributes contains at least one Path 719 attribute, store the value of the last such attribute in 720 the path field. 722 secure-only If the cookie-attributes contains at least one 723 Secure attribute, store the value true in the secure-only 724 field. 726 http-only If the cookie-attributes contains at least one 727 HttpOnly attribute, store the value true in the http-only 728 field. 730 2. Remove from the cookie store all cookies that have the share the 731 same name, domain, path, and host-only fields as the newly 732 created cookie. [TODO: Validate this list!] [TODO: There's some 733 funny business around http-only here.] 735 3. Insert the newly created cookie into the cookie store. 737 The user agent MUST evict a cookie from the cookie store if A cookie 738 exists in the cookie store with an expiry date in the past. 740 The user agent MAY evict a cookie from the cookie store if the number 741 of cookies sharing a domain field exceeds some predetermined upper 742 bound (such as 50 cookies). [TODO: Explain where 50 comes from.] 744 The user agent MAY evict cookies from the cookie store if the cookie 745 store exceeds some maximum storage bound (such as 3000 cookies). 746 [TODO: Explain where 3000 comes from.] 748 When the user agent evicts cookies from the cookie store, the user 749 agent MUST evict cookies in the following priority order: 751 1. Cookies with an expiry date in the past. 753 2. Cookies that share a domain field more than a predetermined 754 number of other cookies. 756 3. All other cookies. 758 If two cookies have the same removal priority, the user agent MUST 759 evict the cookie with the least recent last-access date first. 761 When "the current session is over", the user agent MUST remove from 762 the cookie store all cookies with the persistent field set to false. 764 NOTE: This document does not define when "the current session is 765 over." Many user agents remove non-persistent cookies when they 766 exit. However, other user agent expire non-persistent cookies 767 using other heuristics. 769 5.3. The Cookie Header 771 When the user agent generates an HTTP request for a particular URI, 772 the user agent SHOULD attach exactly one HTTP header named Cookie if 773 the cookie-string (defined below) for that URI is non-empty. 775 A user agent MAY elide the Cookie header in its entirety if the user 776 agent is configured to block sending cookie for a particular request. 777 For example, the user agent might wish to block sending cookies 778 during "third-party" requests. 780 The user agent MUST use the following algorithm to compute the 781 cookie-string from a cookie store and from a URI: 783 1. Let cookie-list be the set of cookies from the cookie store that 784 meet the following requirements: 786 * The cookie's domain field must domain-match the URI's host. 787 [TODO: Spec me] 789 * The cookie's path field must path-match the URI's path. 791 * If the cookie's host-only flag is set, the cookie's domain 792 field must denote exactly the same FQDN as the URI's host. 793 [TODO: Internet Explorer does not implement this requirement 794 but most other major implementations do.] 796 * If the cookie's secure-only field is true, then the URI's 797 scheme must denote a "secure" protocol. 799 NOTE: The notion of an "secure" protocol is not defined by 800 this document. Typically, user agents consider a protocol 801 secure if the protocol makes use of transport-layer 802 security, such as TLS. For example, most user agents 803 consider "https" to be a scheme that denotes a secure 804 protocol. 806 * If the cookie's http-only field is true, then include the 807 cookie unless the cookie-string is begin generated for a "non- 808 HTTP" API. (Note that this document does not define which 809 APIs are "non-HTTP".) 811 NOTE: The Cookie header will not contain any expired cookies 812 because cookies past their expiry date are removed from the 813 cookie store immediately. 815 2. Sort the cookie-list in the following order: 817 * Cookies with longer path fields are listed before cookies with 818 shorter path field. 820 * Among cookies that have equal length path fields, cookies with 821 earlier creation dates are listed before cookies with later 822 creation dates. 824 3. Update the last-access field of each cookie in the cookie-list to 825 the current date. 827 4. Serialize the cookie-list into a cookie-string by processing each 828 cookie in the cookie-list in order: 830 1. If the cookie's name field is non-empty, output the cookie's 831 name field followed by the character U+3D ("="). 833 2. Output the cookie's value field. 835 3. If there is an unprocessed cookie in the cookie-list, output 836 the characters U+3B and U+20 ("; ") 838 6. Implementation Considerations 840 6.1. Set-Cookie Content 842 An origin server's content should probably be divided into disjoint 843 application areas, some of which require the use of state 844 information. The application areas can be distinguished by their 845 request URLs. The Set-Cookie header can incorporate information 846 about the application areas by setting the Path attribute for each 847 one. 849 The session information can obviously be clear or encoded text that 850 describes state. However, if it grows too large, it can become 851 unwieldy. Therefore, an implementor might choose for the session 852 information to be a key to a server-side resource. [TODO: Describe 853 briefly how to generate a decent session key.] 855 [TODO: We could recommend that servers encrypt and mac their cookie 856 data.] 858 [TODO: Mention issues that arise from having multiple concurrent 859 sessions.] 861 6.2. Implementation Limits 863 Practical user agent implementations have limits on the number and 864 size of cookies that they can store. General-use user agents SHOULD 865 provide each of the following minimum capabilities: 867 o At least 4096 bytes per cookie (as measured by the size of the 868 characters that comprise the cookie non-terminal in the syntax 869 description of the Set-Cookie header). [TODO: Validate] 871 o At least 50 cookies per domain. [TODO: History lesson] 873 o At least 3000 cookies total. 875 The information in a Set-Cookie response header must be retained in 876 its entirety. If for some reason there is inadequate space to store 877 the cookie, the cookie must be discarded, not truncated. 879 Applications should use as few and as small cookies as possible, and 880 they should cope gracefully with the loss of a cookie. [TODO: Could 881 mention latency issues that arise from having tons of cookies.] 883 7. Security Considerations 885 7.1. Clear Text 887 The information in the Set-Cookie and Cookie headers is transmitted 888 in the clear. Three consequences are: 890 1. Any sensitive information that is conveyed in in the headers is 891 exposed to an eavesdropper. 893 2. A malicious intermediary could alter the headers as they travel 894 in either direction, with unpredictable results. 896 3. A malicious client could alter the Cookie header before 897 transmission, with unpredictable results. 899 These facts imply that information of a personal and/or financial 900 nature should be sent over a secure channel. For less sensitive 901 information, or when the content of the header is a database key, an 902 origin server should be vigilant to prevent a bad Cookie value from 903 causing failures. 905 7.2. Weak Isolation 907 [TODO: Weak isolation by port.] 909 [TODO: Weak isolation by scheme (e.g., ftp, gopher, etc).] 911 7.3. Cookie Spoofing 913 [TODO: Mention integrity issue where a sibling domain can inject 914 cookies.] 916 [TODO: Mention integrity issue where a HTTP can inject cookies into 917 HTTPS.] 919 8. Other, Similar, Proposals 921 [TODO: Describe relation to the Netscape Cookie Spec, RFC 2109, RFC 922 2629, and cookie-v2.] 924 Appendix A. Acknowledgements 926 This document borrows heavily from RFC 2109. [TODO: Figure out the 927 proper way to credit the authors of RFC 2109.] 929 Appendix B. Tabled Items 931 Tabled items: 933 o Public suffix. 935 Author's Address 937 Adam Barth 938 University of California, Berkeley 940 Email: abarth@eecs.berkeley.edu 941 URI: http://www.adambarth.com/