<?xml version="1.0" encoding="UTF-8"?>
  <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
  <!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.0.30 -->

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
]>

<?rfc toc="yes"?>
<?rfc tocindent="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>

<rfc ipr="trust200902" docName="draft-ietf-httpbis-cookie-alone-01" category="std" updates="6265">

  <feedback xmlns='http://purl.org/net/xml2rfc/ext' template="mailto:ietf-http-wg@w3.org?subject={docname},%20%22{section}%22&amp;body=%3c{ref}%3e:"/><front>
    <title abbrev="Leave Secure Cookies Alone">Deprecate modification of 'secure' cookies from non-secure origins</title>

    <author initials="M." surname="West" fullname="Mike West">
      <organization>Google, Inc</organization>
      <address>
        <email>mkwst@google.com</email>
        <uri>https://mikewest.org/</uri>
      </address>
    </author>

    <date year="2016" month="9" day="5"/>

    <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" title="Introduction">

<t>Section 8.5 and Section 8.6 of <xref target="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 <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" title="Terminology and notation">

<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 Section 3 of <xref target="RFC3986"/>.</t>

</section>
<section anchor="recommendations" title="Recommendations">

<t>This document updates Section 5.3 of <xref target="RFC6265"/> 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" title="Security Considerations">

<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' target='http://www.rfc-editor.org/info/rfc2119'>
<front>
<title>Key words for use in RFCs to Indicate Requirement Levels</title>
<author initials='S.' surname='Bradner' fullname='S. Bradner'><organization /></author>
<date year='1997' month='March' />
<abstract><t>In 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.</t></abstract>
</front>
<seriesInfo name='BCP' value='14'/>
<seriesInfo name='RFC' value='2119'/>
<seriesInfo name='DOI' value='10.17487/RFC2119'/>
</reference>



<reference  anchor='RFC3986' target='http://www.rfc-editor.org/info/rfc3986'>
<front>
<title>Uniform Resource Identifier (URI): Generic Syntax</title>
<author initials='T.' surname='Berners-Lee' fullname='T. Berners-Lee'><organization /></author>
<author initials='R.' surname='Fielding' fullname='R. Fielding'><organization /></author>
<author initials='L.' surname='Masinter' fullname='L. Masinter'><organization /></author>
<date year='2005' month='January' />
<abstract><t>A 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]</t></abstract>
</front>
<seriesInfo name='STD' value='66'/>
<seriesInfo name='RFC' value='3986'/>
<seriesInfo name='DOI' value='10.17487/RFC3986'/>
</reference>



<reference  anchor='RFC6265' target='http://www.rfc-editor.org/info/rfc6265'>
<front>
<title>HTTP State Management Mechanism</title>
<author initials='A.' surname='Barth' fullname='A. Barth'><organization /></author>
<date year='2011' month='April' />
<abstract><t>This 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]</t></abstract>
</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 initials="X." surname="Zheng" fullname="Xiaofeng Zheng">
      <organization>Tsinghua University and Tsinghua National Laboratory for Information Science and Technology</organization>
    </author>
    <author initials="J." surname="Jiang" fullname="Jian Jiang">
      <organization>University of California, Berkeley</organization>
    </author>
    <author initials="J." surname="Liang" fullname="Jinjin Liang">
      <organization>Tsinghua University and Tsinghua National Laboratory for Information Science and Technology;</organization>
    </author>
    <author initials="H." surname="Duan" fullname="Haixin Duan">
      <organization>Tsinghua University, Tsinghua National Laboratory for Information Science and Technology, and International Computer Science Institute;</organization>
    </author>
    <author initials="S." surname="Chen" fullname="Shuo Chen">
      <organization>Microsoft Research Redmond;</organization>
    </author>
    <author initials="T." surname="Wan" fullname="Tao Wan">
      <organization>Huawei Canada</organization>
    </author>
    <author initials="N." surname="Weaver" fullname="Nicholas Weaver">
      <organization>International Computer Science Institute and University of California, Berkeley</organization>
    </author>
    <date year="2015" month="August"/>
  </front>
</reference>
<reference anchor="COOKIE-PREFIXES" target="https://tools.ietf.org/html/draft-ietf-httpbis-cookie-prefixes">
  <front>
    <title>Cookie Prefixes</title>
    <author initials="M." surname="West" fullname="Mike 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 >
      <organization></organization>
    </author>
    <date year="n.d."/>
  </front>
</reference>




<reference  anchor='RFC6797' target='http://www.rfc-editor.org/info/rfc6797'>
<front>
<title>HTTP Strict Transport Security (HSTS)</title>
<author initials='J.' surname='Hodges' fullname='J. Hodges'><organization /></author>
<author initials='C.' surname='Jackson' fullname='C. Jackson'><organization /></author>
<author initials='A.' surname='Barth' fullname='A. Barth'><organization /></author>
<date year='2012' month='November' />
<abstract><t>This specification defines a mechanism enabling web sites to declare themselves accessible only via secure connections and/or for users to be able to direct their user agent(s) to interact with given sites only over secure connections.  This overall policy is referred to as HTTP Strict Transport Security (HSTS).  The policy is declared by web sites via the Strict-Transport-Security HTTP response header field and/or by other means, such as user agent configuration, for example. [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='RFC' value='6797'/>
<seriesInfo name='DOI' value='10.17487/RFC6797'/>
</reference>




    </references>


<section anchor="acknowledgements" title="Acknowledgements">

<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" title="Changes">

<section anchor="since-00" title="Since -00">

<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>

