idnits 2.17.1 draft-abarth-cookie-05.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 194: '...tokens. Servers MUST NOT include two ...' RFC 2119 keyword, line 198: '...the user agent and MAY be anything the...' RFC 2119 keyword, line 266: '... Syntax Servers MUST NOT include a va...' RFC 2119 keyword, line 268: '... 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 (November 25, 2009) is 5265 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 466 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 29, 2010 November 25, 2009 6 HTTP State Management Mechanism 7 draft-abarth-cookie-05 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 29, 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 . . . . . . . . . . . . . . . . . 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 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 [TODO: Consider replacing this grammar with the one from 2009-11-07- 180 Yui-Naruse.txt.] 182 set-cookie-header = "Set-Cookie:" name-value-pairs 183 name-value-pairs = name-value-pair *(";" name-value-pair) 184 name-value-pair = name ["=" value] ; optional value 185 name = token 186 value = *CHAR 188 The valid character for the value production vary depending on the 189 attribute name. 191 [TODO: Investigate what token actually means.] 193 Attributes names are case-insensitive. White space is permitted 194 between tokens. Servers MUST NOT include two attributes with the 195 same name. Note that although the above syntax description shows 196 value as optional, some attributes require values. 198 The cookie-value is opaque to the user agent and MAY be anything the 199 origin server chooses to send, possibly in a server-selected 200 printable ASCII encoding. "Opaque" implies that the content is of 201 interest and relevance only to the origin server. The content may, 202 in fact, be readable by anyone who examines the Set-Cookie header. 204 NOTE: The syntax above allows whitespace between the attribute and 205 the U+3D ("=") character. Servers wishing to interoperate with some 206 legacy user agents might wish to elide this extra white space to 207 maximize compatibility. 209 4.1.2. Semantics 211 When the user agent receives a Set-Cookie header, the user agent 212 stores the cookie in its cookie store. When the user agent makes 213 another HTTP request to the origin server, the user agent returns the 214 cookie in the Cookie header. 216 The server can override the default handling of cookies by specifying 217 cookie attributes. User agents ignore unrecognized cookie 218 attributes. 220 4.1.2.1. Max-Age 222 [TODO: Consider removing Max-Age from the server conformance section 223 because it's not supported by IE.] 225 Syntax A sequence of ASCII numerals. 227 Semantics The value of the Max-Age attribute represents the maximum 228 lifetime of the cookie, measured in seconds from the moment the 229 user agent receives the cookie. If the server does not supply an 230 Expires or a Max-Age attribute, the lifetime of the cookie is 231 limited to the current session (as defined by the user agent). 233 4.1.2.2. Expires 235 Syntax An RFC 1123 date [cite]. (Note that user agents use very 236 forgiving date parers; see Section [TODO]). 238 Semantics The value of the Expires attribute represents the maximum 239 lifetime of the cookie, represented as the point in time at which 240 the cookie expires. If the server does not supply an Expires or a 241 Max-Age attribute, the lifetime of the cookie is limited to the 242 current session (as defined by the user agent). 244 4.1.2.3. Domain 246 [TODO: Test Domain.] The Domain attribute specifies the domain for 247 which the cookie is valid. The leading dot isn't required. If there 248 is no Domain attribute, the default is to return the cookie only to 249 the origin server. [TODO: You can only set cookies for related 250 domains.] 252 4.1.2.4. Path 254 Syntax A sequence of characters beginning with a "/" character. 256 Semantics The Path attribute specifies the scope of the cookie 257 within a given FQDN. The user agent will include a cookie in an 258 HTTP request only if the Request-URI's path matches, or is a 259 subdirectory of, the cookie's Path attribute (where the "/" 260 character is interpreted as a directory separator). The default 261 value for the Path attribute is the directory of the Request-URI 262 when the cookie was received. 264 4.1.2.5. Secure 266 Syntax Servers MUST NOT include a value. 268 Semantics The user agent SHOULD protect the confidentiality of 269 cookies with the Secure attribute by not transmitting Secure 270 cookies over an "insecure" channel (where "insecure" is defined by 271 the user agent). 273 4.1.2.6. HttpOnly 275 Syntax Servers MUST NOT include a value. 277 Semantics The user agent SHOULD protect confidentiality of cookies 278 with the HttpOnly attribute by not revealing their contents via 279 "non-HTTP" APIs. (Note that this document does not define which 280 APIs are "non-HTTP".) 282 4.2. Cookie 284 4.2.1. Syntax 286 The user agent returns stored cookies to the origin server in the 287 Cookie header. The Cookie header shares a common syntax with the 288 Set-Cookie header, but the semantics of the header differ 289 dramatically. 291 cookie-header = "Cookie:" name-value-pairs 292 name-value-pairs = name-value-pair *(";" name-value-pair) 293 name-value-pair = name "=" value 294 name = token 295 value = *CHAR 297 NOTE: If the server supplies a Set-Cookie header that does not 298 conform to the grammar in Section [TODO], the user agent might not 299 supply a Cookie header that conforms to the preceding grammar. 301 4.2.2. Semantics 303 Each name-value-pair represents a cookie stored by the user agent. 304 The cookie name is returned in as the name and the cookie value is 305 returned as the value. 307 The meaning of the cookies in the Cookie header is not defined by 308 this document. Servers are expected to imbue these cookies with 309 server-specific semantics. 311 4.3. Controlling Caching 313 [TODO: Should we go into this much detail here? This seems redundant 314 with the HTTP specs.] 316 An origin server must be cognizant of the effect of possible caching 317 of both the returned resource and the Set-Cookie header. Caching 318 "public" documents is desirable. For example, if the origin server 319 wants to use a public document such as a "front door" page as a 320 sentinel to indicate the beginning of a session for which a Set- 321 Cookie response header must be generated, the page should be stored 322 in caches "pre-expired" so that the origin server will see further 323 requests. "Private documents", for example those that contain 324 information strictly private to a session, should not be cached in 325 shared caches. 327 If the cookie is intended for use by a single user, the Set-Cookie 328 header should not be cached. A Set-Cookie header that is intended to 329 be shared by multiple users may be cached. 331 The origin server should send the following additional HTTP/1.1 332 response headers, depending on circumstances: [TODO: Is this good 333 advice?] 335 o To suppress caching of the Set-Cookie header: Cache-control: no- 336 cache="set-cookie". 338 and one of the following: 340 o To suppress caching of a private document in shared caches: Cache- 341 Control: private. 343 o To allow caching of a document and require that it be validated 344 before returning it to the client: Cache-Control: must-revalidate. 346 o To allow caching of a document, but to require that proxy caches 347 (not user agent caches) validate it before returning it to the 348 client: Cache-Control: proxy-revalidate. 350 o To allow caching of a document and request that it be validated 351 before returning it to the client (by "pre-expiring" it): Cache- 352 Control: max-age=0. Not all caches will revalidate the document 353 in every case. 355 HTTP/1.1 servers must send Expires: old-date (where old-date is a 356 date long in the past) on responses containing Set-Cookie response 357 headers unless they know for certain (by out of band means) that 358 there are no downstream HTTP/1.0 proxies. HTTP/1.1 servers may send 359 other Cache-Control directives that permit caching by HTTP/1.1 360 proxies in addition to the Expires: old-date directive; the Cache- 361 Control directive will override the Expires: old-date for HTTP/1.1 362 proxies. 364 5. User Agent Conformance 366 Not all origin servers conform to the behavior specified in the 367 previous section. To ensure interoperability, user agents MUST 368 process cookies in a manner that is "black-box" indistinguishable 369 from the requirements in this section. 371 5.1. Parsing the Set-Cookie Header 373 Let an LWS character be either a U+20 (SPACE) or a U+09 (TAB) 374 character. 376 When a user agent receives an Set-Cookie header in an HTTP response, 377 the user agent *receives a set-cookie-string* consisting of the value 378 of the header. 380 A user agent MUST use the following algorithm to parse set-cookie- 381 strings: 383 1. [TODO: Deal with "," characters. My current thinking is that we 384 don't actually have to do anything special for them.] 386 2. If the header contains a U+3B (";") character: 388 the name-value-pair string is characters up to, but not 389 including, the first U+3B (";"), and the unparsed-cookie- 390 attributes are the remainder of the header (including the U+3B 391 (";") in question). 393 Otherwise: 395 the name-value-pair string is all the character contained in 396 the header, and the unparsed-cookie-attributes is the empty 397 string. 399 3. If the name-value-pair string contains a U+3D ("=") character: 401 the (possibly empty) name string is the characters up to, but 402 not including, the first U+3D ("=") character, and the 403 (possibly empty) value string is the characters after the 404 first U+3D ("=") character. 406 Otherwise: 408 the name string is empty, and the value string is the entire 409 name-value-pair string. 411 4. Remove any leading or trailing space from the name string and the 412 value string. 414 5. The cookie-name is the name string, and the cookie-value is the 415 value string. 417 The user agent MUST use the following algorithm to parse the 418 unparsed-attributes: 420 1. If the unparsed-attributes string is empty, skip the rest of 421 these steps. 423 2. Consume the first character of the unparsed-attributes (which 424 will be a U+3B (";") character). 426 3. If the remaining unparsed-attributes contains a U+3B (";") 427 character: 429 Consume the characters of the unparsed-attributes up to, but 430 not including, the first U+3B (";") character. 432 Otherwise: 434 Consume the remainder of the unparsed-attributes. 436 The characters consumed in this step comprise the attribute- 437 value-pair string. 439 4. If the attribute-value-pair string contains a U+3D ("=") 440 character: 442 the (possibly empty) name string is the characters up to, but 443 not including, the first U+3D ("=") character, and the 444 (possibly empty) value string is the characters after the 445 first U+3D ("=") character . 447 Otherwise: 449 the name string is the entire attribute-value-pair string, and 450 the value string is empty. (Note that this step differs from 451 the analogous step when parsing the name-value-pair string.) 453 5. Remove any leading or trailing space from the name string and the 454 value string. 456 6. If the name is a ASCII case-insensitive match for an entry in the 457 following table, process the value string as instructed. 459 Attribute | Instruction 460 ------------+--------------------- 461 Max-Age | See Section [TODO] 462 Expires | See Section [TODO] 463 Domain | See Section [TODO] 464 Path | See Section [TODO] 465 Secure | See Section [TODO] 466 HttpOnly | See Section [TODO] 468 7. Return to Step 1. 470 [TODO: Can parsing a cookie ever fail? Doesn't look like it! Well, 471 unless you count "Set-Cookie: " as a fail...] 473 When the user agent finishes parsing the set-cookie-string header, 474 the user agent *receives a cookie* from the origin server with name 475 cookie-name, value cookie-value, and attributes cookie-attribute- 476 list. 478 5.1.1. The Max-Age Attribute 480 When the user agent receives a cookie attribute with a name string 481 that case-insensitively matches the string "Max-Age", the user agent 482 MUST process the value string as follows. 484 If the first character of the value string is not a DIGIT or a "-" 485 character, the user agent MUST ignore the attribute. 487 If the remainder of value string contains a non-DIGIT character, the 488 user agent MUST ignore the attribute. 490 Let delta-seconds be the contents of the value string converted to an 491 integer. 493 If delta-seconds is less than or equal to 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. 497 If delta-seconds is strictly greater than 0, then append an attribute 498 named Expires (note the name conversion) to the cookie-attribute-list 499 with a value equal to the current date and time plus delta-seconds 500 seconds. 502 5.1.2. The Expires Attribute 504 Unfortunately, cookie dates are quite complex for historical reasons. 506 When the user agent receives a cookie attribute with a name string 507 that case-insensitively matches the string "Expires", the user agent 508 MUST process the value string as follows. 510 If the attribute lacks a value or the value is the empty string, 511 abort these steps. 513 Using the grammar below, divide the value of the attribute into date- 514 tokens. 516 cookie-date = date-token-list 517 date-token-list = date-token [ delimiter date-token-list ] 518 delimiter = U+09 / U+20 / U+21 / U+22 / U+23 / U+24 / 519 U+25 / U+26 / U+27 / U+28 / U+29 / U+2A / 520 U+2B / U+2C / U+2D / U+2E / U+2F / U+3B / 521 U+3C / U+3D / U+3E / U+3F / U+40 / U+5B / 522 U+5C / U+5D / U+5E / U+5F / U+60 / U+7B / 523 U+7C / U+7D / U+7E 524 date-token = day-of-month / month / year / time / mystery 525 day-of-month = 2DIGIT / DIGIT 526 month = "jan" [ mystery ] / "feb" [ mystery ] / 527 "mar" [ mystery ] / "apr" [ mystery ] / 528 "may" [ mystery ] / "jun" [ mystery ] / 529 "jul" [ mystery ] / "aug" [ mystery ] / 530 "sep" [ mystery ] / "oct" [ mystery ] / 531 "nov" [ mystery ] / "dec" [ mystery ] 532 year = 5DIGIT / 4DIGIT / 3DIGIT / 2DIGIT / DIGIT 533 time = 2DIGIT ":" 2DIGIT ":" 2DIGIT 534 mystery = (anything except a delimiter) 536 Process each data-token sequentially in the order the date-tokens 537 appear in the attribute value: 539 1. If the found-day-of-month flag is not set and the token matches 540 the day-of-month production, set the found-day-of-month flag and 541 set the day-of-month-value to the number denoted by the token. 542 Skip the remaining sub-steps and continue to the next token. 544 2. If the found-month flag is not set and the token matches the 545 month production, set the found-month flag and set the month- 546 value to the month denoted by the token. Skip the remaining sub- 547 steps and continue to the next token. 549 3. If the found-year flag is not set and the token matches the year 550 production, set the found-year flag and set the year-value to the 551 number denoted by the token. Skip the remaining sub-steps and 552 continue to the next token. 554 4. If the found-time flag is not set and the token matches the time 555 production, set the found-time flag and set the hour-value, 556 minute-value, and second-value to the numbers denoted by the 557 digits in the token, respectively. Skip the remaining sub-steps 558 and continue to the next token. 560 Abort these steps if 562 o at least one of the found-day-of-month, found-month, found-year, 563 or found-time flags is not set, 565 o the day-of-month-value is less than 1 or greater than 31, 567 o the year-value is less than 1601 or greater than 30827, 569 o the hour-value is greater than 23, 571 o the minute-value is greater than 59, or 573 o the second-value is greater than 59. 575 If the year-value is greater than 68 and less than 100, increment the 576 year-value by 1900. 578 If the year-value is greater than or equal to 0 and less than 69, 579 increment the year-value by 2000. 581 Let the expiry-time be the date whose day-of-month, month, year, 582 hour, minute, and second (in GMT) are the day-of-month-value, the 583 month-value, the year-value, the hour-value, the minute-value, and 584 the second-value, respectively. 586 If the expiry-time is later than the last date the user agent can 587 represent, the user agent MAY replace the expiry-time with the last 588 representable date. 590 If the expiry-time is earlier than the first date the user agent can 591 represent, the user agent MAY replace the expiry-time with the first 592 representable date. 594 Append an attribute named Expires to the cookie-attribute-list with a 595 value equal to expiry-time. 597 5.1.3. The Domain Attribute 599 When the user agent receives a cookie attribute with a name string 600 that case-insensitively matches the string "Domain", the user agent 601 MUST process the value string as follows: 603 o If the value string is empty, then ignore the attribute. [TODO: 604 Add a test for this with multiple Domain attributes.] 606 o If the first character of the value string is ".", then append an 607 attribute named Domain to the cookie-attribute-list with a value 608 equal to value string excluding the leading "." character. 610 o If the first character of the value string is not ".", then append 611 an attribute named Domain to the cookie-attribute-list with a 612 value equal to value string and mark the attribute as host-only. 614 o [TODO: Deal with domains that have an insufficient number of 615 fields.] 617 o Otherwise, ignore the attribute. 619 5.1.4. The Path Attribute 621 The user agent MUST use the following algorithm to compute the 622 default-path of a cookie: 624 1. Let uri-path be the path portion of the URI from which the user 625 agent received the cookie. [TODO: Define this more precisely.] 627 2. If the first character of the uri-path is not a "/" character, 628 output "/" and skip the remaining steps. 630 3. If the uri-path contains only a single "/" character, output "/" 631 and skip the remaining steps. 633 4. Output the characters of the uri-path from the first character up 634 to, and but not including, the right-most "/". 636 A request-path path-matches a cookie-path if the cookie-path is a 637 prefix of the request-path and at least one of the following 638 conditions hold: 640 o The last character of the cookie-path is "/". 642 o The first character of the request-path that is not included in 643 the cookie-path is a "/" character. 645 When the user agent receives a cookie attribute with a name string 646 that case-insensitively matches the string "Path", the user agent 647 MUST process the value string as follows: 649 o If the value string is empty, then append an attribute named Path 650 to the cookie-attribute-list with a value equal to default-path of 651 the cookie. [TODO: Is this right if there are more than one path 652 attribute?] 654 o If the value string is non-empty and the first character is "/", 655 then append an attribute named Path to the cookie-attribute-list 656 with a value equal to value string. 658 o Otherwise, ignore the attribute. 660 [TODO: Test \ ? ; # $ % etc] 662 5.1.5. The Secure Attribute 664 When the user agent receives a cookie attribute with a name string 665 that case-insensitively matches the string "Secure", the user agent 666 MUST append an attribute named Secure to the cookie-attribute-list 667 with an empty value regardless of the value string. 669 5.1.6. The HttpOnly Attribute 671 When the user agent receives a cookie attribute with a name string 672 that case-insensitively matches the string "HttpOnly", the user agent 673 MUST append an attribute named HttpOnly to the cookie-attribute-list 674 with an empty value regardless of the value string. 676 5.2. Storage Model 678 When the user agent receives a cookie, the user agent SHOULD record 679 the cookie in its cookie store as follows. 681 A user agent MAY ignore received cookies in their entirety if the 682 user agent is configured to block receiving cookie for a particular 683 response. For example, the user agent might wish to block receiving 684 cookies from "third-party" responses. 686 The user agent stores the following fields about each cookie: 688 o name (a sequence of bytes) 690 o value (a sequence of bytes) 691 o expiry (a date) 693 o domain (a cookie-domain) 695 o path (a sequence of bytes) 697 o creation (a date) 699 o last-access (a date) 701 o persistent (a Boolean) 703 o host-only (a Boolean) 705 o secure-only (a Boolean) 707 o http-only (a Boolean) 709 When the user agent receives a cookie, the user agent MUST follow the 710 following algorithm: 712 1. Create a new cookie based on the parsed Set-Cookie header: 714 1. Create a new cookie with the following default field values: 716 + name = the cookie-name 718 + value = the cookie-value 720 + expiry = the latest representable date 722 + domain = the request-host 724 + path = the cookie's default-path 726 + last-access = the date and time the cookie was received 728 + persistent = false 730 + host-only = true 732 + secure-only = false 734 + http-only = false 736 2. Update the default field values according to the cookie- 737 attributes: 739 expiry If the cookie-attributes contains at least one valid 740 Expires attribute, store the expiry-value of the last such 741 attribute in the expiry field. Store the value true in 742 the persistent field. [TODO: Test that this really works 743 when mixing Max-Age and Expires.] 745 domain If the cookie-attributes contains at least one Domain 746 attribute, store the value of the last such attribute in 747 the domain field. Store the value false in the host-only 748 field. [TODO: Reject cookies for unrelated domains.] 749 [TODO: If the URL's host is an IP address, let Domain to 750 be an IP address if it matches the URL's host exactly, but 751 set the host-only flag. ] 753 path If the cookie-attributes contains at least one Path 754 attribute, store the value of the last such attribute in 755 the path field. 757 secure-only If the cookie-attributes contains at least one 758 Secure attribute, store the value true in the secure-only 759 field. 761 http-only If the cookie-attributes contains at least one 762 HttpOnly attribute, store the value true in the http-only 763 field. 765 2. Remove from the cookie store all cookies that have the share the 766 same name, domain, path, and host-only fields as the newly 767 created cookie. [TODO: Validate this list!] [TODO: There's some 768 funny business around http-only here.] 770 3. Insert the newly created cookie into the cookie store. 772 The user agent MUST evict a cookie from the cookie store if A cookie 773 exists in the cookie store with an expiry date in the past. 775 The user agent MAY evict a cookie from the cookie store if the number 776 of cookies sharing a domain field exceeds some predetermined upper 777 bound (such as 50 cookies). [TODO: Explain where 50 comes from.] 779 The user agent MAY evict cookies from the cookie store if the cookie 780 store exceeds some maximum storage bound (such as 3000 cookies). 781 [TODO: Explain where 3000 comes from.] 783 When the user agent evicts cookies from the cookie store, the user 784 agent MUST evict cookies in the following priority order: 786 1. Cookies with an expiry date in the past. 788 2. Cookies that share a domain field more than a predetermined 789 number of other cookies. 791 3. All other cookies. 793 If two cookies have the same removal priority, the user agent MUST 794 evict the cookie with the least recent last-access date first. 796 When "the current session is over", the user agent MUST remove from 797 the cookie store all cookies with the persistent field set to false. 799 NOTE: This document does not define when "the current session is 800 over." Many user agents remove non-persistent cookies when they 801 exit. However, other user agent expire non-persistent cookies 802 using other heuristics. 804 5.3. The Cookie Header 806 When the user agent generates an HTTP request for a particular URI, 807 the user agent SHOULD attach exactly one HTTP header named Cookie if 808 the cookie-string (defined below) for that URI is non-empty. 810 A user agent MAY elide the Cookie header in its entirety if the user 811 agent is configured to block sending cookie for a particular request. 812 For example, the user agent might wish to block sending cookies 813 during "third-party" requests. 815 The user agent MUST use the following algorithm to compute the 816 cookie-string from a cookie store and from a URI: 818 1. Let cookie-list be the set of cookies from the cookie store that 819 meet the following requirements: 821 * The cookie's domain field must domain-match the URI's host. 822 [TODO: Spec me] 824 * The cookie's path field must path-match the URI's path. 826 * If the cookie's host-only flag is set, the cookie's domain 827 field must denote exactly the same FQDN as the URI's host. 828 [TODO: Internet Explorer does not implement this requirement 829 but most other major implementations do.] 831 * If the cookie's secure-only field is true, then the URI's 832 scheme must denote a "secure" protocol. 834 NOTE: The notion of an "secure" protocol is not defined by 835 this document. Typically, user agents consider a protocol 836 secure if the protocol makes use of transport-layer 837 security, such as TLS. For example, most user agents 838 consider "https" to be a scheme that denotes a secure 839 protocol. 841 * If the cookie's http-only field is true, then include the 842 cookie unless the cookie-string is begin generated for a "non- 843 HTTP" API. (Note that this document does not define which 844 APIs are "non-HTTP".) 846 NOTE: The Cookie header will not contain any expired cookies 847 because cookies past their expiry date are removed from the 848 cookie store immediately. 850 2. Sort the cookie-list in the following order: 852 * Cookies with longer path fields are listed before cookies with 853 shorter path field. 855 * Among cookies that have equal length path fields, cookies with 856 earlier creation dates are listed before cookies with later 857 creation dates. 859 3. Update the last-access field of each cookie in the cookie-list to 860 the current date. 862 4. Serialize the cookie-list into a cookie-string by processing each 863 cookie in the cookie-list in order: 865 1. If the cookie's name field is non-empty, output the cookie's 866 name field followed by the character U+3D ("="). 868 2. Output the cookie's value field. 870 3. If there is an unprocessed cookie in the cookie-list, output 871 the characters U+3B and U+20 ("; ") 873 6. Implementation Considerations 875 6.1. Set-Cookie Content 877 An origin server's content should probably be divided into disjoint 878 application areas, some of which require the use of state 879 information. The application areas can be distinguished by their 880 request URLs. The Set-Cookie header can incorporate information 881 about the application areas by setting the Path attribute for each 882 one. 884 The session information can obviously be clear or encoded text that 885 describes state. However, if it grows too large, it can become 886 unwieldy. Therefore, an implementor might choose for the session 887 information to be a key to a server-side resource. [TODO: Describe 888 briefly how to generate a decent session key.] 890 [TODO: We could recommend that servers encrypt and mac their cookie 891 data.] 893 [TODO: Mention issues that arise from having multiple concurrent 894 sessions.] 896 6.2. Implementation Limits 898 Practical user agent implementations have limits on the number and 899 size of cookies that they can store. General-use user agents SHOULD 900 provide each of the following minimum capabilities: 902 o At least 4096 bytes per cookie (as measured by the size of the 903 characters that comprise the cookie non-terminal in the syntax 904 description of the Set-Cookie header). [TODO: Validate] 906 o At least 50 cookies per domain. [TODO: History lesson] 908 o At least 3000 cookies total. 910 The information in a Set-Cookie response header must be retained in 911 its entirety. If for some reason there is inadequate space to store 912 the cookie, the cookie must be discarded, not truncated. 914 Applications should use as few and as small cookies as possible, and 915 they should cope gracefully with the loss of a cookie. [TODO: Could 916 mention latency issues that arise from having tons of cookies.] 918 7. Security Considerations 920 7.1. Clear Text 922 The information in the Set-Cookie and Cookie headers is transmitted 923 in the clear. Three consequences are: 925 1. Any sensitive information that is conveyed in in the headers is 926 exposed to an eavesdropper. 928 2. A malicious intermediary could alter the headers as they travel 929 in either direction, with unpredictable results. 931 3. A malicious client could alter the Cookie header before 932 transmission, with unpredictable results. 934 These facts imply that information of a personal and/or financial 935 nature should be sent over a secure channel. For less sensitive 936 information, or when the content of the header is a database key, an 937 origin server should be vigilant to prevent a bad Cookie value from 938 causing failures. 940 7.2. Weak Isolation 942 [TODO: Weak isolation by port.] 944 [TODO: Weak isolation by scheme (e.g., ftp, gopher, etc).] 946 7.3. Cookie Spoofing 948 [TODO: Mention integrity issue where a sibling domain can inject 949 cookies.] 951 [TODO: Mention integrity issue where a HTTP can inject cookies into 952 HTTPS.] 954 8. Other, Similar, Proposals 956 [TODO: Describe relation to the Netscape Cookie Spec, RFC 2109, RFC 957 2629, and cookie-v2.] 959 Appendix A. Acknowledgements 961 This document borrows heavily from RFC 2109. [TODO: Figure out the 962 proper way to credit the authors of RFC 2109.] 964 Appendix B. Tabled Items 966 Tabled items: 968 o Public suffix. 970 Author's Address 972 Adam Barth 973 University of California, Berkeley 975 Email: abarth@eecs.berkeley.edu 976 URI: http://www.adambarth.com/