title: Deprecate modification of 'secure' cookies from non-secure origins abbrev: Leave Secure Cookies Alone docname: draft-ietf-httpbis-cookie-alone-latest date: 2017 category: std updates: 6265
ipr: trust200902 area: Applications and Real-Time workgroup: HTTP keyword: Internet-Draft keyword: Cookie
stand_alone: yes pi: [toc, tocindent, sortrefs, symrefs, strict, compact, subcompact, comments, inline]
ins: M. West name: Mike West organization: Google, Inc email: [email protected] uri: https://mikewest.org/
normative: RFC2119: RFC3986: RFC6265:
informative: COOKIE-INTEGRITY: target: https://www.usenix.org/conference/usenixsecurity15/technical-sessions/presentation/zheng title: "Cookies Lack Integrity: Real-World Implications" date: 2015-08 author: - ins: X. Zheng name: Xiaofeng Zheng organization: Tsinghua University and Tsinghua National Laboratory for Information Science and Technology - ins: J. Jiang name: Jian Jiang organization: University of California, Berkeley - ins: J. Liang name: Jinjin Liang organization: Tsinghua University and Tsinghua National Laboratory for Information Science and Technology; - ins: H. Duan name: Haixin Duan organization: Tsinghua University, Tsinghua National Laboratory for Information Science and Technology, and International Computer Science Institute; - ins: S. Chen name: Shuo Chen organization: Microsoft Research Redmond; - ins: T. Wan name: Tao Wan organization: Huawei Canada - ins: N. Weaver name: Nicholas Weaver organization: International Computer Science Institute and University of California, Berkeley COOKIE-PREFIXES: target: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-prefixes title: "Cookie Prefixes" date: 2016 author: - ins: M. West name: Mike West organization: Google, Inc HSTS-PRELOADING: target: https://hstspreload.appspot.com/ title: "HSTS Preload Submission" RFC6797:
--- abstract
This document updates RFC6265 by removing the ability for a non-secure origin to set cookies with a 'secure' flag, and to overwrite cookies whose 'secure' flag is set. This deprecation improves the isolation between HTTP and HTTPS origins, and reduces the risk of malicious interference.
--- note_Note_to_Readers
Discussion of this draft takes place on the HTTP working group mailing list ([email protected]), which is archived at https://lists.w3.org/Archives/Public/ietf-http-wg/.
Working Group information can be found at http://httpwg.github.io/; source code and issues list for this draft can be found at https://github.com/httpwg/http-extensions/labels/cookie-alone.
--- middle
Section 8.5 and Section 8.6 of {{RFC6265}} spell out some of the drawbacks of cookies' implementation: due to historical accident, non-secure origins can set cookies which will be delivered to secure origins in a manner indistinguishable from cookies set by that origin itself. This enables a number of attacks, which have been recently spelled out in some detail in {{COOKIE-INTEGRITY}}.
We can mitigate the risk of these attacks by making it more difficult for non-secure origins to influence the state of secure origins. Accordingly, this document recommends the deprecation and removal of non-secure origins' ability to write cookies with a 'secure' flag, and their ability to overwrite cookies whose 'secure' flag is set.
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 {{RFC2119}}.
The scheme
component of a URI is defined in Section 3 of {{RFC3986}}.
This document updates Section 5.3 of {{RFC6265}} as follows:
-
After step 8 of the current algorithm, which sets the cookie's
secure-only-flag
, execute the following step:- If the
scheme
component of therequest-uri
does not denote a "secure" protocol (as defined by the user agent), and the cookie'ssecure-only-flag
istrue
, then abort these steps and ignore the newly created cookie entirely.
- If the
-
Before step 11, execute the following step:
-
If the newly created cookie's
secure-only-flag
is not set, and thescheme
component of therequest-uri
does not denote a "secure" protocol, then abort these steps and ignore the newly created cookie entirely if the cookie store contains one or more cookies that meet all of the following criteria:-
Their
name
matches thename
of the newly created cookie. -
Their
secure-only-flag
is set. -
Their
domain
domain-matches thedomain
of the newly created cookie, or vice-versa. -
The
path
of the newly created cookie path-matches thepath
of the existing cookie.
Note: The
path
comparison is not symmetric, ensuring only that a newly-created non-secure cookie does not overlay an existing secure cookie, providing some mitigation against cookie fixing attacks. That is, given an existing secure cookie nameda
with apath
of/login
, a non-secure cookie nameda
could be set for apath
of/
or/foo
, but not for apath
of/login
or/login/en
.Note: This allows "secure" pages to override
secure
cookies with non-secure variants. Perhaps we should restrict that as well? -
-
-
In order to ensure that a non-secure site can never cause a
secure
cookie to be evicted, adjust the "remove excess cookies" priority order at the bottom of Section 5.3 to be the following:-
Expired cookies.
-
Cookies whose
secure-only-flag
is not set and which share adomain
field with more than a predetermined number of other cookies. -
Cookies that share a
domain
field with more than a predetermined number of other cookies. -
All cookies.
Note that the eviction algorithm specified here is triggered only after insertion of a cookie which causes the user agent to exceed some predetermined upper bound. Conforming user agents MUST ensure that inserting a non-secure cookie does not cause a secure cookie to be removed.
-
This specification increases a site's confidence that secure cookies it sets will remain unmodified by insecure pages on hosts which it domain-matches. Ideally, sites would use HSTS as described in {{RFC6797}} to defend more robustly against the dangers of non-secure transport in general, but until adoption of that protection becomes ubiquitous, this deprecation this document recommends will mitigate a number of risks.
The mitigations in this document do not, however, give complete confidence that
a given cookie was set securely. If an attacker is able to impersonate a
response from http://example.com/
before a user visits https://example.com/
,
the user agent will accept any cookie that the insecure origin sets, as the
"secure" cookie won't yet be present in the user agent's cookie store. An
active network attacker may still be able to use this ability to mount an attack
against example.com
, even if that site uses HTTPS exclusively.
The proposal in {{COOKIE-PREFIXES}} could mitigate this risk, as could
"preloading" HSTS for example.com
into the user agent {{HSTS-PRELOADING}}.
--- back
Richard Barnes encouraged a formalization of the deprecation proposal. {{COOKIE-INTEGRITY}} was a useful exploration of the issues {{RFC6265}} described.
- Issue 223 addressed by adding a path-match constraint to the storage algorithm for non-secure cookies. This ensures that non-secure cookies cannot overlay secure cookies for a given path, but allows secure and non-secure cookies with the same name to exist on distinct paths.