<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc version 1.6.17 (Ruby 2.6.4) -->
<?rfc tocindent="yes"?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc-ext html-pretty-print="prettyprint https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"?>
<rfc xmlns:x="http://purl.org/net/xml2rfc/ext"
      category="std"
      consensus="true"
      docName="draft-ietf-httpbis-cookie-alone-latest"
      ipr="trust200902"
      sortRefs="true"
      symRefs="true"
      tocInclude="true"
      updates="6265">
   <x:feedback template="mailto:quic@ietf.org?subject={docname},%20%22{section}%22\&amp;amp;body=%3c{ref}%3e:"/>
   <front>
      <title abbrev="Leave Secure Cookies Alone">Deprecate modification of 'secure' cookies from non-secure origins</title>
      <author fullname="Mike West" initials="M." surname="West">
         <organization>Google, Inc</organization>
         <address>
            <email>mkwst@google.com</email>
            <uri>https://mikewest.org/</uri>
         </address>
      </author>
      <date year="2018"/>
      <area>Applications and Real-Time</area>
      <workgroup>HTTP</workgroup>
      <keyword>Cookie</keyword>
      <abstract>
         <t>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.</t>
      </abstract>
      <note title="Note to Readers">
         <t>Discussion of this draft takes place on the HTTP working group mailing list (ietf-http-wg@w3.org), which is archived at <eref target="https://lists.w3.org/Archives/Public/ietf-http-wg/">https://lists.w3.org/Archives/Public/ietf-http-wg/</eref>.</t>
         <t>Working Group information can be found at <eref target="http://httpwg.github.io/">http://httpwg.github.io/</eref>; source code and issues list for this draft can be found at <eref target="https://github.com/httpwg/http-extensions/labels/cookie-alone">https://github.com/httpwg/http-extensions/labels/cookie-alone</eref>.</t>
      </note>
   </front>
   <middle>
      <section anchor="introduction">
         <name>Introduction</name>
         <t>Section 8.5 and <xref target="RFC6265" x:fmt="of" x:sec="8.6"/> 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 <xref target="COOKIE-INTEGRITY"/>.</t>
         <t>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.</t>
      </section>
      <section anchor="terminology-and-notation">
         <name>Terminology and notation</name>
         <t>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 <xref target="RFC2119"/>.</t>
         <t>The <spanx style="verb">scheme</spanx> component of a URI is defined in <xref target="RFC3986" x:fmt="of" x:sec="3"/>.</t>
      </section>
      <section anchor="recommendations">
         <name>Recommendations</name>
         <t>This document updates <xref target="RFC6265" x:fmt="of" x:sec="5.3"/> as follows:</t>
         <t>
            <list style="numbers">
               <t>After step 8 of the current algorithm, which sets the cookie's <spanx style="verb">secure-only-flag</spanx>, execute the following step: <list style="numbers">
                     <t>If the <spanx style="verb">scheme</spanx> component of the <spanx style="verb">request-uri</spanx> does not denote a "secure" protocol (as defined by the user agent), and the cookie's <spanx style="verb">secure-only-flag</spanx> is <spanx style="verb">true</spanx>, then abort these steps and ignore the newly created cookie entirely.</t>
                  </list>
               </t>
               <t>Before step 11, execute the following step: <list style="numbers">
                     <t>If the newly created cookie's <spanx style="verb">secure-only-flag</spanx> is not set, and the <spanx style="verb">scheme</spanx> component of the <spanx style="verb">request-uri</spanx> 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: <list style="numbers">
                           <t>Their <spanx style="verb">name</spanx> matches the <spanx style="verb">name</spanx> of the newly created cookie.</t>
                           <t>Their <spanx style="verb">secure-only-flag</spanx> is set.</t>
                           <t>Their <spanx style="verb">domain</spanx> domain-matches the <spanx style="verb">domain</spanx> of the newly created cookie, or vice-versa.</t>
                           <t>The <spanx style="verb">path</spanx> of the newly created cookie path-matches the <spanx style="verb">path</spanx> of the existing cookie.</t>
                        </list> Note: The <spanx style="verb">path</spanx> 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 named <spanx style="verb">a</spanx> with a <spanx style="verb">path</spanx> of <spanx style="verb">/login</spanx>, a non-secure cookie named <spanx style="verb">a</spanx> could be set for a <spanx style="verb">path</spanx> of <spanx style="verb">/</spanx> or <spanx style="verb">/foo</spanx>, but not for a <spanx style="verb">path</spanx> of <spanx style="verb">/login</spanx> or <spanx style="verb">/login/en</spanx>. <vspace blankLines="1"/> Note: This allows "secure" pages to override <spanx style="verb">secure</spanx> cookies with non-secure variants. Perhaps we should restrict that as well?</t>
                  </list>
               </t>
               <t>In order to ensure that a non-secure site can never cause a <spanx style="verb">secure</spanx> cookie to be evicted, adjust the "remove excess cookies" priority order at the bottom of Section 5.3 to be the following: <list style="numbers">
                     <t>Expired cookies.</t>
                     <t>Cookies whose <spanx style="verb">secure-only-flag</spanx> is not set and which share a <spanx style="verb">domain</spanx> field with more than a predetermined number of other cookies.</t>
                     <t>Cookies that share a <spanx style="verb">domain</spanx> field with more than a predetermined number of other cookies.</t>
                     <t>All cookies.</t>
                  </list> 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.</t>
            </list>
         </t>
      </section>
      <section anchor="security-considerations">
         <name>Security Considerations</name>
         <t>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 <xref target="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.</t>
         <t>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 <spanx style="verb">http://example.com/</spanx> before a user visits <spanx style="verb">https://example.com/</spanx>, 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 <spanx style="verb">example.com</spanx>, even if that site uses HTTPS exclusively.</t>
         <t>The proposal in <xref target="COOKIE-PREFIXES"/> could mitigate this risk, as could "preloading" HSTS for <spanx style="verb">example.com</spanx> into the user agent <xref target="HSTS-PRELOADING"/>.</t>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="RFC2119">
            <front>
               <title>Key words for use in RFCs to Indicate Requirement Levels</title>
               <author fullname="S. Bradner" initials="S." surname="Bradner"/>
               <date month="March" year="1997"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="2119"/>
            <seriesInfo name="DOI" value="10.17487/RFC2119"/>
         </reference>
         <reference anchor="RFC3986">
            <front>
               <title>Uniform Resource Identifier (URI): Generic Syntax</title>
               <author fullname="T. Berners-Lee" initials="T." surname="Berners-Lee"/>
               <author fullname="R. Fielding" initials="R." surname="Fielding"/>
               <author fullname="L. Masinter" initials="L." surname="Masinter"/>
               <date month="January" year="2005"/>
            </front>
            <seriesInfo name="STD" value="66"/>
            <seriesInfo name="RFC" value="3986"/>
            <seriesInfo name="DOI" value="10.17487/RFC3986"/>
         </reference>
         <reference anchor="RFC6265">
            <front>
               <title>HTTP State Management Mechanism</title>
               <author fullname="A. Barth" initials="A." surname="Barth"/>
               <date month="April" year="2011"/>
            </front>
            <seriesInfo name="RFC" value="6265"/>
            <seriesInfo name="DOI" value="10.17487/RFC6265"/>
         </reference>
      </references>
      <references title="Informative References">
         <reference anchor="COOKIE-INTEGRITY"
                     target="https://www.usenix.org/conference/usenixsecurity15/technical-sessions/presentation/zheng">
            <front>
               <title>Cookies Lack Integrity: Real-World Implications</title>
               <author fullname="Xiaofeng Zheng" initials="X." surname="Zheng">
                  <organization>Tsinghua University and Tsinghua National Laboratory for Information Science and Technology</organization>
               </author>
               <author fullname="Jian Jiang" initials="J." surname="Jiang">
                  <organization>University of California, Berkeley</organization>
               </author>
               <author fullname="Jinjin Liang" initials="J." surname="Liang">
                  <organization>Tsinghua University and Tsinghua National Laboratory for Information Science and Technology;</organization>
               </author>
               <author fullname="Haixin Duan" initials="H." surname="Duan">
                  <organization>Tsinghua University, Tsinghua National Laboratory for Information Science and Technology, and International Computer Science Institute;</organization>
               </author>
               <author fullname="Shuo Chen" initials="S." surname="Chen">
                  <organization>Microsoft Research Redmond;</organization>
               </author>
               <author fullname="Tao Wan" initials="T." surname="Wan">
                  <organization>Huawei Canada</organization>
               </author>
               <author fullname="Nicholas Weaver" initials="N." surname="Weaver">
                  <organization>International Computer Science Institute and University of California, Berkeley</organization>
               </author>
               <date month="August" year="2015"/>
            </front>
         </reference>
         <reference anchor="COOKIE-PREFIXES"
                     target="https://tools.ietf.org/html/draft-ietf-httpbis-cookie-prefixes">
            <front>
               <title>Cookie Prefixes</title>
               <author fullname="Mike West" initials="M." surname="West">
                  <organization>Google, Inc</organization>
               </author>
               <date year="2016"/>
            </front>
         </reference>
         <reference anchor="HSTS-PRELOADING" target="https://hstspreload.appspot.com/">
            <front>
               <title>HSTS Preload Submission</title>
               <author/>
               <date year="n.d."/>
            </front>
         </reference>
         <reference anchor="RFC6797">
            <front>
               <title>HTTP Strict Transport Security (HSTS)</title>
               <author fullname="J. Hodges" initials="J." surname="Hodges"/>
               <author fullname="C. Jackson" initials="C." surname="Jackson"/>
               <author fullname="A. Barth" initials="A." surname="Barth"/>
               <date month="November" year="2012"/>
            </front>
            <seriesInfo name="RFC" value="6797"/>
            <seriesInfo name="DOI" value="10.17487/RFC6797"/>
         </reference>
      </references>
      <section anchor="acknowledgements">
         <name>Acknowledgements</name>
         <t>Richard Barnes encouraged a formalization of the deprecation proposal. <xref target="COOKIE-INTEGRITY"/> was a useful exploration of the issues <xref target="RFC6265"/> described.</t>
      </section>
      <section anchor="changes">
         <name>Changes</name>
         <section anchor="since-00">
            <name>Since -00</name>
            <t>
               <list style="symbols">
                  <t>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.</t>
               </list>
            </t>
         </section>
      </section>
   </back>
</rfc>
