Git init
[profile/ivi/libsoup2.4.git] / docs / specs / rfc2109.txt
1
2
3
4
5
6
7 Network Working Group                                         D. Kristol
8 Request for Comments: 2109        Bell Laboratories, Lucent Technologies
9 Category: Standards Track                                    L. Montulli
10                                                  Netscape Communications
11                                                            February 1997
12
13
14                     HTTP State Management Mechanism
15
16 Status of this Memo
17
18    This document specifies an Internet standards track protocol for the
19    Internet community, and requests discussion and suggestions for
20    improvements.  Please refer to the current edition of the "Internet
21    Official Protocol Standards" (STD 1) for the standardization state
22    and status of this protocol.  Distribution of this memo is unlimited.
23
24 1.  ABSTRACT
25
26    This document specifies a way to create a stateful session with HTTP
27    requests and responses.  It describes two new headers, Cookie and
28    Set-Cookie, which carry state information between participating
29    origin servers and user agents.  The method described here differs
30    from Netscape's Cookie proposal, but it can interoperate with
31    HTTP/1.0 user agents that use Netscape's method.  (See the HISTORICAL
32    section.)
33
34 2.  TERMINOLOGY
35
36    The terms user agent, client, server, proxy, and origin server have
37    the same meaning as in the HTTP/1.0 specification.
38
39    Fully-qualified host name (FQHN) means either the fully-qualified
40    domain name (FQDN) of a host (i.e., a completely specified domain
41    name ending in a top-level domain such as .com or .uk), or the
42    numeric Internet Protocol (IP) address of a host.  The fully
43    qualified domain name is preferred; use of numeric IP addresses is
44    strongly discouraged.
45
46    The terms request-host and request-URI refer to the values the client
47    would send to the server as, respectively, the host (but not port)
48    and abs_path portions of the absoluteURI (http_URL) of the HTTP
49    request line.  Note that request-host must be a FQHN.
50
51
52
53
54
55
56
57
58 Kristol & Montulli          Standards Track                     [Page 1]
59 \f
60 RFC 2109            HTTP State Management Mechanism        February 1997
61
62
63    Hosts names can be specified either as an IP address or a FQHN
64    string.  Sometimes we compare one host name with another.  Host A's
65    name domain-matches host B's if
66
67    * both host names are IP addresses and their host name strings match
68      exactly; or
69
70    * both host names are FQDN strings and their host name strings match
71      exactly; or
72
73    * A is a FQDN string and has the form NB, where N is a non-empty name
74      string, B has the form .B', and B' is a FQDN string.  (So, x.y.com
75      domain-matches .y.com but not y.com.)
76
77    Note that domain-match is not a commutative operation: a.b.c.com
78    domain-matches .c.com, but not the reverse.
79
80    Because it was used in Netscape's original implementation of state
81    management, we will use the term cookie to refer to the state
82    information that passes between an origin server and user agent, and
83    that gets stored by the user agent.
84
85 3.  STATE AND SESSIONS
86
87    This document describes a way to create stateful sessions with HTTP
88    requests and responses.  Currently, HTTP servers respond to each
89    client request without relating that request to previous or
90    subsequent requests; the technique allows clients and servers that
91    wish to exchange state information to place HTTP requests and
92    responses within a larger context, which we term a "session".  This
93    context might be used to create, for example, a "shopping cart", in
94    which user selections can be aggregated before purchase, or a
95    magazine browsing system, in which a user's previous reading affects
96    which offerings are presented.
97
98    There are, of course, many different potential contexts and thus many
99    different potential types of session.  The designers' paradigm for
100    sessions created by the exchange of cookies has these key attributes:
101
102       1.  Each session has a beginning and an end.
103
104       2.  Each session is relatively short-lived.
105
106       3.  Either the user agent or the origin server may terminate a
107           session.
108
109       4.  The session is implicit in the exchange of state information.
110
111
112
113
114 Kristol & Montulli          Standards Track                     [Page 2]
115 \f
116 RFC 2109            HTTP State Management Mechanism        February 1997
117
118
119 4.  OUTLINE
120
121    We outline here a way for an origin server to send state information
122    to the user agent, and for the user agent to return the state
123    information to the origin server.  The goal is to have a minimal
124    impact on HTTP and user agents.  Only origin servers that need to
125    maintain sessions would suffer any significant impact, and that
126    impact can largely be confined to Common Gateway Interface (CGI)
127    programs, unless the server provides more sophisticated state
128    management support.  (See Implementation Considerations, below.)
129
130 4.1  Syntax:  General
131
132    The two state management headers, Set-Cookie and Cookie, have common
133    syntactic properties involving attribute-value pairs.  The following
134    grammar uses the notation, and tokens DIGIT (decimal digits) and
135    token (informally, a sequence of non-special, non-white space
136    characters) from the HTTP/1.1 specification [RFC 2068] to describe
137    their syntax.
138
139    av-pairs        =       av-pair *(";" av-pair)
140    av-pair         =       attr ["=" value]        ; optional value
141    attr            =       token
142    value           =       word
143    word            =       token | quoted-string
144
145    Attributes (names) (attr) are case-insensitive.  White space is
146    permitted between tokens.  Note that while the above syntax
147    description shows value as optional, most attrs require them.
148
149    NOTE: The syntax above allows whitespace between the attribute and
150    the = sign.
151
152 4.2  Origin Server Role
153
154 4.2.1  General
155
156    The origin server initiates a session, if it so desires.  (Note that
157    "session" here does not refer to a persistent network connection but
158    to a logical session created from HTTP requests and responses.  The
159    presence or absence of a persistent connection should have no effect
160    on the use of cookie-derived sessions).  To initiate a session, the
161    origin server returns an extra response header to the client, Set-
162    Cookie.  (The details follow later.)
163
164    A user agent returns a Cookie request header (see below) to the
165    origin server if it chooses to continue a session.  The origin server
166    may ignore it or use it to determine the current state of the
167
168
169
170 Kristol & Montulli          Standards Track                     [Page 3]
171 \f
172 RFC 2109            HTTP State Management Mechanism        February 1997
173
174
175    session.  It may send back to the client a Set-Cookie response header
176    with the same or different information, or it may send no Set-Cookie
177    header at all.  The origin server effectively ends a session by
178    sending the client a Set-Cookie header with Max-Age=0.
179
180    Servers may return a Set-Cookie response headers with any response.
181    User agents should send Cookie request headers, subject to other
182    rules detailed below, with every request.
183
184    An origin server may include multiple Set-Cookie headers in a
185    response.  Note that an intervening gateway could fold multiple such
186    headers into a single header.
187
188 4.2.2  Set-Cookie Syntax
189
190    The syntax for the Set-Cookie response header is
191
192    set-cookie      =       "Set-Cookie:" cookies
193    cookies         =       1#cookie
194    cookie          =       NAME "=" VALUE *(";" cookie-av)
195    NAME            =       attr
196    VALUE           =       value
197    cookie-av       =       "Comment" "=" value
198                    |       "Domain" "=" value
199                    |       "Max-Age" "=" value
200                    |       "Path" "=" value
201                    |       "Secure"
202                    |       "Version" "=" 1*DIGIT
203
204    Informally, the Set-Cookie response header comprises the token Set-
205    Cookie:, followed by a comma-separated list of one or more cookies.
206    Each cookie begins with a NAME=VALUE pair, followed by zero or more
207    semi-colon-separated attribute-value pairs.  The syntax for
208    attribute-value pairs was shown earlier.  The specific attributes and
209    the semantics of their values follows.  The NAME=VALUE attribute-
210    value pair must come first in each cookie.  The others, if present,
211    can occur in any order.  If an attribute appears more than once in a
212    cookie, the behavior is undefined.
213
214    NAME=VALUE
215       Required.  The name of the state information ("cookie") is NAME,
216       and its value is VALUE.  NAMEs that begin with $ are reserved for
217       other uses and must not be used by applications.
218
219
220
221
222
223
224
225
226 Kristol & Montulli          Standards Track                     [Page 4]
227 \f
228 RFC 2109            HTTP State Management Mechanism        February 1997
229
230
231       The VALUE is opaque to the user agent and may be anything the
232       origin server chooses to send, possibly in a server-selected
233       printable ASCII encoding.  "Opaque" implies that the content is of
234       interest and relevance only to the origin server.  The content
235       may, in fact, be readable by anyone that examines the Set-Cookie
236       header.
237
238    Comment=comment
239       Optional.  Because cookies can contain private information about a
240       user, the Cookie attribute allows an origin server to document its
241       intended use of a cookie.  The user can inspect the information to
242       decide whether to initiate or continue a session with this cookie.
243
244    Domain=domain
245       Optional.  The Domain attribute specifies the domain for which the
246       cookie is valid.  An explicitly specified domain must always start
247       with a dot.
248
249    Max-Age=delta-seconds
250       Optional.  The Max-Age attribute defines the lifetime of the
251       cookie, in seconds.  The delta-seconds value is a decimal non-
252       negative integer.  After delta-seconds seconds elapse, the client
253       should discard the cookie.  A value of zero means the cookie
254       should be discarded immediately.
255
256    Path=path
257       Optional.  The Path attribute specifies the subset of URLs to
258       which this cookie applies.
259
260    Secure
261       Optional.  The Secure attribute (with no value) directs the user
262       agent to use only (unspecified) secure means to contact the origin
263       server whenever it sends back this cookie.
264
265       The user agent (possibly under the user's control) may determine
266       what level of security it considers appropriate for "secure"
267       cookies.  The Secure attribute should be considered security
268       advice from the server to the user agent, indicating that it is in
269       the session's interest to protect the cookie contents.
270
271    Version=version
272       Required.  The Version attribute, a decimal integer, identifies to
273       which version of the state management specification the cookie
274       conforms.  For this specification, Version=1 applies.
275
276
277
278
279
280
281
282 Kristol & Montulli          Standards Track                     [Page 5]
283 \f
284 RFC 2109            HTTP State Management Mechanism        February 1997
285
286
287 4.2.3  Controlling Caching
288
289    An origin server must be cognizant of the effect of possible caching
290    of both the returned resource and the Set-Cookie header.  Caching
291    "public" documents is desirable.  For example, if the origin server
292    wants to use a public document such as a "front door" page as a
293    sentinel to indicate the beginning of a session for which a Set-
294    Cookie response header must be generated, the page should be stored
295    in caches "pre-expired" so that the origin server will see further
296    requests.  "Private documents", for example those that contain
297    information strictly private to a session, should not be cached in
298    shared caches.
299
300    If the cookie is intended for use by a single user, the Set-cookie
301    header should not be cached.  A Set-cookie header that is intended to
302    be shared by multiple users may be cached.
303
304    The origin server should send the following additional HTTP/1.1
305    response headers, depending on circumstances:
306
307    * To suppress caching of the Set-Cookie header: Cache-control: no-
308      cache="set-cookie".
309
310    and one of the following:
311
312    * To suppress caching of a private document in shared caches: Cache-
313      control: private.
314
315    * To allow caching of a document and require that it be validated
316      before returning it to the client: Cache-control: must-revalidate.
317
318    * To allow caching of a document, but to require that proxy caches
319      (not user agent caches) validate it before returning it to the
320      client: Cache-control: proxy-revalidate.
321
322    * To allow caching of a document and request that it be validated
323      before returning it to the client (by "pre-expiring" it):
324      Cache-control: max-age=0.  Not all caches will revalidate the
325      document in every case.
326
327    HTTP/1.1 servers must send Expires: old-date (where old-date is a
328    date long in the past) on responses containing Set-Cookie response
329    headers unless they know for certain (by out of band means) that
330    there are no downsteam HTTP/1.0 proxies.  HTTP/1.1 servers may send
331    other Cache-Control directives that permit caching by HTTP/1.1
332    proxies in addition to the Expires: old-date directive; the Cache-
333    Control directive will override the Expires: old-date for HTTP/1.1
334    proxies.
335
336
337
338 Kristol & Montulli          Standards Track                     [Page 6]
339 \f
340 RFC 2109            HTTP State Management Mechanism        February 1997
341
342
343 4.3  User Agent Role
344
345 4.3.1  Interpreting Set-Cookie
346
347    The user agent keeps separate track of state information that arrives
348    via Set-Cookie response headers from each origin server (as
349    distinguished by name or IP address and port).  The user agent
350    applies these defaults for optional attributes that are missing:
351
352    VersionDefaults to "old cookie" behavior as originally specified by
353           Netscape.  See the HISTORICAL section.
354
355    Domain Defaults to the request-host.  (Note that there is no dot at
356           the beginning of request-host.)
357
358    Max-AgeThe default behavior is to discard the cookie when the user
359           agent exits.
360
361    Path   Defaults to the path of the request URL that generated the
362           Set-Cookie response, up to, but not including, the
363           right-most /.
364
365    Secure If absent, the user agent may send the cookie over an
366           insecure channel.
367
368 4.3.2  Rejecting Cookies
369
370    To prevent possible security or privacy violations, a user agent
371    rejects a cookie (shall not store its information) if any of the
372    following is true:
373
374    * The value for the Path attribute is not a prefix of the request-
375      URI.
376
377    * The value for the Domain attribute contains no embedded dots or
378      does not start with a dot.
379
380    * The value for the request-host does not domain-match the Domain
381      attribute.
382
383    * The request-host is a FQDN (not IP address) and has the form HD,
384      where D is the value of the Domain attribute, and H is a string
385      that contains one or more dots.
386
387    Examples:
388
389    * A Set-Cookie from request-host y.x.foo.com for Domain=.foo.com
390      would be rejected, because H is y.x and contains a dot.
391
392
393
394 Kristol & Montulli          Standards Track                     [Page 7]
395 \f
396 RFC 2109            HTTP State Management Mechanism        February 1997
397
398
399    * A Set-Cookie from request-host x.foo.com for Domain=.foo.com would
400      be accepted.
401
402    * A Set-Cookie with Domain=.com or Domain=.com., will always be
403      rejected, because there is no embedded dot.
404
405    * A Set-Cookie with Domain=ajax.com will be rejected because the
406      value for Domain does not begin with a dot.
407
408 4.3.3  Cookie Management
409
410    If a user agent receives a Set-Cookie response header whose NAME is
411    the same as a pre-existing cookie, and whose Domain and Path
412    attribute values exactly (string) match those of a pre-existing
413    cookie, the new cookie supersedes the old.  However, if the Set-
414    Cookie has a value for Max-Age of zero, the (old and new) cookie is
415    discarded.  Otherwise cookies accumulate until they expire (resources
416    permitting), at which time they are discarded.
417
418    Because user agents have finite space in which to store cookies, they
419    may also discard older cookies to make space for newer ones, using,
420    for example, a least-recently-used algorithm, along with constraints
421    on the maximum number of cookies that each origin server may set.
422
423    If a Set-Cookie response header includes a Comment attribute, the
424    user agent should store that information in a human-readable form
425    with the cookie and should display the comment text as part of a
426    cookie inspection user interface.
427
428    User agents should allow the user to control cookie destruction.  An
429    infrequently-used cookie may function as a "preferences file" for
430    network applications, and a user may wish to keep it even if it is
431    the least-recently-used cookie.  One possible implementation would be
432    an interface that allows the permanent storage of a cookie through a
433    checkbox (or, conversely, its immediate destruction).
434
435    Privacy considerations dictate that the user have considerable
436    control over cookie management.  The PRIVACY section contains more
437    information.
438
439 4.3.4  Sending Cookies to the Origin Server
440
441    When it sends a request to an origin server, the user agent sends a
442    Cookie request header to the origin server if it has cookies that are
443    applicable to the request, based on
444
445    * the request-host;
446
447
448
449
450 Kristol & Montulli          Standards Track                     [Page 8]
451 \f
452 RFC 2109            HTTP State Management Mechanism        February 1997
453
454
455    * the request-URI;
456
457    * the cookie's age.
458
459    The syntax for the header is:
460
461    cookie          =       "Cookie:" cookie-version
462                            1*((";" | ",") cookie-value)
463    cookie-value    =       NAME "=" VALUE [";" path] [";" domain]
464    cookie-version  =       "$Version" "=" value
465    NAME            =       attr
466    VALUE           =       value
467    path            =       "$Path" "=" value
468    domain          =       "$Domain" "=" value
469
470    The value of the cookie-version attribute must be the value from the
471    Version attribute, if any, of the corresponding Set-Cookie response
472    header.  Otherwise the value for cookie-version is 0.  The value for
473    the path attribute must be the value from the Path attribute, if any,
474    of the corresponding Set-Cookie response header.  Otherwise the
475    attribute should be omitted from the Cookie request header.  The
476    value for the domain attribute must be the value from the Domain
477    attribute, if any, of the corresponding Set-Cookie response header.
478    Otherwise the attribute should be omitted from the Cookie request
479    header.
480
481    Note that there is no Comment attribute in the Cookie request header
482    corresponding to the one in the Set-Cookie response header.  The user
483    agent does not return the comment information to the origin server.
484
485    The following rules apply to choosing applicable cookie-values from
486    among all the cookies the user agent has.
487
488    Domain Selection
489         The origin server's fully-qualified host name must domain-match
490         the Domain attribute of the cookie.
491
492    Path Selection
493         The Path attribute of the cookie must match a prefix of the
494         request-URI.
495
496    Max-Age Selection
497         Cookies that have expired should have been discarded and thus
498         are not forwarded to an origin server.
499
500
501
502
503
504
505
506 Kristol & Montulli          Standards Track                     [Page 9]
507 \f
508 RFC 2109            HTTP State Management Mechanism        February 1997
509
510
511    If multiple cookies satisfy the criteria above, they are ordered in
512    the Cookie header such that those with more specific Path attributes
513    precede those with less specific.  Ordering with respect to other
514    attributes (e.g., Domain) is unspecified.
515
516    Note: For backward compatibility, the separator in the Cookie header
517    is semi-colon (;) everywhere.  A server should also accept comma (,)
518    as the separator between cookie-values for future compatibility.
519
520 4.3.5  Sending Cookies in Unverifiable Transactions
521
522    Users must have control over sessions in order to ensure privacy.
523    (See PRIVACY section below.)  To simplify implementation and to
524    prevent an additional layer of complexity where adequate safeguards
525    exist, however, this document distinguishes between transactions that
526    are verifiable and those that are unverifiable.  A transaction is
527    verifiable if the user has the option to review the request-URI prior
528    to its use in the transaction.  A transaction is unverifiable if the
529    user does not have that option.  Unverifiable transactions typically
530    arise when a user agent automatically requests inlined or embedded
531    entities or when it resolves redirection (3xx) responses from an
532    origin server.  Typically the origin transaction, the transaction
533    that the user initiates, is verifiable, and that transaction may
534    directly or indirectly induce the user agent to make unverifiable
535    transactions.
536
537    When it makes an unverifiable transaction, a user agent must enable a
538    session only if a cookie with a domain attribute D was sent or
539    received in its origin transaction, such that the host name in the
540    Request-URI of the unverifiable transaction domain-matches D.
541
542    This restriction prevents a malicious service author from using
543    unverifiable transactions to induce a user agent to start or continue
544    a session with a server in a different domain.  The starting or
545    continuation of such sessions could be contrary to the privacy
546    expectations of the user, and could also be a security problem.
547
548    User agents may offer configurable options that allow the user agent,
549    or any autonomous programs that the user agent executes, to ignore
550    the above rule, so long as these override options default to "off".
551
552    Many current user agents already provide a review option that would
553    render many links verifiable.  For instance, some user agents display
554    the URL that would be referenced for a particular link when the mouse
555    pointer is placed over that link.  The user can therefore determine
556    whether to visit that site before causing the browser to do so.
557    (Though not implemented on current user agents, a similar technique
558    could be used for a button used to submit a form -- the user agent
559
560
561
562 Kristol & Montulli          Standards Track                    [Page 10]
563 \f
564 RFC 2109            HTTP State Management Mechanism        February 1997
565
566
567    could display the action to be taken if the user were to select that
568    button.) However, even this would not make all links verifiable; for
569    example, links to automatically loaded images would not normally be
570    subject to "mouse pointer" verification.
571
572    Many user agents also provide the option for a user to view the HTML
573    source of a document, or to save the source to an external file where
574    it can be viewed by another application.  While such an option does
575    provide a crude review mechanism, some users might not consider it
576    acceptable for this purpose.
577
578 4.4  How an Origin Server Interprets the Cookie Header
579
580    A user agent returns much of the information in the Set-Cookie header
581    to the origin server when the Path attribute matches that of a new
582    request.  When it receives a Cookie header, the origin server should
583    treat cookies with NAMEs whose prefix is $ specially, as an attribute
584    for the adjacent cookie.  The value for such a NAME is to be
585    interpreted as applying to the lexically (left-to-right) most recent
586    cookie whose name does not have the $ prefix.  If there is no
587    previous cookie, the value applies to the cookie mechanism as a
588    whole.  For example, consider the cookie
589
590    Cookie: $Version="1"; Customer="WILE_E_COYOTE";
591            $Path="/acme"
592
593    $Version applies to the cookie mechanism as a whole (and gives the
594    version number for the cookie mechanism).  $Path is an attribute
595    whose value (/acme) defines the Path attribute that was used when the
596    Customer cookie was defined in a Set-Cookie response header.
597
598 4.5  Caching Proxy Role
599
600    One reason for separating state information from both a URL and
601    document content is to facilitate the scaling that caching permits.
602    To support cookies, a caching proxy must obey these rules already in
603    the HTTP specification:
604
605    * Honor requests from the cache, if possible, based on cache validity
606      rules.
607
608    * Pass along a Cookie request header in any request that the proxy
609      must make of another server.
610
611    * Return the response to the client.  Include any Set-Cookie response
612      header.
613
614
615
616
617
618 Kristol & Montulli          Standards Track                    [Page 11]
619 \f
620 RFC 2109            HTTP State Management Mechanism        February 1997
621
622
623    * Cache the received response subject to the control of the usual
624      headers, such as Expires, Cache-control: no-cache, and Cache-
625      control: private,
626
627    * Cache the Set-Cookie subject to the control of the usual header,
628      Cache-control: no-cache="set-cookie".  (The Set-Cookie header
629      should usually not be cached.)
630
631    Proxies must not introduce Set-Cookie (Cookie) headers of their own
632    in proxy responses (requests).
633
634 5.  EXAMPLES
635
636 5.1  Example 1
637
638    Most detail of request and response headers has been omitted.  Assume
639    the user agent has no stored cookies.
640
641      1.  User Agent -> Server
642
643          POST /acme/login HTTP/1.1
644          [form data]
645
646          User identifies self via a form.
647
648      2.  Server -> User Agent
649
650          HTTP/1.1 200 OK
651          Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
652
653          Cookie reflects user's identity.
654
655      3.  User Agent -> Server
656
657          POST /acme/pickitem HTTP/1.1
658          Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"
659          [form data]
660
661          User selects an item for "shopping basket."
662
663      4.  Server -> User Agent
664
665          HTTP/1.1 200 OK
666          Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";
667                  Path="/acme"
668
669          Shopping basket contains an item.
670
671
672
673
674 Kristol & Montulli          Standards Track                    [Page 12]
675 \f
676 RFC 2109            HTTP State Management Mechanism        February 1997
677
678
679      5.  User Agent -> Server
680
681          POST /acme/shipping HTTP/1.1
682          Cookie: $Version="1";
683                  Customer="WILE_E_COYOTE"; $Path="/acme";
684                  Part_Number="Rocket_Launcher_0001"; $Path="/acme"
685          [form data]
686
687          User selects shipping method from form.
688
689      6.  Server -> User Agent
690
691          HTTP/1.1 200 OK
692          Set-Cookie: Shipping="FedEx"; Version="1"; Path="/acme"
693
694          New cookie reflects shipping method.
695
696      7.  User Agent -> Server
697
698          POST /acme/process HTTP/1.1
699          Cookie: $Version="1";
700                  Customer="WILE_E_COYOTE"; $Path="/acme";
701                  Part_Number="Rocket_Launcher_0001"; $Path="/acme";
702                  Shipping="FedEx"; $Path="/acme"
703          [form data]
704
705          User chooses to process order.
706
707      8.  Server -> User Agent
708
709          HTTP/1.1 200 OK
710
711          Transaction is complete.
712
713    The user agent makes a series of requests on the origin server, after
714    each of which it receives a new cookie.  All the cookies have the
715    same Path attribute and (default) domain.  Because the request URLs
716    all have /acme as a prefix, and that matches the Path attribute, each
717    request contains all the cookies received so far.
718
719 5.2  Example 2
720
721    This example illustrates the effect of the Path attribute.  All
722    detail of request and response headers has been omitted.  Assume the
723    user agent has no stored cookies.
724
725    Imagine the user agent has received, in response to earlier requests,
726    the response headers
727
728
729
730 Kristol & Montulli          Standards Track                    [Page 13]
731 \f
732 RFC 2109            HTTP State Management Mechanism        February 1997
733
734
735    Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";
736            Path="/acme"
737
738    and
739
740    Set-Cookie: Part_Number="Riding_Rocket_0023"; Version="1";
741            Path="/acme/ammo"
742
743    A subsequent request by the user agent to the (same) server for URLs
744    of the form /acme/ammo/...  would include the following request
745    header:
746
747    Cookie: $Version="1";
748            Part_Number="Riding_Rocket_0023"; $Path="/acme/ammo";
749            Part_Number="Rocket_Launcher_0001"; $Path="/acme"
750
751    Note that the NAME=VALUE pair for the cookie with the more specific
752    Path attribute, /acme/ammo, comes before the one with the less
753    specific Path attribute, /acme.  Further note that the same cookie
754    name appears more than once.
755
756    A subsequent request by the user agent to the (same) server for a URL
757    of the form /acme/parts/ would include the following request header:
758
759    Cookie: $Version="1"; Part_Number="Rocket_Launcher_0001"; $Path="/acme"
760
761    Here, the second cookie's Path attribute /acme/ammo is not a prefix
762    of the request URL, /acme/parts/, so the cookie does not get
763    forwarded to the server.
764
765 6.  IMPLEMENTATION CONSIDERATIONS
766
767    Here we speculate on likely or desirable details for an origin server
768    that implements state management.
769
770 6.1  Set-Cookie Content
771
772    An origin server's content should probably be divided into disjoint
773    application areas, some of which require the use of state
774    information.  The application areas can be distinguished by their
775    request URLs.  The Set-Cookie header can incorporate information
776    about the application areas by setting the Path attribute for each
777    one.
778
779    The session information can obviously be clear or encoded text that
780    describes state.  However, if it grows too large, it can become
781    unwieldy.  Therefore, an implementor might choose for the session
782    information to be a key to a server-side resource.  Of course, using
783
784
785
786 Kristol & Montulli          Standards Track                    [Page 14]
787 \f
788 RFC 2109            HTTP State Management Mechanism        February 1997
789
790
791    a database creates some problems that this state management
792    specification was meant to avoid, namely:
793
794      1.  keeping real state on the server side;
795
796      2.  how and when to garbage-collect the database entry, in case the
797          user agent terminates the session by, for example, exiting.
798
799 6.2  Stateless Pages
800
801    Caching benefits the scalability of WWW.  Therefore it is important
802    to reduce the number of documents that have state embedded in them
803    inherently.  For example, if a shopping-basket-style application
804    always displays a user's current basket contents on each page, those
805    pages cannot be cached, because each user's basket's contents would
806    be different.  On the other hand, if each page contains just a link
807    that allows the user to "Look at My Shopping Basket", the page can be
808    cached.
809
810 6.3  Implementation Limits
811
812    Practical user agent implementations have limits on the number and
813    size of cookies that they can store.  In general, user agents' cookie
814    support should have no fixed limits.  They should strive to store as
815    many frequently-used cookies as possible.  Furthermore, general-use
816    user agents should provide each of the following minimum capabilities
817    individually, although not necessarily simultaneously:
818
819       * at least 300 cookies
820
821       * at least 4096 bytes per cookie (as measured by the size of the
822         characters that comprise the cookie non-terminal in the syntax
823         description of the Set-Cookie header)
824
825       * at least 20 cookies per unique host or domain name
826
827    User agents created for specific purposes or for limited-capacity
828    devices should provide at least 20 cookies of 4096 bytes, to ensure
829    that the user can interact with a session-based origin server.
830
831    The information in a Set-Cookie response header must be retained in
832    its entirety.  If for some reason there is inadequate space to store
833    the cookie, it must be discarded, not truncated.
834
835    Applications should use as few and as small cookies as possible, and
836    they should cope gracefully with the loss of a cookie.
837
838
839
840
841
842 Kristol & Montulli          Standards Track                    [Page 15]
843 \f
844 RFC 2109            HTTP State Management Mechanism        February 1997
845
846
847 6.3.1  Denial of Service Attacks
848
849    User agents may choose to set an upper bound on the number of cookies
850    to be stored from a given host or domain name or on the size of the
851    cookie information.  Otherwise a malicious server could attempt to
852    flood a user agent with many cookies, or large cookies, on successive
853    responses, which would force out cookies the user agent had received
854    from other servers.  However, the minima specified above should still
855    be supported.
856
857 7.  PRIVACY
858
859 7.1  User Agent Control
860
861    An origin server could create a Set-Cookie header to track the path
862    of a user through the server.  Users may object to this behavior as
863    an intrusive accumulation of information, even if their identity is
864    not evident.  (Identity might become evident if a user subsequently
865    fills out a form that contains identifying information.)  This state
866    management specification therefore requires that a user agent give
867    the user control over such a possible intrusion, although the
868    interface through which the user is given this control is left
869    unspecified.  However, the control mechanisms provided shall at least
870    allow the user
871
872       * to completely disable the sending and saving of cookies.
873
874       * to determine whether a stateful session is in progress.
875
876       * to control the saving of a cookie on the basis of the cookie's
877         Domain attribute.
878
879    Such control could be provided by, for example, mechanisms
880
881       * to notify the user when the user agent is about to send a cookie
882         to the origin server, offering the option not to begin a session.
883
884       * to display a visual indication that a stateful session is in
885         progress.
886
887       * to let the user decide which cookies, if any, should be saved
888         when the user concludes a window or user agent session.
889
890       * to let the user examine the contents of a cookie at any time.
891
892    A user agent usually begins execution with no remembered state
893    information.  It should be possible to configure a user agent never
894    to send Cookie headers, in which case it can never sustain state with
895
896
897
898 Kristol & Montulli          Standards Track                    [Page 16]
899 \f
900 RFC 2109            HTTP State Management Mechanism        February 1997
901
902
903    an origin server.  (The user agent would then behave like one that is
904    unaware of how to handle Set-Cookie response headers.)
905
906    When the user agent terminates execution, it should let the user
907    discard all state information.  Alternatively, the user agent may ask
908    the user whether state information should be retained; the default
909    should be "no".  If the user chooses to retain state information, it
910    would be restored the next time the user agent runs.
911
912    NOTE: User agents should probably be cautious about using files to
913    store cookies long-term.  If a user runs more than one instance of
914    the user agent, the cookies could be commingled or otherwise messed
915    up.
916
917 7.2  Protocol Design
918
919    The restrictions on the value of the Domain attribute, and the rules
920    concerning unverifiable transactions, are meant to reduce the ways
921    that cookies can "leak" to the "wrong" site.  The intent is to
922    restrict cookies to one, or a closely related set of hosts.
923    Therefore a request-host is limited as to what values it can set for
924    Domain.  We consider it acceptable for hosts host1.foo.com and
925    host2.foo.com to share cookies, but not a.com and b.com.
926
927    Similarly, a server can only set a Path for cookies that are related
928    to the request-URI.
929
930 8.  SECURITY CONSIDERATIONS
931
932 8.1  Clear Text
933
934    The information in the Set-Cookie and Cookie headers is unprotected.
935    Two consequences are:
936
937    1.  Any sensitive information that is conveyed in them is exposed
938        to intruders.
939
940    2.  A malicious intermediary could alter the headers as they travel
941        in either direction, with unpredictable results.
942
943    These facts imply that information of a personal and/or financial
944    nature should only be sent over a secure channel.  For less sensitive
945    information, or when the content of the header is a database key, an
946    origin server should be vigilant to prevent a bad Cookie value from
947    causing failures.
948
949
950
951
952
953
954 Kristol & Montulli          Standards Track                    [Page 17]
955 \f
956 RFC 2109            HTTP State Management Mechanism        February 1997
957
958
959 8.2  Cookie Spoofing
960
961    Proper application design can avoid spoofing attacks from related
962    domains.  Consider:
963
964      1.  User agent makes request to victim.cracker.edu, gets back
965          cookie session_id="1234" and sets the default domain
966          victim.cracker.edu.
967
968      2.  User agent makes request to spoof.cracker.edu, gets back
969          cookie session-id="1111", with Domain=".cracker.edu".
970
971      3.  User agent makes request to victim.cracker.edu again, and
972          passes
973
974          Cookie: $Version="1";
975                          session_id="1234";
976                          session_id="1111"; $Domain=".cracker.edu"
977
978          The server at victim.cracker.edu should detect that the second
979          cookie was not one it originated by noticing that the Domain
980          attribute is not for itself and ignore it.
981
982 8.3  Unexpected Cookie Sharing
983
984    A user agent should make every attempt to prevent the sharing of
985    session information between hosts that are in different domains.
986    Embedded or inlined objects may cause particularly severe privacy
987    problems if they can be used to share cookies between disparate
988    hosts.  For example, a malicious server could embed cookie
989    information for host a.com in a URI for a CGI on host b.com.  User
990    agent implementors are strongly encouraged to prevent this sort of
991    exchange whenever possible.
992
993 9.  OTHER, SIMILAR, PROPOSALS
994
995    Three other proposals have been made to accomplish similar goals.
996    This specification is an amalgam of Kristol's State-Info proposal and
997    Netscape's Cookie proposal.
998
999    Brian Behlendorf proposed a Session-ID header that would be user-
1000    agent-initiated and could be used by an origin server to track
1001    "clicktrails".  It would not carry any origin-server-defined state,
1002    however.  Phillip Hallam-Baker has proposed another client-defined
1003    session ID mechanism for similar purposes.
1004
1005
1006
1007
1008
1009
1010 Kristol & Montulli          Standards Track                    [Page 18]
1011 \f
1012 RFC 2109            HTTP State Management Mechanism        February 1997
1013
1014
1015    While both session IDs and cookies can provide a way to sustain
1016    stateful sessions, their intended purpose is different, and,
1017    consequently, the privacy requirements for them are different.  A
1018    user initiates session IDs to allow servers to track progress through
1019    them, or to distinguish multiple users on a shared machine.  Cookies
1020    are server-initiated, so the cookie mechanism described here gives
1021    users control over something that would otherwise take place without
1022    the users' awareness.  Furthermore, cookies convey rich, server-
1023    selected information, whereas session IDs comprise user-selected,
1024    simple information.
1025
1026 10.  HISTORICAL
1027
1028 10.1  Compatibility With Netscape's Implementation
1029
1030    HTTP/1.0 clients and servers may use Set-Cookie and Cookie headers
1031    that reflect Netscape's original cookie proposal.  These notes cover
1032    inter-operation between "old" and "new" cookies.
1033
1034 10.1.1  Extended Cookie Header
1035
1036    This proposal adds attribute-value pairs to the Cookie request header
1037    in a compatible way.  An "old" client that receives a "new" cookie
1038    will ignore attributes it does not understand; it returns what it
1039    does understand to the origin server.  A "new" client always sends
1040    cookies in the new form.
1041
1042    An "old" server that receives a "new" cookie will see what it thinks
1043    are many cookies with names that begin with a $, and it will ignore
1044    them.  (The "old" server expects these cookies to be separated by
1045    semi-colon, not comma.)  A "new" server can detect cookies that have
1046    passed through an "old" client, because they lack a $Version
1047    attribute.
1048
1049 10.1.2  Expires and Max-Age
1050
1051    Netscape's original proposal defined an Expires header that took a
1052    date value in a fixed-length variant format in place of Max-Age:
1053
1054    Wdy, DD-Mon-YY HH:MM:SS GMT
1055
1056    Note that the Expires date format contains embedded spaces, and that
1057    "old" cookies did not have quotes around values.  Clients that
1058    implement to this specification should be aware of "old" cookies and
1059    Expires.
1060
1061
1062
1063
1064
1065
1066 Kristol & Montulli          Standards Track                    [Page 19]
1067 \f
1068 RFC 2109            HTTP State Management Mechanism        February 1997
1069
1070
1071 10.1.3  Punctuation
1072
1073    In Netscape's original proposal, the values in attribute-value pairs
1074    did not accept "-quoted strings.  Origin servers should be cautious
1075    about sending values that require quotes unless they know the
1076    receiving user agent understands them (i.e., "new" cookies).  A
1077    ("new") user agent should only use quotes around values in Cookie
1078    headers when the cookie's version(s) is (are) all compliant with this
1079    specification or later.
1080
1081    In Netscape's original proposal, no whitespace was permitted around
1082    the = that separates attribute-value pairs.  Therefore such
1083    whitespace should be used with caution in new implementations.
1084
1085 10.2  Caching and HTTP/1.0
1086
1087    Some caches, such as those conforming to HTTP/1.0, will inevitably
1088    cache the Set-Cookie header, because there was no mechanism to
1089    suppress caching of headers prior to HTTP/1.1.  This caching can lead
1090    to security problems.  Documents transmitted by an origin server
1091    along with Set-Cookie headers will usually either be uncachable, or
1092    will be "pre-expired".  As long as caches obey instructions not to
1093    cache documents (following Expires: <a date in the past> or Pragma:
1094    no-cache (HTTP/1.0), or Cache-control: no-cache (HTTP/1.1))
1095    uncachable documents present no problem.  However, pre-expired
1096    documents may be stored in caches.  They require validation (a
1097    conditional GET) on each new request, but some cache operators loosen
1098    the rules for their caches, and sometimes serve expired documents
1099    without first validating them.  This combination of factors can lead
1100    to cookies meant for one user later being sent to another user.  The
1101    Set-Cookie header is stored in the cache, and, although the document
1102    is stale (expired), the cache returns the document in response to
1103    later requests, including cached headers.
1104
1105 11.  ACKNOWLEDGEMENTS
1106
1107    This document really represents the collective efforts of the
1108    following people, in addition to the authors: Roy Fielding, Marc
1109    Hedlund, Ted Hardie, Koen Holtman, Shel Kaphan, Rohit Khare.
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122 Kristol & Montulli          Standards Track                    [Page 20]
1123 \f
1124 RFC 2109            HTTP State Management Mechanism        February 1997
1125
1126
1127 12.  AUTHORS' ADDRESSES
1128
1129    David M. Kristol
1130    Bell Laboratories, Lucent Technologies
1131    600 Mountain Ave.  Room 2A-227
1132    Murray Hill, NJ  07974
1133
1134    Phone: (908) 582-2250
1135    Fax: (908) 582-5809
1136    EMail: dmk@bell-labs.com
1137
1138
1139    Lou Montulli
1140    Netscape Communications Corp.
1141    501 E. Middlefield Rd.
1142    Mountain View, CA  94043
1143
1144    Phone: (415) 528-2600
1145    EMail: montulli@netscape.com
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178 Kristol & Montulli          Standards Track                    [Page 21]
1179 \f