draft-ietf-httpstate-cookie-00.txt   draft-ietf-httpstate-cookie-01.txt 
http-state A. Barth httpstate A. Barth
Internet-Draft U.C. Berkeley Internet-Draft U.C. Berkeley
Expires: June 25, 2010 December 22, 2009 Obsoletes: 2109 (if approved) January 6, 2010
Intended status: Standards Track
Expires: July 10, 2010
HTTP State Management Mechanism HTTP State Management Mechanism
draft-ietf-httpstate-cookie-00 draft-ietf-httpstate-cookie-01
Status of this Memo Status of this Memo
This Internet-Draft is submitted to IETF in full conformance with the This Internet-Draft is submitted to IETF in full conformance with the
provisions of BCP 78 and BCP 79. This document may contain material provisions of BCP 78 and BCP 79. This document may contain material
from IETF Documents or IETF Contributions published or made publicly from IETF Documents or IETF Contributions published or made publicly
available before November 10, 2008. The person(s) controlling the available before November 10, 2008. The person(s) controlling the
copyright in some of this material may not have granted the IETF copyright in some of this material may not have granted the IETF
Trust the right to allow modifications of such material outside the Trust the right to allow modifications of such material outside the
IETF Standards Process. Without obtaining an adequate license from IETF Standards Process. Without obtaining an adequate license from
skipping to change at page 1, line 41 skipping to change at page 1, line 43
and may be updated, replaced, or obsoleted by other documents at any and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress." material or to cite them other than as "work in progress."
The list of current Internet-Drafts can be accessed at The list of current Internet-Drafts can be accessed at
http://www.ietf.org/ietf/1id-abstracts.txt. http://www.ietf.org/ietf/1id-abstracts.txt.
The list of Internet-Draft Shadow Directories can be accessed at The list of Internet-Draft Shadow Directories can be accessed at
http://www.ietf.org/shadow.html. http://www.ietf.org/shadow.html.
This Internet-Draft will expire on June 25, 2010. This Internet-Draft will expire on July 10, 2010.
Copyright Notice Copyright Notice
Copyright (c) 2009 IETF Trust and the persons identified as the Copyright (c) 2010 IETF Trust and the persons identified as the
document authors. All rights reserved. document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents in effect on the date of Provisions Relating to IETF Documents in effect on the date of
publication of this document (http://trustee.ietf.org/license-info). publication of this document (http://trustee.ietf.org/license-info).
Please review these documents carefully, as they describe your rights Please review these documents carefully, as they describe your rights
and restrictions with respect to this document. and restrictions with respect to this document.
Abstract Abstract
This document defines the HTTP Cookie and Set-Cookie headers. This document defines the HTTP Cookie and Set-Cookie headers. These
headers can be used by HTTP servers to store state on HTTP user
agents, letting the servers maintain a stateful session over the
mostly stateless HTTP protocol. The cookie protocol has many
historical infelicities and should be avoided for new applications of
HTTP.
NOTE: If you have suggestions for improving the draft, please send NOTE: If you have suggestions for improving the draft, please send
email to http-state@ietf.org. Suggestions with test cases are email to http-state@ietf.org. Suggestions with test cases are
especially appreciated. especially appreciated.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1. Syntax Notation . . . . . . . . . . . . . . . . . . . . . 4 1.1. Syntax Notation . . . . . . . . . . . . . . . . . . . . . 5
2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 5 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 6
3. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.1. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 7
4. Protocol Description . . . . . . . . . . . . . . . . . . . . . 7 4. A Well-Behaved Profile . . . . . . . . . . . . . . . . . . . . 8
4.1. Set-Cookie . . . . . . . . . . . . . . . . . . . . . . . . 7 4.1. Set-Cookie . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . 7 4.1.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1.2. Semantics . . . . . . . . . . . . . . . . . . . . . . 8 4.1.2. Semantics (Non-Normative) . . . . . . . . . . . . . . 9
4.2. Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.2. Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . 9 4.2.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.2. Semantics . . . . . . . . . . . . . . . . . . . . . . 10 4.2.2. Semantics . . . . . . . . . . . . . . . . . . . . . . 11
4.3. Controlling Caching . . . . . . . . . . . . . . . . . . . 10 5. The Cookie Protocol . . . . . . . . . . . . . . . . . . . . . 12
5. User Agent Conformance . . . . . . . . . . . . . . . . . . . . 12 5.1. Algorithms . . . . . . . . . . . . . . . . . . . . . . . . 12
5.1. Parsing the Set-Cookie Header . . . . . . . . . . . . . . 12 5.1.1. Dates . . . . . . . . . . . . . . . . . . . . . . . . 12
5.1.1. The Max-Age Attribute . . . . . . . . . . . . . . . . 14 5.1.2. Domains . . . . . . . . . . . . . . . . . . . . . . . 14
5.1.2. The Expires Attribute . . . . . . . . . . . . . . . . 14 5.1.3. Paths . . . . . . . . . . . . . . . . . . . . . . . . 14
5.1.3. The Domain Attribute . . . . . . . . . . . . . . . . . 17 5.2. The Set-Cookie Header . . . . . . . . . . . . . . . . . . 15
5.1.4. The Path Attribute . . . . . . . . . . . . . . . . . . 17 5.2.1. The Max-Age Attribute . . . . . . . . . . . . . . . . 17
5.1.5. The Secure Attribute . . . . . . . . . . . . . . . . . 18 5.2.2. The Expires Attribute . . . . . . . . . . . . . . . . 17
5.1.6. The HttpOnly Attribute . . . . . . . . . . . . . . . . 18 5.2.3. The Domain Attribute . . . . . . . . . . . . . . . . . 18
5.2. Storage Model . . . . . . . . . . . . . . . . . . . . . . 18 5.2.4. The Path Attribute . . . . . . . . . . . . . . . . . . 18
5.3. The Cookie Header . . . . . . . . . . . . . . . . . . . . 21 5.2.5. The Secure Attribute . . . . . . . . . . . . . . . . . 19
6. Implementation Considerations . . . . . . . . . . . . . . . . 23 5.2.6. The HttpOnly Attribute . . . . . . . . . . . . . . . . 19
6.1. Set-Cookie Content . . . . . . . . . . . . . . . . . . . . 23 5.3. Storage Model . . . . . . . . . . . . . . . . . . . . . . 19
6.2. Implementation Limits . . . . . . . . . . . . . . . . . . 23 5.4. The Cookie Header . . . . . . . . . . . . . . . . . . . . 21
7. Security Considerations . . . . . . . . . . . . . . . . . . . 24 6. Implementation Limits . . . . . . . . . . . . . . . . . . . . 24
7.1. Clear Text . . . . . . . . . . . . . . . . . . . . . . . . 24 7. Security Considerations . . . . . . . . . . . . . . . . . . . 25
7.2. Weak Isolation . . . . . . . . . . . . . . . . . . . . . . 24 7.1. Clear Text . . . . . . . . . . . . . . . . . . . . . . . . 25
7.3. Cookie Spoofing . . . . . . . . . . . . . . . . . . . . . 24 7.2. Weak Confidentiality . . . . . . . . . . . . . . . . . . . 25
8. Other, Similar, Proposals . . . . . . . . . . . . . . . . . . 25 7.3. Weak Integrity . . . . . . . . . . . . . . . . . . . . . . 25
9. Normative References . . . . . . . . . . . . . . . . . . . . . 26 8. Normative References . . . . . . . . . . . . . . . . . . . . . 27
Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 27 Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 28
Appendix B. Tabled Items . . . . . . . . . . . . . . . . . . . . 28
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 29 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 29
1. Introduction 1. Introduction
This document defines the HTTP Cookie and Set-Cookie header. This document defines the HTTP Cookie and Set-Cookie header. Using
the Set-Cookie header, an HTTP server can store name/value pairs
(called cookies) at the user agent. When the user agent makes
subsequent requests to the server, the user agent will return the
name/value pairs in the Cookie header.
Although simple on its surface, the cookie protocol has a number of
complexities. For example, the server indicates a scope for each
cookie when sending them to the user agent. The scope indicates the
maximum amount of time the user agent should persist the cookie, to
which servers the user agent should return the cookie, and for which
protocols the cookie is applicable.
For historical reasons, the cookie protocol contains a number of
security and privacy infelicities. For example, a server can
indicate that a given cookie is intended for "secure" connections,
but the Secure attribute provides only confidentiality (not
integrity) from active network attackers. Similarly, cookies for a
given host are shared across all the ports on that host, even though
the usual "same-origin policy" used by web browsers isolates content
retrieved from different ports.
1.1. Syntax Notation 1.1. Syntax Notation
This specification uses the Augmented Backus-Naur Form (ABNF) This specification uses the Augmented Backus-Naur Form (ABNF)
notation of [RFC5234]. notation of [RFC5234].
The following core rules are included by reference, as defined in The following core rules are included by reference, as defined in
[RFC5234], Appendix B.1: ALPHA (letters), CR (carriage return), CRLF [RFC5234], Appendix B.1: ALPHA (letters), CR (carriage return), CRLF
(CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double quote), (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double quote),
HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 8-bit HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 8-bit
sequence of data), SP (space), VCHAR (any visible [USASCII] sequence of data), SP (space), HTAB (horizontal tab), VCHAR (any
character), and WSP (whitespace). visible [USASCII] character), and WSP (whitespace).
2. Terminology 2. Terminology
The terms user agent, client, server, proxy, and origin server have The terms user agent, client, server, proxy, and origin server have
the same meaning as in the HTTP/1.0 specification. the same meaning as in the HTTP/1.0 specification.
Fully-qualified host name (FQHN) means either the fully-qualified The terms request-host and request-URI refer to the values the user
domain name (FQDN) of a host (i.e., a completely specified domain agent would send to the server as, respectively, the host (but not
name ending in a top-level domain such as .com or .uk), or the port) and abs_path portions of the absoluteURI (http_URL) of the HTTP
numeric Internet Protocol (IP) address of a host. The fully request line.
qualified domain name is preferred; use of numeric IP addresses is
strongly discouraged. [TODO: What does "strongly discouraged" mean?]
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. Hosts names
can be specified either as an IP address or a FQHN string.
Because it was used in Netscape's original implementation of state
management, we will use the term cookie to refer to the state
information that passes between an origin server and user agent, and
that gets stored by the user agent.
3. Overview 3. Overview
We outline here a way for an origin server to send state information 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 to the user agent, and for the user agent to return the state
information to the origin server. information to the origin server.
The origin server initiates a session, if it so desires, by including The origin server initiates a session, if it so desires, by including
a Set-Cookie header in an HTTP response. (Note that "session" here a Set-Cookie header in an HTTP response. (Note that "session" here
does not refer to a persistent network connection but to a logical does not refer to a persistent network connection but to a logical
session created from HTTP requests and responses. The presence or session created from HTTP requests and responses. The presence or
absence of a persistent connection should have no effect on the use absence of a persistent connection should have no effect on the use
of cookie-derived sessions). of cookie-derived sessions).
A user agent returns a Cookie request header (see below) to the The user agent returns a Cookie request header to the origin server
origin server if it chooses to continue a session. The origin server if it chooses to continue a session. The Cookie header contains a
may ignore it or use it to determine the current state of the number of cookies the user agent received in previous Set-Cookie
session. It may send the client a Set-Cookie response header with headers. The origin server MAY ignore the Cookie header or use the
the same or different information, or it may send no Set-Cookie header to determine the current state of the session. The origin
header at all. server MAY send the user agent a Set-Cookie response header with the
same or different information, or it MAY send no Set-Cookie header at
all.
Servers may return a Set-Cookie response headers with any response. Servers MAY return a Set-Cookie response headers with any response.
User agents should send Cookie request headers, subject to other User agents should send Cookie request headers, subject to other
rules detailed below, with every request. rules detailed below, with every request.
An origin server may include multiple Set-Cookie headers in a An origin server MAY include multiple Set-Cookie header fields in a
response. Note that an intervening gateway MUST NOT fold multiple single response. Note that an intervening gateway MUST NOT fold
Set-Cookie headers into a single header. multiple Set-Cookie header fields into a single header field.
[TODO: Overview the Set-Cookie and Cookie headers.]
3.1. Examples 3.1. Examples
[TODO: Put some examples here. [TODO: Put some examples here.
4. Protocol Description 4. A Well-Behaved Profile
The cookie protocol consists of two HTTP headers: the Set-Cookie
header and the Cookie header. The server sends the Set-Cookie header
is to the user agent in an HTTP response, causing the user agent to
modify the Cookie header it returns to the server.
This section describes the syntax and semantics of the protocol. This section describes the syntax and semantics of a well-behaved
Detailed conformance requirements for user agents are given in profile of the protocol. Servers SHOULD use the profile described in
Section [TODO]. this section, both to maximize interoperability with existing user
agents and because a future version of the cookie protocol could
remove support for some of the most esoteric aspects of the protocol.
User agents, however, MUST implement the full protocol to ensure
interoperability with servers making use of the full protocol.
4.1. Set-Cookie 4.1. Set-Cookie
The Set-Cookie header is used to send cookies from the server to the
user agent.
4.1.1. Syntax 4.1.1. Syntax
Informally, the Set-Cookie response header comprises the token Set- Informally, the Set-Cookie response header comprises the token Set-
Cookie:, followed by a cookie. Each cookie begins with a name-value- Cookie:, followed by a cookie. Each cookie begins with a name-value-
pair, followed by zero or more semi-colon-separated attribute-value pair, followed by zero or more attribute-value pairs. Servers SHOULD
pairs. NOT send Set-Cookie headers that fail to conform to the following
grammar:
[TODO: Consider replacing this grammar with the one from 2009-11-07-
Yui-Naruse.txt.]
set-cookie-header = "Set-Cookie:" name-value-pairs
name-value-pairs = name-value-pair *(";" name-value-pair)
name-value-pair = name ["=" value] ; optional value
name = token
value = *CHAR
token = <token, as defined in Section 2.2 of RFC 2616>
The valid character for the value production vary depending on the set-cookie-header = "Set-Cookie:" OWS set-cookie-string OWS
attribute name. set-cookie-string = cookie-pair *( ";" cookie-av)
cookie-pair = cookie-name "=" cookie-value
cookie-name = token
cookie-value = token
token = <token, as defined in RFC 2616>
[TODO: Investigate what token actually means.] cookie-av = expires-av / domain-av / path-av /
secure-av / httponly-av
expires-av = "Expires" "=" cookie-date
cookie-date = <rfc1123-date, as defined in RFC 2616>
domain-av = "Domain" "=" domain-value
domain-value = token
path-av = "Path" "=" path-value
path-value = <abs_path, as defined in RFC 2616>
secure-av = "Secure"
httponly-av = "HttpOnly"
Attributes names are case-insensitive. White space is permitted Servers SHOULD NOT include two attributes with the same name.
between tokens. Servers MUST NOT include two attributes with the
same name. Note that although the above syntax description shows
value as optional, some attributes require values.
The cookie-value is opaque to the user agent and MAY be anything the The cookie-value is opaque to the user agent and MAY be anything the
origin server chooses to send, possibly in a server-selected origin server chooses to send, possibly in a server-selected
printable ASCII encoding. "Opaque" implies that the content is of printable ASCII encoding. "Opaque" implies that the content is of
interest and relevance only to the origin server. The content may, interest and relevance only to the origin server. The content is, in
in fact, be readable by anyone who examines the Set-Cookie header. fact, readable by anyone who examines the Set-Cookie header.
NOTE: The syntax above allows whitespace between the attribute and NOTE: The syntax above allows whitespace between the attribute and
the U+3D ("=") character. Servers wishing to interoperate with some the U+003D ("=") character. Servers wishing to interoperate with
legacy user agents might wish to elide this extra white space to some legacy user agents might wish to elide this whitespace.
maximize compatibility.
4.1.2. Semantics 4.1.2. Semantics (Non-Normative)
This section describes a simplified semantics of the Set-Cookie
header. These semantics are detailed enough to be useful for
understanding the most common uses of the cookie protocol. The full
semantics are described in Section 5.
When the user agent receives a Set-Cookie header, the user agent When the user agent receives a Set-Cookie header, the user agent
stores the cookie in its cookie store. When the user agent makes stores the cookie in its cookie store. When the user agent
another HTTP request to the origin server, the user agent returns the subsequently makes an HTTP request, the user agent consults its
cookie in the Cookie header. cookie store and includes the applicable, non-expired cookies in the
Cookie header.
The server can override the default handling of cookies by specifying If the cookie store already contains a cookie with the same cookie-
cookie attributes. User agents ignore unrecognized cookie name, domain-value, and path-value, the existing cookie is evicted
attributes. from the cookie store and replaced with the new value. Notice that
servers can delete cookies by including an Expires attribute with a
value in the past.
4.1.2.1. Max-Age Unless the cookie's attributes indicate otherwise, the cookie is
returned only to the origin server, and it expires at the end of the
current session (as defined by the user agent). User agents ignore
unrecognized cookie attributes.
[TODO: Consider removing Max-Age from the server conformance section 4.1.2.1. Expires
because it's not supported by IE.]
Syntax A sequence of ASCII numerals. The Expires attribute indicates the maximum lifetime of the cookie,
represented as the date and time at which the cookie expires. The
user agent is not required to retain the cookie until the specified
date has passed. In fact, user agents often evict cookies from the
cookie store due to memory pressure or privacy concerns.
Semantics The value of the Max-Age attribute represents the maximum 4.1.2.2. Domain
lifetime of the cookie, measured in seconds from the moment the
user agent receives the cookie. If the server does not supply an
Expires or a Max-Age attribute, the lifetime of the cookie is
limited to the current session (as defined by the user agent).
4.1.2.2. Expires The Domain attribute specifies those hosts for which the cookie will
be sent. For example, if the domain attribute contains the value
".example.com", the user agent will include the cookie in the Cookie
header when making HTTP requests to example.com, www.example.com, and
www.corp.example.com. (Note that a leading U+2E ("."), if present,
is ignored.) If the server omits the Domain attribute, the user
agent will return the cookie only to the origin server
The user agent will reject cookies (refuse to store them in the
cookie store) unless the Domain attribute specifies a scope for the
cookie that would include the origin server. For example, the user
agent will accept a Domain attribute of ".example.com" or of
".foo.example.com" from foo.example.com, but the user agent will not
accept a Domain attribute of ".bar.example.com" or of
".baz.foo.example.com".
Syntax An RFC 1123 date [cite]. (Note that user agents use very NOTE: For security reasons, some user agents are configured to reject
forgiving date parers; see Section [TODO]). Domain attributes that do not correspond to a "registry controlled"
domain (or a subdomain of a registry controlled domain). For
example, some user agents will reject Domain attributes of ".com".
Semantics The value of the Expires attribute represents the maximum 4.1.2.3. Path
lifetime of the cookie, represented as the point in time at which
the cookie expires. If the server does not supply an Expires or a
Max-Age attribute, the lifetime of the cookie is limited to the
current session (as defined by the user agent).
4.1.2.3. Domain The Path attribute limits the scope of the cookie to a set of paths.
When a cookie has a Path attribute, the user agent will include the
cookie in an HTTP request only if the path portion of the Request-URI
matches (or is a subdirectory of) the cookie's Path attribute, where
the U+002F ("/") character is interpreted as a directory separator.
If the server omits the Path attribute, the user agent will use the
directory of the Request-URI's path component as the default value.
[TODO: Test Domain.] The Domain attribute specifies the domain for Although seemingly useful for isolating cookies between different
which the cookie is valid. The leading dot isn't required. If there paths within a given domain, the Path attribute cannot be relied upon
is no Domain attribute, the default is to return the cookie only to for security for two reasons: First, user agents do not prevent one
the origin server. [TODO: You can only set cookies for related path from overwriting the cookies for another path. For example, if
domains.] a response to a request for /foo/bar.html attempts to set a cookie
with a Path attribute of "/baz" the user agent will store that cookie
in the cookie store. Second, the "same-origin" policy implemented by
many user agents does not isolate different paths within an origin.
For example, /foo/bar.html can read cookies with a Path attribute of
"/baz" because they are within the "same origin".
4.1.2.4. Path 4.1.2.4. Secure
Syntax A sequence of characters beginning with a "/" character. The Secure attribute limits the scope of the cookie to "secure"
channels (where "secure" is defined by the user agent). When a
cookie has the Secure attribute, the user agent will include the
cookie in an HTTP request only if the request is transmitted over a
secure channel (typically TLS [RFC5234]).
Semantics The Path attribute specifies the scope of the cookie Although seemingly useful for protecting cookies from active network
within a given FQDN. The user agent will include a cookie in an attackers, the Secure attribute protects only the cookie's
HTTP request only if the Request-URI's path matches, or is a confidentiality. An active network attacker can overwrite Secure
subdirectory of, the cookie's Path attribute (where the "/" cookies from an insecure channel, disrupting the integrity of the
character is interpreted as a directory separator). The default cookies.
value for the Path attribute is the directory of the Request-URI
when the cookie was received.
4.1.2.5. Secure 4.1.2.5. HttpOnly
Syntax Servers MUST NOT include a value. The HttpOnly attribute limits the scope of the cookie to HTTP
requests. In particular, the attribute instructs the user agent to
elide the cookie when providing access to its cookie store via "non-
HTTP" APIs (as defined by the user agent).
Semantics The user agent SHOULD protect the confidentiality of 4.2. Cookie
cookies with the Secure attribute by not transmitting Secure
cookies over an "insecure" channel (where "insecure" is defined by
the user agent).
4.1.2.6. HttpOnly 4.2.1. Syntax
Syntax Servers MUST NOT include a value. The user agent returns stored cookies to the origin server in the
Cookie header. If the server conforms to the requirements in this
section, the requirements in the next section will cause the user
agent to return a Cookie header that conforms to the following
grammar.
Semantics The user agent SHOULD protect confidentiality of cookies cookie-header = "Cookie:" OWS cookie-string OWS
with the HttpOnly attribute by not revealing their contents via cookie-string = cookie-pair *( ";" cookie-pair)
"non-HTTP" APIs. (Note that this document does not define which cookie-pair = cookie-name "=" cookie-value
APIs are "non-HTTP".) cookie-name = token
cookie-value = token
token = <token, as defined in Section 2.2 of RFC 2616>
4.2. Cookie 4.2.2. Semantics
4.2.1. Syntax Each cookie-pair represents a cookie stored by the user agent. The
cookie-name and the cookie-value are returned verbatim from the
corresponding parts of the Set-Cookie header.
The user agent returns stored cookies to the origin server in the Notice that the cookie attributes are not returned. In particular,
Cookie header. The Cookie header shares a common syntax with the the server cannot determine from the Cookie header alone when a
Set-Cookie header, but the semantics of the header differ cookie will expire, for which domains the cookie is valid, for which
dramatically. paths the cookie is valid, or whether the cookie was set with the
Secure or HttpOnly attributes.
cookie-header = "Cookie:" name-value-pairs The semantics of individual cookies in the Cookie header is not
name-value-pairs = name-value-pair *(";" name-value-pair) defined by this document. Servers are expected to imbue these
name-value-pair = name "=" value cookies with server-specific semantics.
name = token
value = *CHAR
NOTE: If the server supplies a Set-Cookie header that does not 5. The Cookie Protocol
conform to the grammar in Section [TODO], the user agent might not
supply a Cookie header that conforms to the preceding grammar.
4.2.2. Semantics For historical reasons, the full cookie protocol contains a number of
exotic quirks. This section is intended to specify the cookie
protocol in enough detail to enable a user agent that implements the
protocol precisely as specified to interoperate with existing
servers.
Each name-value-pair represents a cookie stored by the user agent. Although some parts of the cookie protocol are specified
The cookie name is returned in as the name and the cookie value is algorithmically, user agents are free to implement the cookie
returned as the value. protocol in any manner as long as their resultant behavior is "black-
box" indistinguishable from a user agent that implements the protocol
as described.
The meaning of the cookies in the Cookie header is not defined by 5.1. Algorithms
this document. Servers are expected to imbue these cookies with
server-specific semantics.
4.3. Controlling Caching This section defines a number of algorithms used by the cookie
protocol.
[TODO: Should we go into this much detail here? This seems redundant 5.1.1. Dates
with the HTTP specs.]
An origin server must be cognizant of the effect of possible caching The user agent MUST use the following algorithm to *parse a cookie-
of both the returned resource and the Set-Cookie header. Caching date*:
"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 Set-
Cookie 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 Set-Cookie 1. Using the grammar below, divide the cookie-date into date-tokens.
header should not be cached. A Set-Cookie header that is intended to
be shared by multiple users may be cached.
The origin server should send the following additional HTTP/1.1 cookie-date = date-token *( 1*delimiter date-token )
response headers, depending on circumstances: [TODO: Is this good delimiter = %x09 / %x20 / %x21 / %x22 / %x23 / %x24 /
advice?] %x25 / %x26 / %x27 / %x28 / %x29 / %x2A /
%x2B / %x2C / %x2D / %x2E / %x2F / %x3B /
%x3C / %x3D / %x3E / %x3F / %x40 / %x5B /
%x5C / %x5D / %x5E / %x5F / %x60 / %x7B /
%x7C / %x7D / %x7E
date-token = day-of-month / month / year / time / mystery
day-of-month = 2DIGIT / DIGIT
month = "jan" [ mystery ] / "feb" [ mystery ] /
"mar" [ mystery ] / "apr" [ mystery ] /
"may" [ mystery ] / "jun" [ mystery ] /
"jul" [ mystery ] / "aug" [ mystery ] /
"sep" [ mystery ] / "oct" [ mystery ] /
"nov" [ mystery ] / "dec" [ mystery ]
year = 5DIGIT / 4DIGIT / 3DIGIT / 2DIGIT / DIGIT
time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
mystery = <anything except a delimiter>
2. Process each date-token sequentially in the order the date-tokens
appear in the cookie-date:
o To suppress caching of the Set-Cookie header: Cache-control: no- 1. If the found-day-of-month flag is not set and the date-token
cache="set-cookie". matches the day-of-month production, set the found-day-of-
month flag and set the day-of-month-value to the number
denoted by the date-token. Skip the remaining sub-steps and
continue to the next date-token.
and one of the following: 2. If the found-month flag is not set and the date-token matches
the month production, set the found-month flag and set the
month-value to the month denoted by the date-token. Skip the
remaining sub-steps and continue to the next date-token.
o To suppress caching of a private document in shared caches: Cache- 3. If the found-year flag is not set and the date-token matches
Control: private. the year production, set the found-year flag and set the
year-value to the number denoted by the date-token. Skip the
remaining sub-steps and continue to the next date-token.
o To allow caching of a document and require that it be validated 4. If the found-time flag is not set and the token matches the
before returning it to the client: Cache-Control: must-revalidate. time production, set the found-time flag and set the hour-
value, minute-value, and second-value to the numbers denoted
by the digits in the date-token, respectively. Skip the
remaining sub-steps and continue to the next date-token.
o To allow caching of a document, but to require that proxy caches 3. Abort these steps and *fail to parse* if
(not user agent caches) validate it before returning it to the
client: Cache-Control: proxy-revalidate.
o To allow caching of a document and request that it be validated * at least one of the found-day-of-month, found-month, found-
before returning it to the client (by "pre-expiring" it): Cache- year, or found-time flags is not set,
Control: max-age=0. Not all caches will revalidate the document
in every case.
HTTP/1.1 servers must send Expires: old-date (where old-date is a * the day-of-month-value is less than 1 or greater than 31,
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 downstream 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.
5. User Agent Conformance * the year-value is less than 1601 or greater than 30827,
Not all origin servers conform to the behavior specified in the * the hour-value is greater than 23,
previous section. To ensure interoperability, user agents MUST
process cookies in a manner that is "black-box" indistinguishable
from the requirements in this section.
5.1. Parsing the Set-Cookie Header * the minute-value is greater than 59, or
Let an LWS character be either a U+20 (SPACE) or a U+09 (TAB) * the second-value is greater than 59.
character.
4. If the year-value is greater than 68 and less than 100, increment
the year-value by 1900.
5. If the year-value is greater than or equal to 0 and less than 69,
increment the year-value by 2000.
6. Let the parsed-cookie-date be the date whose day-of-month, month,
year, hour, minute, and second (in GMT) are the day-of-month-
value, the month-value, the year-value, the hour-value, the
minute-value, and the second-value, respectively.
7. Return the parsed-cookie-date as the result of this algorithm.
5.1.2. Domains
A *canonicalized* host-name is the host-name converted to lower case.
A request-host *domain-matches* a cookie-domain if at least one of
the following conditions hold:
o The cookie-domain and the canonicalized request-host are
identical.
o The cookie-domain is a suffix of the canonicalized request-host,
the last character of the canonicalized request-host that is not
included in the cookie-domain is a U+002E (".") character, and
request-host is a host name (i.e., not an IP address). [TODO: Is
this the right way to spec this???]
5.1.3. Paths
The user agent MUST use the following algorithm to compute the
*default-path* of a cookie:
1. Let uri-path be the path portion of the Request-URI.
2. If the first character of the uri-path is not a U+002F ("/")
character, output U+002F ("/") and skip the remaining steps.
3. If the uri-path contains only a single U+002F ("/") character,
output U+002F ("/") and skip the remaining steps.
4. Output the characters of the uri-path from the first character up
to, but not including, the right-most U+002F ("/").
A request-path *path-matches* a cookie-path if at least one of the
following conditions hold: [TODO: This isn't exactly what IE or
Firefox does.]
o The cookie-path and the request-path are identical.
o The cookie-path is a prefix of the request-path and the last
character of the cookie-path is U+002F ("/").
o The cookie-path is a prefix of the request-path and the first
character of the request-path that is not included in the cookie-
path is a U+002F ("/") character.
5.2. The Set-Cookie Header
When a user agent receives an Set-Cookie header in an HTTP response, When a user agent receives an Set-Cookie header in an HTTP response,
the user agent *receives a set-cookie-string* consisting of the value the user agent *receives a set-cookie-string* consisting of the value
of the header. of the header.
A user agent MUST use the following algorithm to parse set-cookie- A user agent MUST use the following algorithm to parse set-cookie-
strings: strings:
1. [TODO: Deal with "," characters. My current thinking is that we 1. If the set-cookie-string is empty or consists entirely of WSP
don't actually have to do anything special for them.] characters, the user agent MAY ignore the set-cookie-string
entirely.
2. If the header contains a U+3B (";") character: 2. If the set-cookie-string contains a U+003B (";") character:
the name-value-pair string is characters up to, but not The name-value-pair string consists of the characters up to,
including, the first U+3B (";"), and the unparsed-cookie- but not including, the first U+003B (";"), and the unparsed-
attributes are the remainder of the header (including the U+3B attributes consist of the remainder of the set-cookie-string
(";") in question). (including the U+003B (";") in question).
Otherwise: Otherwise:
the name-value-pair string is all the character contained in The name-value-pair string consists of all the character
the header, and the unparsed-cookie-attributes is the empty contained in the set-cookie-string, and the unparsed-
string. attributes is the empty string.
3. If the name-value-pair string contains a U+3D ("=") character: 3. If the name-value-pair string contains a U+003D ("=") character:
the (possibly empty) name string is the characters up to, but The (possibly empty) name string consists of the characters up
not including, the first U+3D ("=") character, and the to, but not including, the first U+003D ("=") character, and
(possibly empty) value string is the characters after the the (possibly empty) value string consists of the characters
first U+3D ("=") character. after the first U+003D ("=") character.
Otherwise: Otherwise:
the name string is empty, and the value string is the entire The name string is empty, and the value string consists of the
name-value-pair string. entire name-value-pair string.
4. Remove any leading or trailing space from the name string and the 4. Remove any leading or trailing WSP characters from the name
value string. string and the value string.
5. The cookie-name is the name string, and the cookie-value is the 5. The cookie-name is the name string, and the cookie-value is the
value string. value string.
The user agent MUST use the following algorithm to parse the The user agent MUST use the following algorithm to parse the
unparsed-attributes: unparsed-attributes:
1. If the unparsed-attributes string is empty, skip the rest of 1. If the unparsed-attributes string is empty, skip the rest of
these steps. these steps.
2. Consume the first character of the unparsed-attributes (which 2. Consume the first character of the unparsed-attributes (which
will be a U+3B (";") character). will be a U+003B (";") character).
3. If the remaining unparsed-attributes contains a U+3B (";") 3. If the remaining unparsed-attributes contains a U+003B (";")
character: character:
Consume the characters of the unparsed-attributes up to, but Consume the characters of the unparsed-attributes up to, but
not including, the first U+3B (";") character. not including, the first U+003B (";") character.
Otherwise: Otherwise:
Consume the remainder of the unparsed-attributes. Consume the remainder of the unparsed-attributes.
The characters consumed in this step comprise the attribute- Let the cookie-av string be the characters consumed in this step.
value-pair string.
4. If the attribute-value-pair string contains a U+3D ("=") 4. If the cookie-av string contains a U+003D ("=") character:
character:
the (possibly empty) name string is the characters up to, but The (possibly empty) attribute-name string consists of the
not including, the first U+3D ("=") character, and the characters up to, but not including, the first U+003D ("=")
(possibly empty) value string is the characters after the character, and the (possibly empty) attribute-value string
first U+3D ("=") character . consists of the characters after the first U+003D ("=")
character.
Otherwise: Otherwise:
the name string is the entire attribute-value-pair string, and The attribute-name string consists of the entire cookie-av
the value string is empty. (Note that this step differs from string, and the attribute-value string is empty. (Note that
the analogous step when parsing the name-value-pair string.) this step differs from the analogous step when parsing the
name-value-pair string.)
5. Remove any leading or trailing space from the name string and the
value string.
6. If the name is a ASCII case-insensitive match for an entry in the 5. Remove any leading or trailing WSP characters from the attribute-
following table, process the value string as instructed. name string and the attribute-value string.
Attribute | Instruction 6. Process the attribute-name and attribute-value according to the
------------+--------------------- requirements in the following subsections.
Max-Age | See Section [TODO]
Expires | See Section [TODO]
Domain | See Section [TODO]
Path | See Section [TODO]
Secure | See Section [TODO]
HttpOnly | See Section [TODO]
7. Return to Step 1. 7. Return to Step 1.
[TODO: Can parsing a cookie ever fail? Doesn't look like it! Well, When the user agent finishes parsing the set-cookie-string, the user
unless you count "Set-Cookie: " as a fail...] agent *receives a cookie* from the Request-URI with name cookie-name,
value cookie-value, and attributes cookie-attribute-list.
When the user agent finishes parsing the set-cookie-string header,
the user agent *receives a cookie* from the origin server with name
cookie-name, value cookie-value, and attributes cookie-attribute-
list.
5.1.1. The Max-Age Attribute
When the user agent receives a cookie attribute with a name string
that case-insensitively matches the string "Max-Age", the user agent
MUST process the value string as follows.
If the first character of the value string is not a DIGIT or a "-"
character, the user agent MUST ignore the attribute.
If the remainder of value string contains a non-DIGIT character, the
user agent MUST ignore the attribute.
Let delta-seconds be the contents of the value string converted to an
integer.
If delta-seconds is less than or equal to 0, then append an attribute
named Expires (note the name conversion) to the cookie-attribute-list
with a value equal to the current date and time.
If delta-seconds is strictly greater than 0, then append an attribute
named Expires (note the name conversion) to the cookie-attribute-list
with a value equal to the current date and time plus delta-seconds
seconds.
5.1.2. The Expires Attribute
Unfortunately, cookie dates are quite complex for historical reasons.
When the user agent receives a cookie attribute with a name string
that case-insensitively matches the string "Expires", the user agent
MUST process the value string as follows.
If the attribute lacks a value or the value is the empty string,
abort these steps.
Using the grammar below, divide the value of the attribute into date- 5.2.1. The Max-Age Attribute
tokens.
cookie-date = date-token-list If the attribute-name case-insensitively matches the string "Max-
date-token-list = date-token [ delimiter date-token-list ] Age", the user agent MUST process the cookie-av as follows.
delimiter = %x09 / %x20 / %x21 / %x22 / %x23 / %x24 /
%x25 / %x26 / %x27 / %x28 / %x29 / %x2A /
%x2B / %x2C / %x2D / %x2E / %x2F / %x3B /
%x3C / %x3D / %x3E / %x3F / %x40 / %x5B /
%x5C / %x5D / %x5E / %x5F / %x60 / %x7B /
%x7C / %x7D / %x7E
date-token = day-of-month / month / year / time / mystery
day-of-month = 2DIGIT / DIGIT
month = "jan" [ mystery ] / "feb" [ mystery ] /
"mar" [ mystery ] / "apr" [ mystery ] /
"may" [ mystery ] / "jun" [ mystery ] /
"jul" [ mystery ] / "aug" [ mystery ] /
"sep" [ mystery ] / "oct" [ mystery ] /
"nov" [ mystery ] / "dec" [ mystery ]
year = 5DIGIT / 4DIGIT / 3DIGIT / 2DIGIT / DIGIT
time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
mystery = <anything except a delimiter>
Process each data-token sequentially in the order the date-tokens If the first character of the attribute-value is not a DIGIT or a "-"
appear in the attribute value: character, ignore the cookie-av.
1. If the found-day-of-month flag is not set and the token matches If the remainder of attribute-value contains a non-DIGIT character,
the day-of-month production, set the found-day-of-month flag and ignore the cookie-av.
set the day-of-month-value to the number denoted by the token.
Skip the remaining sub-steps and continue to the next token.
2. If the found-month flag is not set and the token matches the Let delta-seconds be the attribute-value converted to an integer.
month production, set the found-month flag and set the month-
value to the month denoted by the token. Skip the remaining sub-
steps and continue to the next token.
3. If the found-year flag is not set and the token matches the year If delta-seconds is less than or equal to zero (0), let expiry-time
production, set the found-year flag and set the year-value to the be the current date and time. Otherwise, let the expiry-time be the
number denoted by the token. Skip the remaining sub-steps and current date and time plus delta-seconds seconds.
continue to the next token.
4. If the found-time flag is not set and the token matches the time Append an attribute to the cookie-attribute-list with an attribute-
production, set the found-time flag and set the hour-value, name of Expires (note the name conversion) and an attribute-value of
minute-value, and second-value to the numbers denoted by the expiry-time.
digits in the token, respectively. Skip the remaining sub-steps
and continue to the next token.
Abort these steps if 5.2.2. The Expires Attribute
o at least one of the found-day-of-month, found-month, found-year, If the attribute-name case-insensitively matches the string
or found-time flags is not set, "Expires", the user agent MUST process the cookie-av as follows.
o the day-of-month-value is less than 1 or greater than 31, Let the parsed-cookie-date be the result of parsing the attribute-
value as cookie-date.
o the year-value is less than 1601 or greater than 30827, If the attribute-value failed to parse as a cookie date, ignore the
cookie-av.
o the hour-value is greater than 23, If the user agent received the set-cookie-string from an HTTP
response that contains a Date header field and the contents of the
last Date header field successfully parse as a cookie-date:
o the minute-value is greater than 59, or Let server-date be the date obtained by parsing the contents of
the last Date header field as a cookie-date.
o the second-value is greater than 59. Let delta-seconds be the number of seconds between the server-date
and the parsed-cookie-date (i.e., parsed-cookie-date - server-
date).
If the year-value is greater than 68 and less than 100, increment the Let the expiry-time be the current date and time plus delta-
year-value by 1900. seconds seconds.
If the year-value is greater than or equal to 0 and less than 69, Otherwise:
increment the year-value by 2000.
Let the expiry-time be the date whose day-of-month, month, year, Let the expiry-time be the parsed-cookie-date.
hour, minute, and second (in GMT) are the day-of-month-value, the
month-value, the year-value, the hour-value, the minute-value, and
the second-value, respectively.
If the expiry-time is later than the last date the user agent can If the expiry-time is later than the last date the user agent can
represent, the user agent MAY replace the expiry-time with the last represent, the user agent MAY replace the expiry-time with the last
representable date. representable date.
If the expiry-time is earlier than the first date the user agent can If the expiry-time is earlier than the first date the user agent can
represent, the user agent MAY replace the expiry-time with the first represent, the user agent MAY replace the expiry-time with the first
representable date. representable date.
Append an attribute named Expires to the cookie-attribute-list with a Append an attribute to the cookie-attribute-list with an attribute-
value equal to expiry-time. name of Expires and an attribute-value of expiry-time.
5.1.3. The Domain Attribute
When the user agent receives a cookie attribute with a name string
that case-insensitively matches the string "Domain", the user agent
MUST process the value string as follows:
o If the value string is empty, then ignore the attribute. [TODO:
Add a test for this with multiple Domain attributes.]
o If the first character of the value string is ".", then append an
attribute named Domain to the cookie-attribute-list with a value
equal to value string excluding the leading "." character.
o If the first character of the value string is not ".", then append 5.2.3. The Domain Attribute
an attribute named Domain to the cookie-attribute-list with a
value equal to value string and mark the attribute as host-only.
o [TODO: Deal with domains that have an insufficient number of If the attribute-name case-insensitively matches the string "Domain",
fields.] the user agent MUST process the cookie-av as follows.
o Otherwise, ignore the attribute. If the attribute-value is empty, the behavior is undefined. However,
user agent SHOULD ignore the cookie-av entirely.
5.1.4. The Path Attribute If the first character of the attribute-value string is U+002E ("."):
The user agent MUST use the following algorithm to compute the Let cookie-domain be the attribute-value without the leading
default-path of a cookie: U+002E (".") character.
1. Let uri-path be the path portion of the URI from which the user Otherwise:
agent received the cookie. [TODO: Define this more precisely.]
2. If the first character of the uri-path is not a "/" character, Let cookie-domain be the entire attribute-value.
output "/" and skip the remaining steps.
3. If the uri-path contains only a single "/" character, output "/" Convert the cookie-domain to lower case.
and skip the remaining steps.
4. Output the characters of the uri-path from the first character up [TODO: Test ".127.0.0.1" and "127.0.0.1"]
to, and but not including, the right-most "/".
A request-path path-matches a cookie-path if the cookie-path is a Append an attribute to the cookie-attribute-list with an attribute-
prefix of the request-path and at least one of the following name of Domain and an attribute-value of cookie-domain.
conditions hold:
o The last character of the cookie-path is "/". 5.2.4. The Path Attribute
o The first character of the request-path that is not included in If the attribute-name case-insensitively matches the string "Path",
the cookie-path is a "/" character. the user agent MUST process the cookie-av as follows.
When the user agent receives a cookie attribute with a name string If the attribute-value is empty or if the first character of the
that case-insensitively matches the string "Path", the user agent attribute-value is not U+002F ("/"):
MUST process the value string as follows:
o If the value string is empty, then append an attribute named Path Let cookie-path be the default-path. [TODO: We need more tests
to the cookie-attribute-list with a value equal to default-path of for this, including with " characters and with multiple Path
the cookie. [TODO: Is this right if there are more than one path attributes.]
attribute?]
o If the value string is non-empty and the first character is "/", Otherwise:
then append an attribute named Path to the cookie-attribute-list
with a value equal to value string.
o Otherwise, ignore the attribute. Let cookie-path be the attribute-value.
[TODO: Test \ ? ; # $ % etc] Append an attribute to the cookie-attribute-list with an attribute-
name of Path and an attribute-value of cookie-path.
5.1.5. The Secure Attribute 5.2.5. The Secure Attribute
When the user agent receives a cookie attribute with a name string If the attribute-name case-insensitively matches the string "Secure",
that case-insensitively matches the string "Secure", the user agent the user agent MUST append an attribute to the cookie-attribute-list
MUST append an attribute named Secure to the cookie-attribute-list with an attribute-name of Secure and an empty attribute-value.
with an empty value regardless of the value string.
5.1.6. The HttpOnly Attribute 5.2.6. The HttpOnly Attribute
When the user agent receives a cookie attribute with a name string If the attribute-name case-insensitively matches the string
that case-insensitively matches the string "HttpOnly", the user agent "HttpOnly", the user agent MUST append an attribute to the cookie-
MUST append an attribute named HttpOnly to the cookie-attribute-list attribute-list with an attribute-name of Secure and an empty
with an empty value regardless of the value string. attribute-value.
5.2. Storage Model 5.3. Storage Model
When the user agent receives a cookie, the user agent SHOULD record When the user agent receives a cookie, the user agent SHOULD record
the cookie in its cookie store as follows. the cookie in its cookie store as follows.
A user agent MAY ignore received cookies in their entirety if the A user agent MAY ignore a received cookie in its entirety if the user
user agent is configured to block receiving cookie for a particular agent is configured to block receiving cookies. For example, the
response. For example, the user agent might wish to block receiving user agent might wish to block receiving cookies from "third-party"
cookies from "third-party" responses. responses.
The user agent stores the following fields about each cookie:
o name (a sequence of bytes)
o value (a sequence of bytes)
o expiry (a date)
o domain (a cookie-domain)
o path (a sequence of bytes)
o creation (a date)
o last-access (a date)
o persistent (a Boolean)
o host-only (a Boolean) The user agent stores the following fields about each cookie: name,
value, expiry-time, domain, path, creation-time, last-access-time,
persistent-flag, host-only-flag, secure-only-flag, and http-only-
flag.
o secure-only (a Boolean) When the user agent receives a cookie from a Request-URI with name
cookie-name, value cookie-value, and attributes cookie-attribute-
list, the user agent MUST process the cookie as follows:
o http-only (a Boolean) 1. Create a new cookie with name cookie-name, value cookie-value.
Set the creation-time and the last-access-time to the current
date and time.
When the user agent receives a cookie, the user agent MUST follow the 2. If the cookie-attribute-list contains an attribute with an
following algorithm: attribute-name of "Expires":
1. Create a new cookie based on the parsed Set-Cookie header: Set the cookie's persistent-flag to true.
1. Create a new cookie with the following default field values: Set the cookie's expiry-time to attribute-value of the last
attribute in the cookie-attribute-list with an attribute-name
of "Expires". [TODO: Test that this really works when mixing
Max-Age and Expires.]
+ name = the cookie-name Otherwise:
+ value = the cookie-value Set the cookie's persistent-flag to false.
+ expiry = the latest representable date Set the cookie's expiry-time to the latest representable
date.
+ domain = the request-host 3. If the cookie-attribute-list contains an attribute with an
attribute-name of "Domain":
+ path = the cookie's default-path Let the domain-attribute be the attribute-value of the last
attribute in the cookie-attribute-list with an attribute-name
of "Domain".
+ last-access = the date and time the cookie was received If the Request-URI's host does not domain-match the domain-
attribute, ignore the cookie entirely and abort these steps.
+ persistent = false Set the cookie's host-only-flag to false.
+ host-only = true Set the cookie's domain to the domain-attribute.
+ secure-only = false Otherwise:
+ http-only = false Set the cookie's host-only-flag to true.
2. Update the default field values according to the cookie- Set the cookie's domain to the host of the Request-URI.
attributes:
expiry If the cookie-attributes contains at least one valid 4. If the cookie-attribute-list contains an attribute with an
Expires attribute, store the expiry-value of the last such attribute-name of "Path", set the cookie's path to attribute-
attribute in the expiry field. Store the value true in value of the last attribute in the cookie-attribute-list with an
the persistent field. [TODO: Test that this really works attribute-name of "Path". Otherwise, set cookie's path to the
when mixing Max-Age and Expires.] default-path of the Request-URI.
domain If the cookie-attributes contains at least one Domain 5. If the cookie-attribute-list contains an attribute with an
attribute, store the value of the last such attribute in attribute-name of "Secure", set the cookie's secure-only-flag to
the domain field. Store the value false in the host-only true. Otherwise, set cookie's secure-only-flag to false.
field. [TODO: Reject cookies for unrelated domains.]
[TODO: If the URL's host is an IP address, let Domain to
be an IP address if it matches the URL's host exactly, but
set the host-only flag. ]
path If the cookie-attributes contains at least one Path 6. If the cookie-attribute-list contains an attribute with an
attribute, store the value of the last such attribute in attribute-name of "HttpOnly", set the cookie's http-only-flag to
the path field. true. Otherwise, set cookie's http-only-flag to false.
secure-only If the cookie-attributes contains at least one 7. Remove from the cookie store all cookies that share the same
Secure attribute, store the value true in the secure-only name, domain, path, and host-only-flag as the newly created
field. cookie. [TODO: Validate this list!] [TODO: There's some funny
business around http-only here.]
http-only If the cookie-attributes contains at least one 8. If the cookie's name and value are both empty, abort these
HttpOnly attribute, store the value true in the http-only steps.
field.
2. Remove from the cookie store all cookies that have the share the 9. If the cookie's expiry-time is not in the future, abort these
same name, domain, path, and host-only fields as the newly steps.
created cookie. [TODO: Validate this list!] [TODO: There's some
funny business around http-only here.]
3. Insert the newly created cookie into the cookie store. 10. Insert the newly created cookie into the cookie store.
The user agent MUST evict a cookie from the cookie store if A cookie The user agent MUST evict a cookie from the cookie store if, at any
exists in the cookie store with an expiry date in the past. time, a cookie exists in the cookie store with an expiry date in the
past.
The user agent MAY evict a cookie from the cookie store if the number The user agent MAY evict a cookie from the cookie store if the number
of cookies sharing a domain field exceeds some predetermined upper of cookies sharing a domain field exceeds some predetermined upper
bound (such as 50 cookies). [TODO: Explain where 50 comes from.] bound (such as 50 cookies).
The user agent MAY evict cookies from the cookie store if the cookie The user agent MAY evict a cookie from the cookie store if the cookie
store exceeds some maximum storage bound (such as 3000 cookies). store exceeds some predetermined upper bound (such as 3000 cookies).
[TODO: Explain where 3000 comes from.]
When the user agent evicts cookies from the cookie store, the user When the user agent evicts a cookie from the cookie store, the user
agent MUST evict cookies in the following priority order: agent MUST evict cookies in the following priority order:
1. Cookies with an expiry date in the past. 1. Cookies with an expiry date in the past.
2. Cookies that share a domain field more than a predetermined 2. Cookies that share a domain field with more than a predetermined
number of other cookies. number of other cookies.
3. All other cookies. 3. All cookies.
If two cookies have the same removal priority, the user agent MUST If two cookies have the same removal priority, the user agent MUST
evict the cookie with the least recent last-access date first. evict the cookie with the least recent last-access date first.
When "the current session is over", the user agent MUST remove from When "the current session is over" (as defined by the user agent),
the cookie store all cookies with the persistent field set to false. the user agent MUST remove from the cookie store all cookies with the
persistent-flag set to false.
NOTE: This document does not define when "the current session is
over." Many user agents remove non-persistent cookies when they
exit. However, other user agent expire non-persistent cookies
using other heuristics.
5.3. The Cookie Header 5.4. The Cookie Header
When the user agent generates an HTTP request for a particular URI, When the user agent generates an HTTP request, the user agent SHOULD
the user agent SHOULD attach exactly one HTTP header named Cookie if attach exactly one HTTP header named Cookie if the cookie-string
the cookie-string (defined below) for that URI is non-empty. (defined below) for the Request-URI is non-empty.
A user agent MAY elide the Cookie header in its entirety if the user A user agent MAY elide the Cookie header in its entirety if the user
agent is configured to block sending cookie for a particular request. agent is configured to block sending cookies. For example, the user
For example, the user agent might wish to block sending cookies agent might wish to block sending cookies during "third-party"
during "third-party" requests. requests.
The user agent MUST use the following algorithm to compute the The user agent MUST use the following algorithm to compute the
cookie-string from a cookie store and a URI: cookie-string from a cookie store and a Request-URI:
1. Let cookie-list be the set of cookies from the cookie store that 1. Let cookie-list be the set of cookies from the cookie store that
meet the following requirements: meet all of the following requirements:
* The cookie's domain field must domain-match the URI's host. * Let request-host be the Request-URI's host. Either:
[TODO: Spec me]
* The cookie's path field must path-match the URI's path. The cookie's host-only-flag is true and the canonicalized
request-host is identical to the cookie's domain.
* If the cookie's host-only flag is set, the cookie's domain Or:
field must denote exactly the same FQDN as the URI's host.
[TODO: Internet Explorer does not implement this requirement
but most other major implementations do.]
* If the cookie's secure-only field is true, then the URI's The cookie's host-only-flag is false and the request-host
scheme must denote a "secure" protocol. domain-matches cookie's domain.
* The Request-URI's path patch-matches cookie's path.
* If the cookie's secure-only field is true, then the Request-
URI's scheme must denote a "secure" protocol (as defined by
the user agent).
NOTE: The notion of an "secure" protocol is not defined by NOTE: The notion of an "secure" protocol is not defined by
this document. Typically, user agents consider a protocol this document. Typically, user agents consider a protocol
secure if the protocol makes use of transport-layer secure if the protocol makes use of transport-layer
security, such as TLS. For example, most user agents security, such as TLS. For example, most user agents
consider "https" to be a scheme that denotes a secure consider "https" to be a scheme that denotes a secure
protocol. protocol.
* If the cookie's http-only field is true, then include the * If the cookie's http-only field is true, then exclude the
cookie unless the cookie-string is begin generated for a "non- cookie unless the cookie-string is begin generated for a
HTTP" API. (Note that this document does not define which "HTTP" API (as defined by the user agent).
APIs are "non-HTTP".)
NOTE: The Cookie header will not contain any expired cookies
because cookies past their expiry date are removed from the
cookie store immediately.
2. Sort the cookie-list in the following order: 2. Sort the cookie-list in the following order:
* Cookies with longer path fields are listed before cookies with * Cookies with longer paths are listed before cookies with
shorter path field. shorter paths.
* Among cookies that have equal length path fields, cookies with * Among cookies that have equal length path fields, cookies with
earlier creation dates are listed before cookies with later earlier creation-times are listed before cookies with later
creation dates. creation-times.
3. Update the last-access field of each cookie in the cookie-list to 3. Update the last-access-time of each cookie in the cookie-list to
the current date. the current date and time.
4. Serialize the cookie-list into a cookie-string by processing each 4. Serialize the cookie-list into a cookie-string by processing each
cookie in the cookie-list in order: cookie in the cookie-list in order:
1. If the cookie's name and value fields are both empty, skip 1. If the cookie's name is non-empty, output the cookie's name
the remaining steps for this cookie and continue to the next followed by the U+003D ("=") character.
cookie, if any.
2. If the cookie's name field is non-empty, output the cookie's
name field followed by the character U+3D ("=").
3. Output the cookie's value field.
4. If there is an unprocessed cookie in the cookie-list, output
the characters U+3B and U+20 ("; ")
6. Implementation Considerations
6.1. Set-Cookie 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 Set-Cookie header can incorporate information
about the application areas by setting the Path 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. [TODO: Describe
briefly how to generate a decent session key.]
[TODO: We could recommend that servers encrypt and mac their cookie 2. Output the cookie's value.
data.]
[TODO: Mention issues that arise from having multiple concurrent 3. If there is an unprocessed cookie in the cookie-list, output
sessions.] the characters U+003B and U+0020 ("; ").
6.2. Implementation Limits 6. Implementation Limits
Practical user agent implementations have limits on the number and Practical user agent implementations have limits on the number and
size of cookies that they can store. General-use user agents SHOULD size of cookies that they can store. General-use user agents SHOULD
provide each of the following minimum capabilities: provide each of the following minimum capabilities:
o At least 4096 bytes per cookie (as measured by the size of the o At least 4096 bytes per cookie (as measured by the sum of the
characters that comprise the cookie non-terminal in the syntax length of the cookie's name, value, and attributes).
description of the Set-Cookie header). [TODO: Validate]
o At least 50 cookies per domain. [TODO: History lesson] o At least 50 cookies per domain.
o At least 3000 cookies total. o At least 3000 cookies total.
The information in a Set-Cookie response header must be retained in Servers SHOULD use as few and as small cookies as possible to avoid
its entirety. If for some reason there is inadequate space to store reaching these implementation limits and to avoid network latency due
the cookie, the cookie must be discarded, not truncated. to the Cookie header being included in every request.
Applications should use as few and as small cookies as possible, and Servers should gracefully degrade if the user agent fails to return
they should cope gracefully with the loss of a cookie. [TODO: Could one or more cookies in the Cookie header because the user agent might
mention latency issues that arise from having tons of cookies.] evict any cookie at any time on orders from the user.
7. Security Considerations 7. Security Considerations
7.1. Clear Text 7.1. Clear Text
The information in the Set-Cookie and Cookie headers is transmitted The information in the Set-Cookie and Cookie headers is transmitted
in the clear. Three consequences are: in the clear.
1. Any sensitive information that is conveyed in in the headers is 1. All sensitive information conveyed in these headers is exposed to
exposed to an eavesdropper. an eavesdropper.
2. A malicious intermediary could alter the headers as they travel 2. A malicious intermediary could alter the headers as they travel
in either direction, with unpredictable results. in either direction, with unpredictable results.
3. A malicious client could alter the Cookie header before 3. A malicious client could alter the Cookie header before
transmission, with unpredictable results. transmission, with unpredictable results.
These facts imply that information of a personal and/or financial Servers SHOULD encrypt and sign their cookies. However, encrypting
nature should be sent over a secure channel. For less sensitive and signing cookies does not prevent an attacker from transplanting a
information, or when the content of the header is a database key, an cookie from one user agent to another.
origin server should be vigilant to prevent a bad Cookie value from
causing failures.
7.2. Weak Isolation In addition to encrypting and signing the the contents of every
cookie, servers that require a higher level of security SHOULD use
the cookie protocol only over a secure channel.
[TODO: Weak isolation by port.] 7.2. Weak Confidentiality
[TODO: Weak isolation by scheme (e.g., ftp, gopher, etc).] Cookies do provide isolation by port. If a cookie is readable by a
service running on one port, the cookie is also readable by a service
running on another port of the same server. If a cookie is writable
by a service on one port, the cookie is also writable by a service
running on another port of the same server. For this reason, servers
SHOULD NOT both run mutually distrusting services on different ports
of the same machine and use cookies to store security-sensitive
information.
7.3. Cookie Spoofing Cookies do not provide isolation by scheme. Although most commonly
used with the http and https schemes, the cookies for a given host
are also available to other schemes, such as ftp and gopher. This
lack of isolation is most easily seen when a user agent retrieves a
URI with a gopher scheme via HTTP, but the lack of isolation by
scheme is also apparent via non-HTTP APIs that permit access to
cookies, such as HTML's document.cookie API.
[TODO: Mention integrity issue where a sibling domain can inject 7.3. Weak Integrity
cookies.]
[TODO: Mention integrity issue where a HTTP can inject cookies into Cookies do not integrity guarantees for sibling domains (and their
HTTPS.] subdomains). For example, consider foo.example.com and
bar.example.com. The foo.example.com server can set a cookie with a
Domain attribute of ".example.com", and the user agent will include
that cookie in HTTP requests to bar.example.com. In the worst case,
bar.example.com will be unable to distinguish this cookie from a
cookie it set itself. The foo.example.com server might be able to
leverage this ability to mount an attack against bar.example.com.
8. Other, Similar, Proposals Similarly, an active network attacker can inject cookies into the
Cookie header sent to https://example.com/ by impersonating a
response from http://example.com/ and injecting a Set-Cookie header.
The HTTPS server at example.com will be unable to distinguish these
cookies from cookies that it set itself in an HTTPS response. An
active network attacker might be able to leverage this ability to
mount an attack against example.com even if example.com uses HTTPS
exclusively.
[TODO: Describe relation to the Netscape Cookie Spec, RFC 2109, RFC Servers can partially mitigate these attacks by encrypting and
2629, and cookie-v2.] signing their cookies. However, using cryptography does not fully
ameliorate the issue because an attacker can replay a cookie he or
she received from the authentic example.com server in the user's
session, with unpredictable results.
9. Normative References 8. Normative References
[RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.
[RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax
Specifications: ABNF", STD 68, RFC 5234, January 2008. Specifications: ABNF", STD 68, RFC 5234, January 2008.
[RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security
(TLS) Protocol Version 1.2", RFC 5246, August 2008.
Appendix A. Acknowledgements Appendix A. Acknowledgements
This document borrows heavily from RFC 2109. [TODO: Figure out the This document borrows heavily from RFC 2109. [TODO: Figure out the
proper way to credit the authors of RFC 2109.] proper way to credit the authors of RFC 2109.]
Appendix B. Tabled Items
Tabled items:
o Public suffix.
Author's Address Author's Address
Adam Barth Adam Barth
University of California, Berkeley University of California, Berkeley
Email: abarth@eecs.berkeley.edu Email: abarth@eecs.berkeley.edu
URI: http://www.adambarth.com/ URI: http://www.adambarth.com/
 End of changes. 192 change blocks. 
614 lines changed or deleted 624 lines changed or added

This html diff was produced by rfcdiff 1.37b. The latest version is available from http://tools.ietf.org/tools/rfcdiff/