Cookie PrefixesGoogle, Incmkwst@google.comhttps://mikewest.org/
General
HTTPInternet-DraftThis document updates RFC6265 by adding a set of restrictions upon the names
which may be used for cookies with specific properties. These restrictions
enable user agents to smuggle cookie state to the server within the confines
of the existing Cookie request header syntax, and limits the ways in which
cookies may be abused in a conforming user agent.Section 8.5 and Section 8.6 of spell out some of the drawbacks of
cookies’ implementation: due to historical accident, it is impossible for a
server to have confidence that a cookie set in a secure way (e.g., as a
domain cookie with the Secure (and possibly HttpOnly) flags set) remains
intact and untouched by non-secure subdomains.We can’t alter the syntax of the Cookie request header, as that would likely
break a number of implementations. This rules out sending a cookie’s flags along
with the cookie directly, but we can smuggle information along with the cookie
if we reserve certain name prefixes for cookies with certain properties.This document describes such a scheme, which enables servers to set cookies
which conforming user agents will ensure are Secure, and locked to a domain.The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”,
“SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be
interpreted as described in .The scheme component of a URI is defined in Section 3 of .If a cookie’s name begins with “__Secure-“, the cookie MUST be:Set with a Secure attributeSet from a URI whose scheme is considered “secure” by the user agent.The following cookie would be rejected when set from any origin, as the Secure
flag is not setWhile the following would be accepted if set from a secure origin (e.g.
https://example.com/), and rejected otherwise:If a cookie’s name begins with “__Host-“, the cookie MUST be:Set with a Secure attributeSet from a URI whose scheme is considered “secure” by the user agent.Sent only to the host which set the cookie. That is, a cookie named
“__Host-cookie1” set from https://example.com MUST NOT contain a Domain
attribute (and will therefore be sent only to example.com, and not to
subdomain.example.com).Sent to every request for a host. That is, a cookie named “__Host-cookie1”
MUST contain a Path attribute with a value of “/”.The following cookies would always be rejected:While the following would be accepted if set from a secure origin (e.g.
https://example.com/), and rejected otherwise:This document updates Section 5.3 of as follows:After step 10 of the current algorithm, the cookies flags are set. Insert the
following steps to perform the prefix checks this document specifies:If the cookie-name begins with the string “__Secure-“ or “__Host-“,
abort these steps and ignore the cookie entirely unless both of the
following conditions are true: The cookie’s secure-only-flag is truerequest-uri’s scheme component denotes a “secure” protocol (as
determined by the user agent)If the cookie-name begins with the string “__Host-“, abort these
steps and ignore the cookie entirely unless the following conditions are
true: The cookie’s host-only-flag is trueThe cookie’s path is “/”Prefixes are ugly. :(We started with $, but ran into issues with servers that had implemented
-style cookies. __ is a prefix used for a number of well-known
cookies in the wild (notably Google Analytics’s __ut* cookies, and
CloudFlare’s __cfduid), and so is unlikely to produce such compatibility
issues, while being uncommon enough to mitigate the risk of collisions.It would certainly be possible to extend this scheme to non-secure origins (and
an earlier draft of this document did exactly that). User agents, however, are
slowly moving towards a world where features with security implications are
available only over secure transport (see ,
, and ). This document follows that
trend, limiting exciting new cookie properties to secure transport in order to
ensure that user agents can make claims which middlemen will have a hard time
violating.To that end, note that the requirements listed above mean that prefixed cookies
will be rejected entirely if a non-secure origin attempts to set them.This scheme gives no assurance to the server that the restrictions on cookie
names are enforced. Servers could certainly probe the user agent’s functionality
to determine support, or sniff based on the User-Agent request header, if
such assurances were deemed necessary.Key words for use in RFCs to Indicate Requirement LevelsIn many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.Uniform Resource Identifier (URI): Generic SyntaxA Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource. This specification defines the generic URI syntax and a process for resolving URI references that might be in relative form, along with guidelines and security considerations for the use of URIs on the Internet. The URI syntax defines a grammar that is a superset of all valid URIs, allowing an implementation to parse the common components of a URI reference without knowing the scheme-specific requirements of every possible identifier. This specification does not define a generative grammar for URIs; that task is performed by the individual specifications of each URI scheme. [STANDARDS-TRACK]HTTP State Management MechanismThis document defines the HTTP Cookie and Set-Cookie header fields. These header fields can be used by HTTP servers to store state (called cookies) at HTTP user agents, letting the servers maintain a stateful session over the mostly stateless HTTP protocol. Although cookies have many historical infelicities that degrade their security and privacy, the Cookie and Set-Cookie header fields are widely used on the Internet. This document obsoletes RFC 2965. [STANDARDS-TRACK]HTTP State Management MechanismThis document specifies a way to create a stateful session with HTTP requests and responses. It describes two new headers, Cookie and Set- Cookie, which carry state information between participating origin servers and user agents. The method described here differs from Netscape's Cookie proposal, but it can interoperate with HTTP/1.0 user agents that use Netscape's method. [STANDARDS-TRACK]Prefer Secure Origins for Powerful New FeaturesSecure ContextsDeprecating Non-Secure HTTPDuct Tape and Baling Wire -- Cookie PrefixesEric Lawrence had this idea a million years ago, and wrote about its genesis in
. Devdatta Akhawe helped justify the potential impact of the
scheme on real-world websites. Thomas Broyer pointed out the issues with a
leading $ in the prefixes, and Brian Smith provided valuable contributions to
the discussion around a replacement (ISO C indeed).