1 Abstract: Both Host Names Are IP Addresses and Their Host Name Strings Match Exactly or
1 Abstract: Both Host Names Are IP Addresses and Their Host Name Strings Match Exactly or
Kristol
Request for Comments: 2109 Bell Laboratories, Lucent Technologies
Category: Standards Track L. Montulli
Netscape Communications
February 1997
Page 1
This document specifies an Internet standards track protocol for the Internet
community, and requests discussion and suggestions for improvements. Please
refer to the current edition of the "Internet Official Protocol Standards" (STD
1) for the standardization state and status of this protocol. Distribution of this
memo is unlimited.
1 ABSTRACT
2 TERMINOLOGY
The terms user agent, client, server, proxy, and origin server have the same
meaning as in the HTTP/1.0 specification.
The terms request-host and request-URI refer to the values the client would
send to the server as, respectively, the host (but not port) and abs_path
portions of the absoluteURI (http_URL) of the HTTP request line. Note that
request-host must be a FQHN.
Page 2
exactly; or
* both host names are FQDN strings and their host name strings match
exactly; or
* A is a FQDN string and has the form NB, where N is a non-empty name
string, B has the form .B', and B' is a FQDN string. (So, x.y.com
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 technique
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.
There are, of course, many different potential contexts and thus many
different potential types of session. The designers' paradigm for sessions
created by the exchange of cookies has these key attributes:
Page 3
4 OUTLINE
We outline 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. Only
origin servers that need to maintain sessions would suffer any significant
impact, and that impact can largely be confined to Common Gateway
Interface (CGI) programs, unless the server provides more sophisticated state
management support. (See Implementation Considerations, below.)
The two state management headers, Set-Cookie and Cookie, have common
syntactic properties involving attribute-value pairs. The following grammar
uses the notation, and tokens DIGIT (decimal digits) and token (informally, a
sequence of non-special, non-white space characters) from the HTTP/1.1
specification [RFC 2068] to describe their syntax.
av-pairs = av-pair *(";" av-pair)
attr = token
value = word
NOTE: The syntax above allows whitespace between the attribute and
the = sign.
4.2.1 General
The origin server initiates a session, if it so desires. (Note that "session" here
does not refer to a persistent network connection but to a logical session
created from HTTP requests and responses. The presence or absence of a
persistent connection should have no effect on the use of cookie-derived
sessions). To initiate a session, the origin server returns an extra response
header to the client, Set- Cookie. (The details follow later.)
A user agent returns a Cookie 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
Page 4
session. It may send back to the client a Set-Cookie response header with the
same or different information, or it may send no Set-Cookie header at all. The
origin server effectively ends a session by sending the client a Set-Cookie
header with Max-Age=0.
Servers may return a Set-Cookie response headers with any response. User
agents should send Cookie request headers, subject to other rules detailed
below, with every request.
cookies = 1#cookie
NAME = attr
VALUE = value
| "Secure"
Informally, the Set-Cookie response header comprises the token Set- Cookie:,
followed by a comma-separated list of one or more cookies. Each cookie
begins with a NAME=VALUE 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
NAME=VALUE 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, the behavior is undefined.
NAME=VALUE
Required. The name of the state information ("cookie") is NAME, and its
value is VALUE. NAMEs that begin with $ are reserved for other uses and
must not be used by applications.
Page 5
The VALUE is opaque to the user agent and may be anything the origin
server chooses to send, possibly in a server-selected printable ASCII
encoding. "Opaque" implies that the content is of interest and relevance only
to the origin server. The content may, in fact, be readable by anyone that
examines the Set-Cookie header.
Comment=comment
Optional. Because cookies can contain private information about a user, the
Cookie attribute allows an origin server to document its intended use of a
cookie. The user can inspect the information to decide whether to initiate or
continue a session with this cookie.
Domain=domain
Optional. The Domain attribute specifies the domain for which the cookie is
valid. An explicitly specified domain must always start with a dot.
Max-Age=delta-seconds
Optional. The Max-Age attribute defines the lifetime of the cookie, in
seconds. The delta-seconds value is a decimal non- negative integer. After
delta-seconds seconds elapse, the client should discard the cookie. A value of
zero means the cookie should be discarded immediately.
Path=path
Optional. The Path attribute specifies the subset of URLs to which this cookie
applies.
Secure
Optional. The Secure attribute (with no value) directs the user agent to use
only (unspecified) secure means to contact the origin server whenever it sends
back this cookie.
The user agent (possibly under the user's control) may determine what level of
security it considers appropriate for "secure" cookies. The Secure attribute
should be considered security advice from the server to the user agent,
indicating that it is in the session's interest to protect the cookie contents.
Version=version
Required. The Version attribute, a decimal integer, identifies to which version
of the state management specification the cookie conforms. For this
specification, Version=1 applies.
Page 6
The origin server should send the following additional HTTP/1.1 response
headers, depending on circumstances:
cache="set-cookie".
control: private.
HTTP/1.1 servers must send Expires: old-date (where old-date is a date long
in the past) on responses containing Set-Cookie response headers unless they
know for certain (by out of band means) that there are no downsteam
HTTP/1.0 proxies. HTTP/1.1 servers may send other Cache-Control
directives that permit caching by HTTP/1.1 proxies in addition to the Expires:
old-date directive; the Cache- Control directive will override the Expires: old-
date for HTTP/1.1 proxies.
Page 7
Max-AgeThe default behavior is to discard the cookie when the user agent
exits.
Path Defaults to the path of the request URL that generated the
right-most /.
Secure If absent, the user agent may send the cookie over an insecure channel.
* The value for the Path attribute is not a prefix of the request-
URI.
* The value for the request-host does not domain-match the Domain
attribute.
* The request-host is a FQDN (not IP address) and has the form HD,
Examples:
Page 8
be accepted.
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.
Privacy considerations dictate that the user have considerable control over
cookie management. The PRIVACY section contains more information.
When it sends a request to an origin server, the user agent sends a Cookie
request header to the origin server if it has cookies that are applicable to the
request, based on
* the request-host;
Page 9
* the request-URI;
NAME = attr
VALUE = value
The value of the cookie-version attribute must be the value from the Version
attribute, if any, of the corresponding Set-Cookie response header. Otherwise
the value for cookie-version is 0. The value for the path attribute must be the
value from the Path attribute, if any, of the corresponding Set-Cookie
response header. Otherwise the attribute should be omitted from the Cookie
request header. The value for the domain attribute must be the value from the
Domain attribute, if any, of the corresponding Set-Cookie response header.
Otherwise the attribute should be omitted from the Cookie request header.
Domain Selection
The origin server's fully-qualified host name must domain-match the Domain
attribute of the cookie.
Path Selection
The Path 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.
Page 10
If multiple cookies satisfy the criteria above, they are ordered in the Cookie
header such that those with more specific Path attributes precede those with
less specific. Ordering with respect to other attributes (e.g., Domain) is
unspecified.
Note: For backward compatibility, the separator in the Cookie header is semi-
colon (;) everywhere. A server should also accept comma (,) as the separator
between cookie-values for future compatibility.
Users must have control over sessions in order to ensure privacy. (See
PRIVACY 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 verifiable if the user has the option to review
the request-URI prior to its use in the transaction. A transaction is
unverifiable 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 origin transaction, the transaction that the user initiates, is
verifiable, and that transaction may directly or indirectly induce the user agent
to make unverifiable transactions.
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".
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
Page 11
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.
A user agent returns much of the information in the Set-Cookie header to the
origin server when the Path attribute matches that of a new request. When it
receives a Cookie header, the origin server should treat cookies with NAMEs
whose prefix is $ specially, as an attribute for the adjacent cookie. The value
for such a NAME is to be interpreted as applying to the lexically (left-to-
right) most recent cookie whose name does not have the $ prefix. If there is
no previous cookie, the value applies to the cookie mechanism as a whole.
For example, consider the cookie
$Version applies to the cookie mechanism as a whole (and gives the version
number for the cookie mechanism). $Path is an attribute whose value (/acme)
defines the Path attribute that was used when the Customer cookie was
defined in a Set-Cookie response header.
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:
rules.
* Pass along a Cookie request header in any request that the proxy
header.
Page 12
* Cache the received response subject to the control of the usual
control: private,
5 EXAMPLES
5.1 Example 1
Most detail of request and response headers has been omitted. Assume the
user agent has no stored cookies.
HTTP/1.1 200 OK
Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
HTTP/1.1 200 OK
Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";
Path="/acme"
Shopping basket contains an item.
Page 13
HTTP/1.1 200 OK
Set-Cookie: Shipping="FedEx"; Version="1"; Path="/acme"
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 Path attribute
and (default) domain. Because the request URLs all have /acme as a prefix,
and that matches the Path attribute, each request contains all the cookies
received so far.
5.2 Example 2
This example illustrates the effect of the Path 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
Page 14
and
A subsequent request by the user agent to the (same) server for URLs of the
form /acme/ammo/... 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 Path
attribute, /acme/ammo, comes before the one with the less specific Path
attribute, /acme. 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 /acme/parts/ would include the following request header:
Here, the second cookie's Path attribute /acme/ammo is not a prefix of the
request URL, /acme/parts/, so the cookie does not get forwarded to the server.
6 IMPLEMENTATION CONSIDERATIONS
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
Page 15
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 fixed limits. They should strive to store as many frequently-used
cookies as possible. Furthermore, general-use user agents should provide each
of the following minimum capabilities individually, although not necessarily
simultaneously:
* at least 300 cookies
* at least 4096 bytes per cookie (as measured by the size of the
Applications should use as few and as small cookies as possible, and they
should cope gracefully with the loss of a cookie.
Page 16
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
An origin server could create a Set-Cookie 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
* to completely disable the sending and saving of cookies.
Domain attribute.
progress.
Page 17
an origin server. (The user agent would then behave like one that is unaware
of how to handle Set-Cookie 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.
NOTE: 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 messed up.
The restrictions on the value of the Domain 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, or a closely related
set of hosts. Therefore a request-host is limited as to what values it can set for
Domain. We consider it acceptable for hosts host1.foo.com and host2.foo.com
to share cookies, but not a.com and b.com.
Similarly, a server can only set a Path for cookies that are related to the
request-URI.
8 SECURITY CONSIDERATIONS
Page 18
8.2 Cookie Spoofing
Proper application design can avoid spoofing attacks from related domains.
Consider:
Cookie: $Version="1";
session_id="1234";
session_id="1111"; $Domain=".cracker.edu"
The server at victim.cracker.edu should detect that the second cookie was not
one it originated by noticing that the Domain attribute is not for itself and
ignore it.
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 a.com in a URI for a CGI on host b.com.
User agent implementors are strongly encouraged to prevent this sort of
exchange whenever possible.
Three other proposals have been made to accomplish similar goals. This
specification is an amalgam of Kristol's State-Info proposal and Netscape's
Cookie proposal.
Page 19
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
HTTP/1.0 clients and servers may use Set-Cookie and Cookie headers that
reflect Netscape's original cookie proposal. These notes cover inter-operation
between "old" and "new" cookies.
An "old" server that receives a "new" cookie will see what it thinks are many
cookies with names that begin with a $, and it will ignore them. (The "old"
server expects these cookies to be separated by semi-colon, not comma.) A
"new" server can detect cookies that have passed through an "old" client,
because they lack a $Version attribute.
Netscape's original proposal defined an Expires header that took a date value
in a fixed-length variant format in place of Max-Age:
Note that the Expires date format contains embedded spaces, and that "old"
cookies did not have quotes around values. Clients that implement to this
specification should be aware of "old" cookies and Expires.
Page 20
10.1.3 Punctuation
11 ACKNOWLEDGEMENTS
This document really represents the collective efforts of the following people,
in addition to the authors: Roy Fielding, Marc Hedlund, Ted Hardie, Koen
Holtman, Shel Kaphan, Rohit Khare.
Page 21
12 AUTHORS' ADDRESSES
David M. Kristol
Bell Laboratories, Lucent Technologies
600 Mountain Ave. Room 2A-227
Murray Hill, NJ 07974
Lou Montulli
Netscape Communications Corp.
501 E. Middlefield Rd.
Mountain View, CA 94043