| HTTP Working Group David M. Kristol INTERNET DRAFT Bell Laboratories, Lucent Technologies Obsoletes: RFC 2109 Lou Montulli Netscape Communications February 16, 1998 Expires August 16, 1998 HHHHTTTTTTTTPPPP SSSSttttaaaatttteeee MMMMaaaannnnaaaaggggeeeemmmmeeeennnntttt MMMMeeeecccchhhhaaaannnniiiissssmmmm | SSSSttttaaaattttuuuussss ooooffff tttthhhhiiiissss MMMMeeeemmmmoooo This document is an Internet-Draft. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents as Internet- Drafts. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet- Drafts as reference material or to cite them other than as ``work in progress.'' To learn the current status of any Internet-Draft, please check the ``1id-abstracts.txt'' listing contained in the Internet- Drafts Shadow Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe), munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), or ftp.isi.edu (US West Coast). This is authors' draft 3.1. | 1. ABSTRACT This document specifies a way to create a stateful session with HTTP requests and responses. It describes two new headers, CCCCooooooookkkkiiiieeee and SSSSeeeetttt---- CCCCooooooookkkkiiiieeee2222, which carry state information between participating origin servers and user agents. The method described here differs from Netscape's Cookie proposal, but it can interoperate with HTTP/1.0 user agents that use Netscape's method. (See the HHHHIIIISSSSTTTTOOOORRRRIIIICCCCAAAALLLL section.) This document reflects implementation experience with RFC 2109 and obsoletes it. 2. TERMINOLOGY The terms _u_s_e_r _a_g_e_n_t, _c_l_i_e_n_t, _s_e_r_v_e_r, _p_r_o_x_y, and _o_r_i_g_i_n _s_e_r_v_e_r have the same meaning as in the HTTP/1.1 specification [RFC 2068]. _H_o_s_t _n_a_m_e (HN) means either the host domain name (HDN) or the numeric Internet Protocol (IP) address of a host. The fully qualified domain Kristol draft-ietf-http-state-man-mec-08.txt [Page 1] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 name is preferred; use of numeric IP addresses is strongly discouraged. The terms _r_e_q_u_e_s_t-_h_o_s_t and _r_e_q_u_e_s_t-_U_R_I refer to the values the client would send to the server as, respectively, the hhhhoooosssstttt (but not ppppoooorrrrtttt) and aaaabbbbssss____ppppaaaatttthhhh portions of the aaaabbbbssssoooolllluuuutttteeeeUUUURRRRIIII (hhhhttttttttpppp____UUUURRRRLLLL) of the HTTP request line. Note that request-host is a HN. The term _e_f_f_e_c_t_i_v_e _h_o_s_t _n_a_m_e is related to host name. If a host name | contains no dots, the _e_f_f_e_c_t_i_v_e _h_o_s_t _n_a_m_e is that name with the string | ....llllooooccccaaaallll appended to it. Otherwise the effective host name is the same as | the host name. Note that all effective host names contain at least one | dot. | The term _r_e_q_u_e_s_t-_p_o_r_t refers to the ppppoooorrrrtttt portion of the aaaabbbbssssoooolllluuuutttteeeeUUUURRRRIIII (hhhhttttttttpppp____UUUURRRRLLLL) of the HTTP request line. If the aaaabbbbssssoooolllluuuutttteeeeUUUURRRRIIII has no explicit ppppoooorrrrtttt, the request-port is the HTTP default, 80. The _r_e_q_u_e_s_t-_p_o_r_t _o_f _a _c_o_o_k_i_e is the request-port of the request in which a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header was returned to the user agent. Host names can be specified either as an IP address or a HDN string. Sometimes we compare one host name with another. Host A's name _d_o_m_a_i_n- _m_a_t_c_h_e_s host B's if +o their host name strings match exactly; or +o A is a HDN string and has the form NB, where N is a non-empty name string, B has the form .B', and B' is a HDN string. (So, xxxx....yyyy....ccccoooommmm domain-matches ....yyyy....ccccoooommmm but not yyyy....ccccoooommmm.) Note that domain-match is not a commutative operation: aaaa....bbbb....cccc....ccccoooommmm domain-matches ....cccc....ccccoooommmm, but not the reverse. The _r_e_a_c_h R of a host name H is defined as follows: +o If - H is the host domain name of a host; and, - H has the form A.B; and - A has no embedded dots; and - B has at least one embedded dot, or B is the string ``llllooooccccaaaallll''. | then the reach of H is .B. +o Otherwise, the reach of H is H. Because it was used in Netscape's original implementation of state management, we will use the term _c_o_o_k_i_e to refer to the state information that passes between an origin server and user agent, and that gets stored by the user agent. Kristol draft-ietf-http-state-man-mec-08.txt [Page 2] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 3. STATE AND SESSIONS This document describes a way to create stateful sessions with HTTP requests and responses. Currently, HTTP servers respond to each client request without relating that request to previous or subsequent | requests; the state management mechanism allows clients and servers that | wish to exchange state information to place HTTP requests and responses within a larger context, which we term a ``session.'' This context might be used to create, for example, a ``shopping cart,'' in which user | selections can be aggregated before purchase, or a magazine browsing system, in which a user's previous reading affects which offerings are presented. | 4. DESCRIPTION | We describe here a way for an origin server to send state information to the user agent, and for the user agent to return the state information to the origin server. The goal is to have a minimal impact on HTTP and user agents. * 4.1 Syntax: General The two state management headers, SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 and CCCCooooooookkkkiiiieeee, have common syntactic properties involving attribute-value pairs. The following grammar uses the notation, and tokens DDDDIIIIGGGGIIIITTTT (decimal digits), ttttooookkkkeeeennnn (informally, a sequence of non-special, non-white space characters), and hhhhttttttttpppp____UUUURRRRLLLL from the HTTP/1.1 specification [RFC 2068] to describe their syntax. av-pairs = av-pair *(";" av-pair) av-pair = attr ["=" value] ; optional value attr = token value = token | quoted-string | Attributes (names) (attr) are case-insensitive. White space is permitted between tokens. Note that while the above syntax description shows vvvvaaaalllluuuueeee as optional, most attrs require them. NNNNOOOOTTTTEEEE: The syntax above allows whitespace between the attribute and the ==== sign. 4.2 Origin Server Role 4.2.1 General The origin server initiates a session, if it so desires. | To do so, it returns an extra response header to the client, SSSSeeeetttt---- CCCCooooooookkkkiiiieeee2222.... (The details follow later.) A user agent returns a CCCCooooooookkkkiiiieeee request header (see below) to the origin server if it chooses to continue a session. The origin server may ignore it or use it to determine the current state of the session. It Kristol draft-ietf-http-state-man-mec-08.txt [Page 3] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 may send back to the client a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header with the same or different information, or it may send no SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header at all. The origin server effectively ends a session by sending the client a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header with MMMMaaaaxxxx----AAAAggggeeee====0000. Servers may return SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response headers with any response. User agents should send CCCCooooooookkkkiiiieeee request headers, subject to other rules detailed below, with every request. An origin server may include multiple SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 headers in a response. Note that an intervening gateway could fold multiple such headers into a single header. 4444....2222....2222 SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 Syntax The syntax for the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header is set-cookie = "Set-Cookie2:" cookies cookies = 1#cookie cookie = NAME "=" VALUE *(";" set-cookie-av) NAME = attr VALUE = value set-cookie-av = "Comment" "=" value | "CommentURL" "=" <"> http_URL <"> | "Discard" | "Domain" "=" value | "Max-Age" "=" value | "Path" "=" value | "Port" [ "=" <"> portlist <"> ] | | "Secure" | "Version" "=" 1*DIGIT portlist = 1#portnum | portnum = 1*DIGIT | Informally, the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header comprises the token SSSSeeeetttt---- CCCCooooooookkkkiiiieeee2222::::, followed by a comma-separated list of one or more cookies. Each cookie begins with a _N_A_M_E=_V_A_L_U_E pair, followed by zero or more semi-colon-separated attribute-value pairs. The syntax for attribute- value pairs was shown earlier. The specific attributes and the semantics of their values follows. The _N_A_M_E=_V_A_L_U_E attribute-value pair must come first in each cookie. The others, if present, can occur in any order. If an attribute appears more than once in a cookie, only the value associated with the first appearance of the attribute shall be used; subsequent values after the first must be ignored. | The _N_A_M_E of a cookie may be the same as one of the attributes in this | specification. However, because the cookie's _N_A_M_E must come first in a | SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header, the _N_A_M_E and its _V_A_L_U_E cannot be confused | with an attribute-value pair. _N_A_M_E=_V_A_L_U_E RRRReeeeqqqquuuuiiiirrrreeeedddd. _T_h_e _n_a_m_e _o_f _t_h_e _s_t_a_t_e _i_n_f_o_r_m_a_t_i_o_n (``_c_o_o_k_i_e'') _i_s _N_A_M_E, Kristol draft-ietf-http-state-man-mec-08.txt [Page 4] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 _a_n_d _i_t_s _v_a_l_u_e _i_s _V_A_L_U_E. _N_A_M_Es _t_h_a_t _b_e_g_i_n _w_i_t_h $$$$ _a_r_e _r_e_s_e_r_v_e_d _a_n_d _| _m_u_s_t _n_o_t _b_e _u_s_e_d _b_y _a_p_p_l_i_c_a_t_i_o_n_s. _T_h_e _V_A_L_U_E _i_s _o_p_a_q_u_e _t_o _t_h_e _u_s_e_r _a_g_e_n_t _a_n_d _m_a_y _b_e _a_n_y_t_h_i_n_g _t_h_e _o_r_i_g_i_n _s_e_r_v_e_r _c_h_o_o_s_e_s _t_o _s_e_n_d, _p_o_s_s_i_b_l_y _i_n _a _s_e_r_v_e_r-_s_e_l_e_c_t_e_d _p_r_i_n_t_a_b_l_e _A_S_C_I_I _e_n_c_o_d_i_n_g. ``_O_p_a_q_u_e'' _i_m_p_l_i_e_s _t_h_a_t _t_h_e _c_o_n_t_e_n_t _i_s _o_f _i_n_t_e_r_e_s_t _a_n_d _r_e_l_e_v_a_n_c_e _o_n_l_y _t_o _t_h_e _o_r_i_g_i_n _s_e_r_v_e_r. _T_h_e _c_o_n_t_e_n_t _m_a_y, _i_n _f_a_c_t, _b_e _r_e_a_d_a_b_l_e _b_y _a_n_y_o_n_e _t_h_a_t _e_x_a_m_i_n_e_s _t_h_e SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 _h_e_a_d_e_r. _| _C_o_m_m_e_n_t=_v_a_l_u_e OOOOppppttttiiiioooonnnnaaaallll.... BBBBeeeeccccaaaauuuusssseeee ccccooooooookkkkiiiieeeessss ccccaaaannnn bbbbeeee uuuusssseeeedddd ttttoooo ddddeeeerrrriiiivvvveeee oooorrrr ssssttttoooorrrreeee pppprrrriiiivvvvaaaatttteeee iiiinnnnffffoooorrrrmmmmaaaattttiiiioooonnnn aaaabbbboooouuuutttt aaaa uuuusssseeeerrrr,,,, tttthhhheeee vvvvaaaalllluuuueeee ooooffff tttthhhheeee CCCCoooommmmmmmmeeeennnntttt aaaattttttttrrrriiiibbbbuuuutttteeee aaaalllllllloooowwwwssss |||| aaaannnn oooorrrriiiiggggiiiinnnn sssseeeerrrrvvvveeeerrrr ttttoooo ddddooooccccuuuummmmeeeennnntttt hhhhoooowwww iiiitttt iiiinnnntttteeeennnnddddssss ttttoooo uuuusssseeee tttthhhheeee ccccooooooookkkkiiiieeee.... TTTThhhheeee uuuusssseeeerrrr ccccaaaannnn iiiinnnnssssppppeeeecccctttt tttthhhheeee iiiinnnnffffoooorrrrmmmmaaaattttiiiioooonnnn ttttoooo ddddeeeecccciiiiddddeeee wwwwhhhheeeetttthhhheeeerrrr ttttoooo iiiinnnniiiittttiiiiaaaatttteeee oooorrrr ccccoooonnnnttttiiiinnnnuuuueeee aaaa sssseeeessssssssiiiioooonnnn wwwwiiiitttthhhh tttthhhhiiiissss ccccooooooookkkkiiiieeee.... CCCCoooommmmmmmmeeeennnnttttUUUURRRRLLLL====""""_h_t_t_p__U_R_L"""" OOOOppppttttiiiioooonnnnaaaallll.... BBBBeeeeccccaaaauuuusssseeee ccccooooooookkkkiiiieeeessss ccccaaaannnn bbbbeeee uuuusssseeeedddd ttttoooo ddddeeeerrrriiiivvvveeee oooorrrr ssssttttoooorrrreeee pppprrrriiiivvvvaaaatttteeee iiiinnnnffffoooorrrrmmmmaaaattttiiiioooonnnn aaaabbbboooouuuutttt aaaa uuuusssseeeerrrr,,,, tttthhhheeee CCCCoooommmmmmmmeeeennnnttttUUUURRRRLLLL aaaattttttttrrrriiiibbbbuuuutttteeee aaaalllllllloooowwwwssss aaaannnn oooorrrriiiiggggiiiinnnn |||| sssseeeerrrrvvvveeeerrrr ttttoooo ddddooooccccuuuummmmeeeennnntttt hhhhoooowwww iiiitttt iiiinnnntttteeeennnnddddssss ttttoooo uuuusssseeee tttthhhheeee ccccooooooookkkkiiiieeee.... TTTThhhheeee uuuusssseeeerrrr ccccaaaannnn iiiinnnnssssppppeeeecccctttt tttthhhheeee iiiinnnnffffoooorrrrmmmmaaaattttiiiioooonnnn iiiiddddeeeennnnttttiiiiffffiiiieeeedddd bbbbyyyy tttthhhheeee UUUURRRRLLLL ttttoooo ddddeeeecccciiiiddddeeee wwwwhhhheeeetttthhhheeeerrrr ttttoooo iiiinnnniiiittttiiiiaaaatttteeee oooorrrr ccccoooonnnnttttiiiinnnnuuuueeee aaaa sssseeeessssssssiiiioooonnnn wwwwiiiitttthhhh tttthhhhiiiissss ccccooooooookkkkiiiieeee.... DDDDiiiissssccccaaaarrrrdddd OOOOppppttttiiiioooonnnnaaaallll.... TTTThhhheeee DDDDiiiissssccccaaaarrrrdddd aaaattttttttrrrriiiibbbbuuuutttteeee iiiinnnnssssttttrrrruuuuccccttttssss tttthhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt ttttoooo ddddiiiissssccccaaaarrrrdddd tttthhhheeee ccccooooooookkkkiiiieeee uuuunnnnccccoooonnnnddddiiiittttiiiioooonnnnaaaallllllllyyyy wwwwhhhheeeennnn tttthhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt tttteeeerrrrmmmmiiiinnnnaaaatttteeeessss.... |||| DDDDoooommmmaaaaiiiinnnn====vvvvaaaalllluuuueeee OOOOppppttttiiiioooonnnnaaaallll.... TTTThhhheeee vvvvaaaalllluuuueeee ooooffff tttthhhheeee DDDDoooommmmaaaaiiiinnnn aaaattttttttrrrriiiibbbbuuuutttteeee ssssppppeeeecccciiiiffffiiiieeeessss tttthhhheeee ddddoooommmmaaaaiiiinnnn |||| ffffoooorrrr wwwwhhhhiiiicccchhhh tttthhhheeee ccccooooooookkkkiiiieeee iiiissss vvvvaaaalllliiiidddd.... IIIIffff aaaannnn eeeexxxxpppplllliiiicccciiiittttllllyyyy ssssppppeeeecccciiiiffffiiiieeeedddd vvvvaaaalllluuuueeee |||| ddddooooeeeessss nnnnooootttt ssssttttaaaarrrrtttt wwwwiiiitttthhhh aaaa ddddooootttt,,,, tttthhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt ssssuuuupppppppplllliiiieeeessss aaaa lllleeeeaaaaddddiiiinnnngggg ddddooootttt.... |||| MMMMaaaaxxxx----AAAAggggeeee====vvvvaaaalllluuuueeee OOOOppppttttiiiioooonnnnaaaallll.... TTTThhhheeee vvvvaaaalllluuuueeee ooooffff tttthhhheeee MMMMaaaaxxxx----AAAAggggeeee aaaattttttttrrrriiiibbbbuuuutttteeee ddddeeeeffffiiiinnnneeeessss tttthhhheeee lllliiiiffffeeeettttiiiimmmmeeee |||| ooooffff tttthhhheeee ccccooooooookkkkiiiieeee,,,, iiiinnnn sssseeeeccccoooonnnnddddssss.... TTTThhhheeee ddddeeeellllttttaaaa----sssseeeeccccoooonnnnddddssss vvvvaaaalllluuuueeee iiiissss aaaa ddddeeeecccciiiimmmmaaaallll |||| nnnnoooonnnn----nnnneeeeggggaaaattttiiiivvvveeee iiiinnnntttteeeeggggeeeerrrr.... AAAAfffftttteeeerrrr ddddeeeellllttttaaaa----sssseeeeccccoooonnnnddddssss sssseeeeccccoooonnnnddddssss eeeellllaaaappppsssseeee,,,, tttthhhheeee cccclllliiiieeeennnntttt sssshhhhoooouuuulllldddd ddddiiiissssccccaaaarrrrdddd tttthhhheeee ccccooooooookkkkiiiieeee.... AAAA vvvvaaaalllluuuueeee ooooffff zzzzeeeerrrroooo mmmmeeeeaaaannnnssss tttthhhheeee ccccooooooookkkkiiiieeee sssshhhhoooouuuulllldddd bbbbeeee ddddiiiissssccccaaaarrrrddddeeeedddd iiiimmmmmmmmeeeeddddiiiiaaaatttteeeellllyyyy.... |||| PPPPaaaatttthhhh====vvvvaaaalllluuuueeee OOOOppppttttiiiioooonnnnaaaallll.... TTTThhhheeee vvvvaaaalllluuuueeee ooooffff tttthhhheeee PPPPaaaatttthhhh aaaattttttttrrrriiiibbbbuuuutttteeee ssssppppeeeecccciiiiffffiiiieeeessss tttthhhheeee ssssuuuubbbbsssseeeetttt ooooffff |||| UUUURRRRLLLLssss oooonnnn tttthhhheeee oooorrrriiiiggggiiiinnnn sssseeeerrrrvvvveeeerrrr ttttoooo wwwwhhhhiiiicccchhhh tttthhhhiiiissss ccccooooooookkkkiiiieeee aaaapppppppplllliiiieeeessss.... |||| PPPPoooorrrrtttt[[[[====""""ppppoooorrrrttttlllliiiisssstttt""""]]]] OOOOppppttttiiiioooonnnnaaaallll.... TTTThhhheeee PPPPoooorrrrtttt aaaattttttttrrrriiiibbbbuuuutttteeee rrrreeeessssttttrrrriiiiccccttttssss tttthhhheeee ppppoooorrrrtttt ttttoooo wwwwhhhhiiiicccchhhh aaaa ccccooooooookkkkiiiieeee mmmmaaaayyyy bbbbeeee rrrreeeettttuuuurrrrnnnneeeedddd iiiinnnn aaaa CCCCooooooookkkkiiiieeee rrrreeeeqqqquuuueeeesssstttt hhhheeeeaaaaddddeeeerrrr.... NNNNooootttteeee tttthhhhaaaatttt tttthhhheeee ssssyyyynnnnttttaaaaxxxx rrrreeeeqqqquuuuiiiirrrreeeessss qqqquuuuooootttteeeessss aaaarrrroooouuuunnnndddd tttthhhheeee ooooppppttttiiiioooonnnnaaaallll ppppoooorrrrttttlllliiiisssstttt eeeevvvveeeennnn iiiiffff tttthhhheeeerrrreeee iiiissss oooonnnnllllyyyy |||| oooonnnneeee ppppoooorrrrttttnnnnuuuummmm iiiinnnn ppppoooorrrrttttlllliiiisssstttt.... |||| Kristol draft-ietf-http-state-man-mec-08.txt [Page 5] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 SSSSeeeeccccuuuurrrreeee OOOOppppttttiiiioooonnnnaaaallll.... TTTThhhheeee SSSSeeeeccccuuuurrrreeee aaaattttttttrrrriiiibbbbuuuutttteeee ((((wwwwiiiitttthhhh nnnnoooo vvvvaaaalllluuuueeee)))) ddddiiiirrrreeeeccccttttssss tttthhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt ttttoooo uuuusssseeee oooonnnnllllyyyy ((((uuuunnnnssssppppeeeecccciiiiffffiiiieeeedddd)))) sssseeeeccccuuuurrrreeee mmmmeeeeaaaannnnssss ttttoooo ccccoooonnnnttttaaaacccctttt tttthhhheeee oooorrrriiiiggggiiiinnnn sssseeeerrrrvvvveeeerrrr wwwwhhhheeeennnneeeevvvveeeerrrr iiiitttt sssseeeennnnddddssss bbbbaaaacccckkkk tttthhhhiiiissss ccccooooooookkkkiiiieeee,,,, ttttoooo pppprrrrooootttteeeecccctttt tttthhhheeee ccccoooonnnnffffiiiiddddeeeennnnttttiiiiaaaallllllllyyyy aaaannnndddd aaaauuuutttthhhheeeennnnttttiiiicccciiiittttyyyy ooooffff tttthhhheeee iiiinnnnffffoooorrrrmmmmaaaattttiiiioooonnnn iiiinnnn tttthhhheeee ccccooooooookkkkiiiieeee.... TTTThhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt ((((ppppoooossssssssiiiibbbbllllyyyy uuuunnnnddddeeeerrrr tttthhhheeee uuuusssseeeerrrr''''ssss ccccoooonnnnttttrrrroooollll)))) mmmmaaaayyyy ddddeeeetttteeeerrrrmmmmiiiinnnneeee wwwwhhhhaaaatttt lllleeeevvvveeeellll ooooffff sssseeeeccccuuuurrrriiiittttyyyy iiiitttt ccccoooonnnnssssiiiiddddeeeerrrrssss aaaapppppppprrrroooopppprrrriiiiaaaatttteeee ffffoooorrrr ````````sssseeeeccccuuuurrrreeee'''''''' ccccooooooookkkkiiiieeeessss.... TTTThhhheeee SSSSeeeeccccuuuurrrreeee aaaattttttttrrrriiiibbbbuuuutttteeee sssshhhhoooouuuulllldddd bbbbeeee ccccoooonnnnssssiiiiddddeeeerrrreeeedddd sssseeeeccccuuuurrrriiiittttyyyy aaaaddddvvvviiiicccceeee ffffrrrroooommmm tttthhhheeee sssseeeerrrrvvvveeeerrrr ttttoooo tttthhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt,,,, iiiinnnnddddiiiiccccaaaattttiiiinnnngggg tttthhhhaaaatttt iiiitttt iiiissss iiiinnnn tttthhhheeee sssseeeessssssssiiiioooonnnn''''ssss iiiinnnntttteeeerrrreeeesssstttt ttttoooo pppprrrrooootttteeeecccctttt tttthhhheeee ccccooooooookkkkiiiieeee ccccoooonnnntttteeeennnnttttssss.... WWWWhhhheeeennnn iiiitttt sssseeeennnnddddssss aaaa |||| ````````sssseeeeccccuuuurrrreeee'''''''' ccccooooooookkkkiiiieeee bbbbaaaacccckkkk ttttoooo aaaa sssseeeerrrrvvvveeeerrrr,,,, tttthhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt sssshhhhoooouuuulllldddd uuuusssseeee nnnnoooo lllleeeessssssss tttthhhhaaaannnn tttthhhheeee ssssaaaammmmeeee lllleeeevvvveeeellll ooooffff sssseeeeccccuuuurrrriiiittttyyyy aaaassss wwwwaaaassss uuuusssseeeedddd wwwwhhhheeeennnn iiiitttt rrrreeeecccceeeeiiiivvvveeeedddd tttthhhheeee ccccooooooookkkkiiiieeee ffffrrrroooommmm tttthhhheeee sssseeeerrrrvvvveeeerrrr.... |||| VVVVeeeerrrrssssiiiioooonnnn====vvvvaaaalllluuuueeee RRRReeeeqqqquuuuiiiirrrreeeedddd. TTTThhhheeee vvvvaaaalllluuuueeee ooooffff tttthhhheeee VVVVeeeerrrrssssiiiioooonnnn aaaattttttttrrrriiiibbbbuuuutttteeee,,,, aaaa ddddeeeecccciiiimmmmaaaallll iiiinnnntttteeeeggggeeeerrrr,,,, |||| iiiiddddeeeennnnttttiiiiffffiiiieeeessss tttthhhheeee vvvveeeerrrrssssiiiioooonnnn ooooffff tttthhhheeee ssssttttaaaatttteeee mmmmaaaannnnaaaaggggeeeemmmmeeeennnntttt ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnn ttttoooo |||| wwwwhhhhiiiicccchhhh tttthhhheeee ccccooooooookkkkiiiieeee ccccoooonnnnffffoooorrrrmmmmssss.... FFFFoooorrrr tttthhhhiiiissss ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnn,,,, VVVVeeeerrrrssssiiiioooonnnn====1111 aaaapppppppplllliiiieeeessss.... 4444....2222....3333 CCCCoooonnnnttttrrrroooolllllllliiiinnnngggg CCCCaaaacccchhhhiiiinnnngggg An origin server must be cognizant of the effect of possible caching of both the returned resource and the SSSSeeeetttt---- CCCCooooooookkkkiiiieeee2222 header. Caching ``public'' documents is desirable. For example, if the origin server wants to use a public document such as a ``front door'' page as a sentinel to indicate the beginning of a session for which a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header must be generated, the page should be stored in caches ``pre-expired'' so that the origin server will see further requests. ``Private documents,'' for example those that contain information strictly private to a session, should not be cached in shared caches. If the cookie is intended for use by a single user, the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header should not be cached. A SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header that is intended to be shared by multiple users may be cached. The origin server should send the following additional HTTP/1.1 response headers, depending on circumstances: +o To suppress caching of the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header: | Cache-control: no-cache="set-cookie2" | and one of the following: +o To suppress caching of a private document in shared caches: | Cache-control: private | +o To allow caching of a document and _r_e_q_u_i_r_e that it be validated before returning it to the client: | Kristol draft-ietf-http-state-man-mec-08.txt [Page 6] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 Cache-Control: must-revalidate, max-age=0 | +o To allow caching of a document, but to require that proxy caches (not user agent caches) validate it before returning it to the client: | Cache-Control: proxy-revalidate, max-age=0 | +o To allow caching of a document and _r_e_q_u_e_s_t that it be validated before returning it to the client (by ``pre-expiring'' it): | Cache-control: max-age=0 | Not all caches will revalidate the document in every case. HTTP/1.1 servers must send EEEExxxxppppiiiirrrreeeessss:::: _o_l_d-_d_a_t_e (where _o_l_d-_d_a_t_e is a date long in the past) on responses containing SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response headers unless they know for certain (by out of band means) that there are no | HTTP/1.0 proxies in the response chain. HTTP/1.1 servers may send other CCCCaaaacccchhhheeee----CCCCoooonnnnttttrrrroooollll directives that permit caching by HTTP/1.1 proxies in addition to the EEEExxxxppppiiiirrrreeeessss:::: _o_l_d-_d_a_t_e directive; the CCCCaaaacccchhhheeee----CCCCoooonnnnttttrrrroooollll directive will override the EEEExxxxppppiiiirrrreeeessss:::: _o_l_d-_d_a_t_e for HTTP/1.1 proxies. 4.3 User Agent Role 4.3.1 Interpreting Set-Cookie2 The user agent keeps separate track of state information that arrives via SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response headers from each origin server (as distinguished by name or IP address and port). The user agent must ignore attribute-value pairs whose attribute it does not recognize. The user agent applies these defaults for optional attributes that are missing: | Discard TTTThhhheeee ddddeeeeffffaaaauuuulllltttt bbbbeeeehhhhaaaavvvviiiioooorrrr iiiissss ddddiiiiccccttttaaaatttteeeedddd bbbbyyyy tttthhhheeee pppprrrreeeesssseeeennnncccceeee oooorrrr aaaabbbbsssseeeennnncccceeee ooooffff aaaa MMMMaaaaxxxx----AAAAggggeeee aaaattttttttrrrriiiibbbbuuuutttteeee.... DDDDoooommmmaaaaiiiinnnn DDDDeeeeffffaaaauuuullllttttssss ttttoooo tttthhhheeee eeeeffffffffeeeeccccttttiiiivvvveeee rrrreeeeqqqquuuueeeesssstttt----hhhhoooosssstttt.... ((((NNNNooootttteeee tttthhhhaaaatttt bbbbeeeeccccaaaauuuusssseeee |||| tttthhhheeeerrrreeee iiiissss nnnnoooo ddddooootttt aaaatttt tttthhhheeee bbbbeeeeggggiiiinnnnnnnniiiinnnngggg ooooffff eeeeffffffffeeeeccccttttiiiivvvveeee rrrreeeeqqqquuuueeeesssstttt----hhhhoooosssstttt,,,, tttthhhheeee |||| ddddeeeeffffaaaauuuulllltttt DDDDoooommmmaaaaiiiinnnn ccccaaaannnn oooonnnnllllyyyy ddddoooommmmaaaaiiiinnnn----mmmmaaaattttcccchhhh iiiittttsssseeeellllffff....)))) MMMMaaaaxxxx----AAAAggggeeee TTTThhhheeee ddddeeeeffffaaaauuuulllltttt bbbbeeeehhhhaaaavvvviiiioooorrrr iiiissss ttttoooo ddddiiiissssccccaaaarrrrdddd tttthhhheeee ccccooooooookkkkiiiieeee wwwwhhhheeeennnn tttthhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt eeeexxxxiiiittttssss.... PPPPaaaatttthhhh DDDDeeeeffffaaaauuuullllttttssss ttttoooo tttthhhheeee ppppaaaatttthhhh ooooffff tttthhhheeee rrrreeeeqqqquuuueeeesssstttt UUUURRRRLLLL tttthhhhaaaatttt ggggeeeennnneeeerrrraaaatttteeeedddd tttthhhheeee SSSSeeeetttt---- CCCCooooooookkkkiiiieeee2222 rrrreeeessssppppoooonnnnsssseeee,,,, uuuupppp ttttoooo aaaannnndddd iiiinnnncccclllluuuuddddiiiinnnngggg tttthhhheeee rrrriiiigggghhhhtttt----mmmmoooosssstttt ////.... |||| PPPPoooorrrrtttt TTTThhhheeee ddddeeeeffffaaaauuuulllltttt bbbbeeeehhhhaaaavvvviiiioooorrrr iiiissss tttthhhhaaaatttt aaaa ccccooooooookkkkiiiieeee mmmmaaaayyyy bbbbeeee rrrreeeettttuuuurrrrnnnneeeedddd ttttoooo aaaannnnyyyy rrrreeeeqqqquuuueeeesssstttt----ppppoooorrrrtttt.... SSSSeeeeccccuuuurrrreeee IIIIffff aaaabbbbsssseeeennnntttt,,,, tttthhhheeee uuuusssseeeerrrr aaaaggggeeeennnntttt mmmmaaaayyyy sssseeeennnndddd tttthhhheeee ccccooooooookkkkiiiieeee oooovvvveeeerrrr aaaannnn iiiinnnnsssseeeeccccuuuurrrreeee cccchhhhaaaannnnnnnneeeellll.... Kristol draft-ietf-http-state-man-mec-08.txt [Page 7] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 4444....3333....2222 RRRReeeejjjjeeeeccccttttiiiinnnngggg CCCCooooooookkkkiiiieeeessss To prevent possible security or privacy violations, a user agent rejects a cookie (shall not store its information) if any of the following is true of the attributes explicitly present in the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header: +o The value for the PPPPaaaatttthhhh attribute is not a prefix of the request- URI. +o The value for the DDDDoooommmmaaaaiiiinnnn attribute contains no embedded dots, and | the value is not ....llllooooccccaaaallll. +o The effective host name that derives from the request-host does not | domain-match the DDDDoooommmmaaaaiiiinnnn attribute. +o The request-host is a HDN (not IP address) and has the form HD, where D is the value of the DDDDoooommmmaaaaiiiinnnn attribute, and H is a string that contains one or more dots. +o The PPPPoooorrrrtttt attribute has a """"ppppoooorrrrtttt----lllliiiisssstttt"""", and the request-port was not in the list. Examples: +o A SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 from request-host yyyy....xxxx....ffffoooooooo....ccccoooommmm for DDDDoooommmmaaaaiiiinnnn====....ffffoooooooo....ccccoooommmm would be rejected, because H is yyyy....xxxx and contains a dot. +o A SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 from request-host xxxx....ffffoooooooo....ccccoooommmm for DDDDoooommmmaaaaiiiinnnn====....ffffoooooooo....ccccoooommmm would be accepted. +o A SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 with DDDDoooommmmaaaaiiiinnnn====....ccccoooommmm or DDDDoooommmmaaaaiiiinnnn====....ccccoooommmm...., will always be rejected, because there is no embedded dot. +o A SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 with DDDDoooommmmaaaaiiiinnnn====aaaajjjjaaaaxxxx....ccccoooommmm will be accepted, and the value for DDDDoooommmmaaaaiiiinnnn will be taken to be ....aaaajjjjaaaaxxxx....ccccoooommmm, because a dot gets prepended to the value. +o A SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 with PPPPoooorrrrtttt====""""88880000,,,,8888000000000000"""" will be accepted if the request was made to port 80 or 8000 and will be rejected otherwise. | +o A SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 from request-host eeeexxxxaaaammmmpppplllleeee for DDDDoooommmmaaaaiiiinnnn====....llllooooccccaaaallll will be | accepted, because the effective host name for the request-host is | eeeexxxxaaaammmmpppplllleeee....llllooooccccaaaallll, and eeeexxxxaaaammmmpppplllleeee....llllooooccccaaaallll domain-matches ....llllooooccccaaaallll. 4.3.3 Cookie Management If a user agent receives a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header whose _N_A_M_E is the same as a pre-existing cookie, and whose DDDDoooommmmaaaaiiiinnnn and PPPPaaaatttthhhh attribute values exactly (string) match those of a pre-existing cookie, the new cookie supersedes the old. However, if the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 has a value for MMMMaaaaxxxx----AAAAggggeeee of zero, the (old and new) cookie is discarded. Otherwise a cookie persists (resources permitting) until whichever happens first, then gets discarded: its MMMMaaaaxxxx----AAAAggggeeee lifetime is exceeded; or, if the DDDDiiiissssccccaaaarrrrdddd attribute is set, the user agent terminates Kristol draft-ietf-http-state-man-mec-08.txt [Page 8] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 the session, Because user agents have finite space in which to store cookies, they may also discard older cookies to make space for newer ones, using, for example, a least-recently-used algorithm, along with constraints on the maximum number of cookies that each origin server may set. If a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header includes a CCCCoooommmmmmmmeeeennnntttt attribute, the user agent should store that information in a human-readable form with the cookie and should display the comment text as part of a cookie inspection user interface. If a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header includes a CCCCoooommmmmmmmeeeennnnttttUUUURRRRLLLL attribute, the user agent should store that information in a human-readable form with the cookie, or, preferably, should allow the user to follow the hhhhttttttttpppp____UUUURRRRLLLL link as part of a cookie inspection user interface. The cookie inspection user interface may include a facility whereby a | user can decide, at the time the user agent receives the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header, whether or not to accept the cookie. A potentially confusing situation could arise if the following sequence occurs: +o the user agent receives a cookie that contains a CommentURL attribute; +o the user agent's cookie inspection interface is configured so that it presents a dialog to the user before the user agent accepts the cookie; +o the dialog allows the user to follow the CommentURL link when the user agent receives the cookie; and, +o when the user follows the CommentURL link, the origin server (or another server, via other links in the returned content) returns another cookie. The user agent should not send any cookies in this context. The user agent may discard any cookie it receives in this context that the user has not, through some user agent mechanism, deemed acceptable. User agents should allow the user to control cookie destruction, but they must not extend the cookie's lifetime beyond that controlled by the DDDDiiiissssccccaaaarrrrdddd and MMMMaaaaxxxx----AAAAggggeeee attributes. An infrequently-used cookie may function as a ``preferences file'' for network applications, and a user may wish to keep it even if it is the least-recently-used cookie. One possible implementation would be an interface that allows the permanent storage of a cookie through a checkbox (or, conversely, its immediate destruction). Privacy considerations dictate that the user have considerable control over cookie management. The PPPPRRRRIIIIVVVVAAAACCCCYYYY section contains more information. Kristol draft-ietf-http-state-man-mec-08.txt [Page 9] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 4.3.4 Sending Cookies to the Origin Server When it sends a request to an origin server, the user agent sends a CCCCooooooookkkkiiiieeee request header to the origin server if it has cookies that are applicable to the request, based on +o the request-host and request-port; +o the request-URI; +o the cookie's age. The syntax for the header is: cookie = "Cookie:" cookie-version 1*((";" | ",") cookie-value) cookie-value = NAME "=" VALUE [";" path] [";" domain] [";" port] cookie-version = "$Version" "=" value NAME = attr VALUE = value path = "$Path" "=" value domain = "$Domain" "=" value port = "$Port" [ "=" <"> value <"> ] The value of the cookie-version attribute must be the value from the VVVVeeeerrrrssssiiiioooonnnn attribute of the corresponding SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header. Otherwise the value for cookie-version is 0000. The value for the path attribute must be the value from the PPPPaaaatttthhhh attribute, if one was present, of the corresponding SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header. Otherwise the attribute should be omitted from the CCCCooooooookkkkiiiieeee request header. The value for the domain attribute must be the value from the DDDDoooommmmaaaaiiiinnnn attribute, if one was present, of the corresponding SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header. Otherwise the attribute should be omitted from the CCCCooooooookkkkiiiieeee request header. The port attribute of the CCCCooooooookkkkiiiieeee request header must mirror the PPPPoooorrrrtttt attribute, if one was present, in the corresponding SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header. That is, the port attribute must be present if the PPPPoooorrrrtttt attribute was present in the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header, and it must have the same value, if any. Otherwise, if the PPPPoooorrrrtttt attribute was absent from the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header, the attribute likewise must be omitted from the CCCCooooooookkkkiiiieeee request header. Note that there is neither a CCCCoooommmmmmmmeeeennnntttt nor a CCCCoooommmmmmmmeeeennnnttttUUUURRRRLLLL attribute in the CCCCooooooookkkkiiiieeee request header corresponding to the ones in the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header. The user agent does not return the comment information to the origin server. The user agent applies the following rules to choose applicable cookie- values to send in CCCCooooooookkkkiiiieeee request headers from among all the cookies it has received. Kristol draft-ietf-http-state-man-mec-08.txt [Page 10] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 Domain Selection The origin server's effective host name must domain-match the | DDDDoooommmmaaaaiiiinnnn attribute of the cookie. Port Selection There are three possible behaviors, depending on the PPPPoooorrrrtttt attribute in the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header: 1. By default (no PPPPoooorrrrtttt attribute), the cookie may be sent to any port. 2. If the attribute is present but has no value (e.g., PPPPoooorrrrtttt), the cookie must only be sent to the request-port it was received from. 3. If the attribute has a ppppoooorrrrtttt----lllliiiisssstttt, the cookie must only be returned if the new request-port is one of those listed in ppppoooorrrrtttt----lllliiiisssstttt. Path Selection The PPPPaaaatttthhhh attribute of the cookie must match a prefix of the request-URI. Max-Age Selection Cookies that have expired should have been discarded and thus are not forwarded to an origin server. If multiple cookies satisfy the criteria above, they are ordered in the CCCCooooooookkkkiiiieeee header such that those with more specific PPPPaaaatttthhhh attributes precede those with less specific. Ordering with respect to other attributes (_e._g., DDDDoooommmmaaaaiiiinnnn) is unspecified. NNNNooootttteeee: For backward compatibility, the separator in the CCCCooooooookkkkiiiieeee header is semi-colon (;;;;) everywhere. A server should also accept comma (,,,,) as the separator between cookie-values for future compatibility. 4.3.5 Sending Cookies in Unverifiable Transactions Users must have control over sessions in order to ensure privacy. (See PPPPRRRRIIIIVVVVAAAACCCCYYYY section below.) To simplify implementation and to prevent an additional layer of complexity where adequate safeguards exist, however, this document distinguishes between transactions that are verifiable and those that are unverifiable. A transaction is _v_e_r_i_f_i_a_b_l_e if the user, or a user- designated agent, has the option to review the request-URI prior to its use in the transaction. A transaction is _u_n_v_e_r_i_f_i_a_b_l_e if the user does not have that option. Unverifiable transactions typically arise when a user agent automatically requests inlined or embedded entities or when it resolves redirection (3xx) responses from an origin server. Typically the _o_r_i_g_i_n _t_r_a_n_s_a_c_t_i_o_n, the transaction that the user initiates, is verifiable, and that transaction may directly or indirectly induce the user agent to make unverifiable transactions. Kristol draft-ietf-http-state-man-mec-08.txt [Page 11] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 An unverifiable transaction is to a _t_h_i_r_d-_p_a_r_t_y _h_o_s_t if its request-host U does not domain-match the reach R of the request-host O in the origin transaction. | When it makes an unverifiable transaction, a user agent must disable all cookie processing (_i._e., must not send cookies, and must not accept any received cookies) if the transaction is to a third-party host. This restriction prevents a malicious service author from using unverifiable transactions to induce a user agent to start or continue a session with a server in a different domain. The starting or continuation of such sessions could be contrary to the privacy expectations of the user, and could also be a security problem. User agents may offer configurable options that allow the user agent, or any autonomous programs that the user agent executes, to ignore the above rule, so long as these override options default to ``off.'' (NNNN....BBBB.... Mechanisms may be proposed that will automate overriding the third-party restrictions under controlled conditions.) Many current user agents already provide a review option that would render many links verifiable. For instance, some user agents display the URL that would be referenced for a particular link when the mouse pointer is placed over that link. The user can therefore determine whether to visit that site before causing the browser to do so. (Though not implemented on current user agents, a similar technique could be used for a button used to submit a form -- the user agent could display the action to be taken if the user were to select that button.) However, even this would not make all links verifiable; for example, links to automatically loaded images would not normally be subject to ``mouse pointer'' verification. Many user agents also provide the option for a user to view the HTML source of a document, or to save the source to an external file where it can be viewed by another application. While such an option does provide a crude review mechanism, some users might not consider it acceptable for this purpose. 4.4 How an Origin Server Interprets the Cookie Header A user agent returns much of the information in the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header to the origin server when the PPPPaaaatttthhhh attribute matches that of a new request. When it receives a CCCCooooooookkkkiiiieeee header, the origin server should treat cookies with _N_A_M_Es whose prefix is $$$$ specially, as an attribute for the cookie. Kristol draft-ietf-http-state-man-mec-08.txt [Page 12] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 4.5 Caching Proxy Role One reason for separating state information from both a URL and document content is to facilitate the scaling that caching permits. To support cookies, a caching proxy must obey these rules already in the HTTP specification: +o Honor requests from the cache, if possible, based on cache validity rules. +o Pass along a CCCCooooooookkkkiiiieeee request header in any request that the proxy must make of another server. +o Return the response to the client. Include any SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header. +o Cache the received response subject to the control of the usual headers, such as EEEExxxxppppiiiirrrreeeessss, | Cache-control: no-cache | and | Cache-control: private | +o Cache the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 subject to the control of the usual header, | Cache-control: no-cache="set-cookie2" | (The SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header should usually not be cached.) Proxies must not introduce SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 (CCCCooooooookkkkiiiieeee) headers of their own in proxy responses (requests). 5. EXAMPLES 5.1 Example 1 Most detail of request and response headers has been omitted. Assume the user agent has no stored cookies. 1. User Agent -> Server POST /acme/login HTTP/1.1 [form data] User identifies self via a form. 2. Server -> User Agent Kristol draft-ietf-http-state-man-mec-08.txt [Page 13] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 HTTP/1.1 200 OK Set-Cookie2: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme" Cookie reflects user's identity. 3. User Agent -> Server POST /acme/pickitem HTTP/1.1 Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme" [form data] User selects an item for ``shopping basket.'' 4. Server -> User Agent HTTP/1.1 200 OK Set-Cookie2: Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme" Shopping basket contains an item. 5. User Agent -> Server POST /acme/shipping HTTP/1.1 Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"; Part_Number="Rocket_Launcher_0001"; $Path="/acme" [form data] User selects shipping method from form. 6. Server -> User Agent HTTP/1.1 200 OK Set-Cookie2: Shipping="FedEx"; Version="1"; Path="/acme" New cookie reflects shipping method. 7. User Agent -> Server POST /acme/process HTTP/1.1 Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"; Part_Number="Rocket_Launcher_0001"; $Path="/acme"; Shipping="FedEx"; $Path="/acme" [form data] User chooses to process order. 8. Server -> User Agent Kristol draft-ietf-http-state-man-mec-08.txt [Page 14] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 HTTP/1.1 200 OK Transaction is complete. The user agent makes a series of requests on the origin server, after each of which it receives a new cookie. All the cookies have the same PPPPaaaatttthhhh attribute and (default) domain. Because the request URLs all have ////aaaaccccmmmmeeee as a prefix, and that matches the PPPPaaaatttthhhh attribute, each request contains all the cookies received so far. 5.2 Example 2 This example illustrates the effect of the PPPPaaaatttthhhh attribute. All detail of request and response headers has been omitted. Assume the user agent has no stored cookies. Imagine the user agent has received, in response to earlier requests, the response headers Set-Cookie2: Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme" and Set-Cookie2: Part_Number="Riding_Rocket_0023"; Version="1"; Path="/acme/ammo" A subsequent request by the user agent to the (same) server for URLs of the form ////aaaaccccmmmmeeee////aaaammmmmmmmoooo////............ would include the following request header: Cookie: $Version="1"; Part_Number="Riding_Rocket_0023"; $Path="/acme/ammo"; Part_Number="Rocket_Launcher_0001"; $Path="/acme" Note that the NAME=VALUE pair for the cookie with the more specific PPPPaaaatttthhhh attribute, ////aaaaccccmmmmeeee////aaaammmmmmmmoooo, comes before the one with the less specific PPPPaaaatttthhhh attribute, ////aaaaccccmmmmeeee. Further note that the same cookie name appears more than once. A subsequent request by the user agent to the (same) server for a URL of the form ////aaaaccccmmmmeeee////ppppaaaarrrrttttssss//// would include the following request header: Cookie: $Version="1"; Part_Number="Rocket_Launcher_0001"; $Path="/acme" Here, the second cookie's PPPPaaaatttthhhh attribute ////aaaaccccmmmmeeee////aaaammmmmmmmoooo is not a prefix of the request URL, ////aaaaccccmmmmeeee////ppppaaaarrrrttttssss////, so the cookie does not get forwarded to the server. Kristol draft-ietf-http-state-man-mec-08.txt [Page 15] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 6. IMPLEMENTATION CONSIDERATIONS Here we speculate on likely or desirable details for an origin server that implements state management. 6.1 Set-Cookie2 Content An origin server's content should probably be divided into disjoint application areas, some of which require the use of state information. The application areas can be distinguished by their request URLs. The SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header can incorporate information about the application areas by setting the PPPPaaaatttthhhh attribute for each one. The session information can obviously be clear or encoded text that describes state. However, if it grows too large, it can become unwieldy. Therefore, an implementor might choose for the session information to be a key to a server-side resource. Of course, using a database creates some problems that this state management specification was meant to avoid, namely: 1. keeping real state on the server side; 2. how and when to garbage-collect the database entry, in case the user agent terminates the session by, for example, exiting. 6.2 Stateless Pages Caching benefits the scalability of WWW. Therefore it is important to reduce the number of documents that have state embedded in them inherently. For example, if a shopping-basket-style application always displays a user's current basket contents on each page, those pages cannot be cached, because each user's basket's contents would be different. On the other hand, if each page contains just a link that allows the user to ``Look at My Shopping Basket,'' the page can be cached. 6.3 Implementation Limits Practical user agent implementations have limits on the number and size of cookies that they can store. In general, user agents' cookie support should have no ffffiiiixxxxeeeedddd limits. They should strive to store as many frequently-used cookies as possible. Furthermore, general-use user agents should provide each of the following mmmmiiiinnnniiiimmmmuuuummmm capabilities individually, although not necessarily simultaneously: +o at least 300 cookies +o at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header) Kristol draft-ietf-http-state-man-mec-08.txt [Page 16] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 +o at least 20 cookies per unique host or domain name User agents created for specific purposes or for limited-capacity devices should provide at least 20 cookies of 4096 bytes, to ensure that the user can interact with a session-based origin server. The information in a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header must be retained in its entirety. If for some reason there is inadequate space to store the cookie, it must be discarded, not truncated. Applications should use as few and as small cookies as possible, and they should cope gracefully with the loss of a cookie. 6.3.1 Denial of Service Attacks User agents may choose to set an upper bound on the number of cookies to be stored from a given host or domain name or on the size of the cookie information. Otherwise a malicious server could attempt to flood a user agent with many cookies, or large cookies, on successive responses, which would force out cookies the user agent had received from other servers. However, the minima specified above should still be supported. 7. PRIVACY _I_n_f_o_r_m_e_d _c_o_n_s_e_n_t should guide the design of systems that use cookies. A | user should be able to find out how a web site plans to use information | in a cookie and should be able to choose whether or not those policies | are acceptable. Both the user agent and the origin server must assist | informed consent. 7.1 User Agent Control An origin server could create a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 header to track the path of a user through the server. Users may object to this behavior as an intrusive accumulation of information, even if their identity is not evident. (Identity might become evident if a user subsequently fills out a form that contains identifying information.) This state management specification therefore requires that a user agent give the user control over such a possible intrusion, although the interface through which the user is given this control is left unspecified. However, the control mechanisms provided shall at least allow the user +o to completely disable the sending and saving of cookies. +o to determine whether a stateful session is in progress. +o to control the saving of a cookie on the basis of the cookie's Domain attribute. Such control could be provided, for example, by mechanisms | Kristol draft-ietf-http-state-man-mec-08.txt [Page 17] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 +o to notify the user when the user agent is about to send a cookie to | the origin server, to offer the option not to begin a session. +o to display a visual indication that a stateful session is in progress. +o to let the user decide which cookies, if any, should be saved when the user concludes a window or user agent session. +o to let the user examine the contents of a cookie at any time. A user agent usually begins execution with no remembered state information. It should be possible to configure a user agent never to send CCCCooooooookkkkiiiieeee headers, in which case it can never sustain state with an origin server. (The user agent would then behave like one that is unaware of how to handle SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response headers.) When the user agent terminates execution, it should let the user discard all state information. Alternatively, the user agent may ask the user whether state information should be retained; the default should be ``no.'' If the user chooses to retain state information, it would be restored the next time the user agent runs. NNNNOOOOTTTTEEEE:::: User agents should probably be cautious about using files to store cookies long-term. If a user runs more than one instance of the user agent, the cookies could be commingled or otherwise corrupted. | 7.2 Origin Server Role | A origin server should promote informed consent by adding CCCCoooommmmmmmmeeeennnnttttUUUURRRRLLLL or | CCCCoooommmmmmmmeeeennnntttt information to the cookies it sends. CCCCoooommmmmmmmeeeennnnttttUUUURRRRLLLL is preferred | because of the opportunity to provide richer information in a | multiplicity of languages. 7.3 Clear Text The information in the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 and CCCCooooooookkkkiiiieeee headers is unprotected. | As a consequence: 1. Any sensitive information that is conveyed in them is exposed to intruders. 2. A malicious intermediary could alter the headers as they travel in either direction, with unpredictable results. These facts imply that information of a personal and/or financial nature should only be sent over a secure channel. For less sensitive information, or when the content of the header is a database key, an origin server should be vigilant to prevent a bad CCCCooooooookkkkiiiieeee value from causing failures. | Kristol draft-ietf-http-state-man-mec-08.txt [Page 18] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 A user agent in a shared user environment poses a further risk. Using a | cookie inspection interface, User B could examine the contents of | cookies that were saved when User A used the machine. | 8. SECURITY CONSIDERATIONS | 8.1 Protocol Design | The restrictions on the value of the DDDDoooommmmaaaaiiiinnnn attribute, and the rules | concerning unverifiable transactions, are meant to reduce the ways that | cookies can ``leak'' to the ``wrong'' site. The intent is to restrict | cookies to one host, or a closely related set of hosts. Therefore a | request-host is limited as to what values it can set for DDDDoooommmmaaaaiiiinnnn. We | consider it acceptable for hosts hhhhoooosssstttt1111....ffffoooooooo....ccccoooommmm and hhhhoooosssstttt2222....ffffoooooooo....ccccoooommmm to | share cookies, but not aaaa....ccccoooommmm and bbbb....ccccoooommmm. | Similarly, a server can set a PPPPaaaatttthhhh only for cookies that are related to | the request-URI. 8.2 Cookie Spoofing Proper application design can avoid spoofing attacks from related domains. Consider: 1. User agent makes request to vvvviiiiccccttttiiiimmmm....ccccrrrraaaacccckkkkeeeerrrr....eeeedddduuuu, gets back cookie sssseeeessssssssiiiioooonnnn____iiiidddd====""""1111222233334444"""" and sets the default domain vvvviiiiccccttttiiiimmmm....ccccrrrraaaacccckkkkeeeerrrr....eeeedddduuuu. 2. User agent makes request to ssssppppooooooooffff....ccccrrrraaaacccckkkkeeeerrrr....eeeedddduuuu, gets back cookie sssseeeessssssssiiiioooonnnn----iiiidddd====""""1111111111111111"""", with DDDDoooommmmaaaaiiiinnnn====""""....ccccrrrraaaacccckkkkeeeerrrr....eeeedddduuuu"""". 3. User agent makes request to vvvviiiiccccttttiiiimmmm....ccccrrrraaaacccckkkkeeeerrrr....eeeedddduuuu again, and passes Cookie: $Version="1"; session_id="1234", $Version="1"; session_id="1111"; $Domain=".cracker.edu" The server at vvvviiiiccccttttiiiimmmm....ccccrrrraaaacccckkkkeeeerrrr....eeeedddduuuu should detect that the second cookie was not one it originated by noticing that the DDDDoooommmmaaaaiiiinnnn attribute is not for itself and ignore it. 8.3 Unexpected Cookie Sharing A user agent should make every attempt to prevent the sharing of session information between hosts that are in different domains. Embedded or inlined objects may cause particularly severe privacy problems if they can be used to share cookies between disparate hosts. For example, a malicious server could embed cookie information for host aaaa....ccccoooommmm in a URI for a CGI on host bbbb....ccccoooommmm. User agent implementors are strongly encouraged to prevent this sort of exchange whenever possible. Kristol draft-ietf-http-state-man-mec-08.txt [Page 19] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 9. OTHER, SIMILAR, PROPOSALS Apart from RFC 2109, three other proposals have been made to accomplish similar goals. This specification began as an amalgam of Kristol's State-Info proposal and Netscape's Cookie proposal. Brian Behlendorf proposed a SSSSeeeessssssssiiiioooonnnn----IIIIDDDD header that would be user-agent- initiated and could be used by an origin server to track ``clicktrails.'' It would not carry any origin-server-defined state, however. Phillip Hallam-Baker has proposed another client-defined session ID mechanism for similar purposes. While both session IDs and cookies can provide a way to sustain stateful sessions, their intended purpose is different, and, consequently, the privacy requirements for them are different. A user initiates session IDs to allow servers to track progress through them, or to distinguish multiple users on a shared machine. Cookies are server-initiated, so the cookie mechanism described here gives users control over something that would otherwise take place without the users' awareness. Furthermore, cookies convey rich, server-selected information, whereas session IDs comprise user-selected, simple information. 10. HISTORICAL 10.1 Compatibility with Existing Implementations Existing cookie implementations, based on the Netscape specification, use the SSSSeeeetttt----CCCCooooooookkkkiiiieeee (not SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222) header. User agents that receive in the same response both a SSSSeeeetttt----CCCCooooooookkkkiiiieeee and SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header for the same cookie must discard the SSSSeeeetttt----CCCCooooooookkkkiiiieeee information and use only the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 information. Furthermore, a user agent must assume, if it received a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header, that the sending server complies with this document and will understand CCCCooooooookkkkiiiieeee request headers that also follow this specification. New cookies must replace both equivalent old- and new-style cookies. That is, if a user agent that follows both this specification and Netscape's original specification receives a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header, and the _N_A_M_E and the DDDDoooommmmaaaaiiiinnnn and PPPPaaaatttthhhh attributes match (per the CCCCooooooookkkkiiiieeee MMMMaaaannnnaaaaggggeeeemmmmeeeennnntttt section) a Netscape-style cookie, the Netscape-style cookie must be discarded, and the user agent must retain only the cookie adhering to this specification. Older user agents that do not understand this specification, but that do understand Netscape's original specification, will not recognize the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header and will receive and send cookies according to the older specification. A user agent that supports both this specification and Netscape-style cookies should send a CCCCooooooookkkkiiiieeee request header that follows the older Kristol draft-ietf-http-state-man-mec-08.txt [Page 20] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 Netscape specification if it received the cookie in a SSSSeeeetttt----CCCCooooooookkkkiiiieeee response header and not in a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header. However, it should send the following request header as well: Cookie2: $Version="1" The CCCCooooooookkkkiiiieeee2222 header advises the server that the user agent understands new-style cookies. If the server understands new-style cookies, as well, it should continue the stateful session by sending a SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 response header, rather than SSSSeeeetttt----CCCCooooooookkkkiiiieeee. A server that does not understand new-style cookies will simply ignore the CCCCooooooookkkkiiiieeee2222 request header. 10.2 Caching and HTTP/1.0 Some caches, such as those conforming to HTTP/1.0, will inevitably cache the SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 and SSSSeeeetttt----CCCCooooooookkkkiiiieeee headers, because there was no mechanism to suppress caching of headers prior to HTTP/1.1. This caching can lead to security problems. Documents transmitted by an origin server along with SSSSeeeetttt----CCCCooooooookkkkiiiieeee2222 and SSSSeeeetttt----CCCCooooooookkkkiiiieeee headers usually either will be uncachable, or will be ``pre-expired.'' As long as caches obey instructions not to cache documents (following EEEExxxxppppiiiirrrreeeessss:::: <_a _d_a_t_e _i_n _t_h_e _p_a_s_t> or PPPPrrrraaaaggggmmmmaaaa:::: nnnnoooo----ccccaaaacccchhhheeee (HTTP/1.0), or CCCCaaaacccchhhheeee----ccccoooonnnnttttrrrroooollll:::: nnnnoooo----ccccaaaacccchhhheeee (HTTP/1.1)) uncachable documents present no problem. However, pre- expired documents may be stored in caches. They require validation (a conditional GET) on each new request, but some cache operators loosen the rules for their caches, and sometimes serve expired documents without first validating them. This combination of factors can lead to cookies meant for one user later being sent to another user. The SSSSeeeetttt---- CCCCooooooookkkkiiiieeee2222 and SSSSeeeetttt----CCCCooooooookkkkiiiieeee headers are stored in the cache, and, although the document is stale (expired), the cache returns the document in response to later requests, including cached headers. 11. ACKNOWLEDGEMENTS This document really represents the collective efforts of the following people, in addition to the authors: Roy Fielding, Yaron Goland, Marc Hedlund, Ted Hardie, Koen Holtman, Shel Kaphan, Rohit Khare, Foteos Macrides, David W. Morris. 12. AUTHORS' ADDRESSES Kristol draft-ietf-http-state-man-mec-08.txt [Page 21] INTERNET DRAFT HTTP State Management Mechanism February 16, 1998 David M. Kristol Bell Laboratories, Lucent Technologies 600 Mountain Ave. Room 2A-333 | Murray Hill, NJ 07974 Phone: (908) 582-2250 FAX: (908) 582-1239 Email: dmk@bell-labs.com Lou Montulli Netscape Communications Corp. 501 E. Middlefield Rd. Mountain View, CA 94043 Phone: (415) 528-2600 Email: montulli@netscape.com Expires August 16, 1998 Kristol draft-ietf-http-state-man-mec-08.txt [Page 22]