<?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-prefixes-00"
      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>Cookie Prefixes</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 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 <spanx style="verb">Cookie</spanx> request header syntax, and limits the ways in which cookies may be abused in a conforming user agent.</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-prefixes">https://github.com/httpwg/http-extensions/labels/cookie-prefixes</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, 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 <spanx style="verb">Secure</spanx> (and possibly <spanx style="verb">HttpOnly</spanx>) flags set) remains intact and untouched by non-secure subdomains.</t>
         <t>We can't alter the syntax of the <spanx style="verb">Cookie</spanx> 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.</t>
         <t>This document describes such a scheme, which enables servers to set cookies which conforming user agents will ensure are <spanx style="verb">Secure</spanx>, and locked to a domain.</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="prefixes">
         <name>Prefixes</name>
         <section anchor="the-secure-prefix">
            <name>The "__Secure-" prefix</name>
            <t>If a cookie's name begins with "__Secure-", the cookie MUST be:</t>
            <t>
               <list style="numbers">
                  <t>Set with a <spanx style="verb">Secure</spanx> attribute</t>
                  <t>Set from a URI whose <spanx style="verb">scheme</spanx> is considered "secure" by the user agent.</t>
               </list>
            </t>
            <t>The following cookie would be rejected when set from any origin, as the <spanx style="verb">Secure</spanx> flag is not set</t>
            <figure>
               <artwork>
Set-Cookie: __Secure-SID=12345; Domain=example.com
</artwork>
            </figure>
            <t>While the following would be accepted if set from a secure origin (e.g. <spanx style="verb">https://example.com/</spanx>), and rejected otherwise:</t>
            <figure>
               <artwork>
Set-Cookie: __Secure-SID=12345; Secure; Domain=example.com
</artwork>
            </figure>
         </section>
         <section anchor="the-host-prefix">
            <name>The "__Host-" prefix</name>
            <t>If a cookie's name begins with "__Host-", the cookie MUST be:</t>
            <t>
               <list style="numbers">
                  <t>Set with a <spanx style="verb">Secure</spanx> attribute</t>
                  <t>Set from a URI whose <spanx style="verb">scheme</spanx> is considered "secure" by the user agent.</t>
                  <t>Sent only to the host which set the cookie. That is, a cookie named "__Host-cookie1" set from <spanx style="verb">https://example.com</spanx> MUST NOT contain a <spanx style="verb">Domain</spanx> attribute (and will therefore be sent only to <spanx style="verb">example.com</spanx>, and not to <spanx style="verb">subdomain.example.com</spanx>).</t>
                  <t>Sent to every request for a host. That is, a cookie named "__Host-cookie1" MUST contain a <spanx style="verb">Path</spanx> attribute with a value of "/".</t>
               </list>
            </t>
            <t>The following cookies would always be rejected:</t>
            <figure>
               <artwork>
Set-Cookie: __Host-SID=12345
Set-Cookie: __Host-SID=12345; Secure
Set-Cookie: __Host-SID=12345; Domain=example.com
Set-Cookie: __Host-SID=12345; Domain=example.com; Path=/
Set-Cookie: __Host-SID=12345; Secure; Domain=example.com; Path=/
</artwork>
            </figure>
            <t>While the following would be accepted if set from a secure origin (e.g. <spanx style="verb">https://example.com/</spanx>), and rejected otherwise:</t>
            <figure>
               <artwork>
Set-Cookie: __Host-SID=12345; Secure; Path=/
</artwork>
            </figure>
         </section>
      </section>
      <section anchor="user-agent-requirements">
         <name>User Agent Requirements</name>
         <t>This document updates <xref target="RFC6265" x:fmt="of" x:sec="5.3"/> as follows:</t>
         <t>After step 10 of the current algorithm, the cookies flags are set. Insert the following steps to perform the prefix checks this document specifies:</t>
         <t>
            <list style="numbers">
               <t>If the <spanx style="verb">cookie-name</spanx> begins with the string "__Secure-" or "__Host-", abort these steps and ignore the cookie entirely unless both of the following conditions are true: <list style="symbols">
                     <t>The cookie's <spanx style="verb">secure-only-flag</spanx> is <spanx style="verb">true</spanx>
                     </t>
                     <t>
                        <spanx style="verb">request-uri</spanx>'s <spanx style="verb">scheme</spanx> component denotes a "secure" protocol (as determined by the user agent)</t>
                  </list>
               </t>
               <t>If the <spanx style="verb">cookie-name</spanx> begins with the string "__Host-", abort these steps and ignore the cookie entirely unless the following conditions are true: <list style="symbols">
                     <t>The cookie's <spanx style="verb">host-only-flag</spanx> is <spanx style="verb">true</spanx>
                     </t>
                     <t>The cookie's <spanx style="verb">path</spanx> is "/"</t>
                  </list>
               </t>
            </list>
         </t>
      </section>
      <section anchor="aesthetic-considerations">
         <name>Aesthetic Considerations</name>
         <section anchor="not-pretty">
            <name>Not pretty.</name>
            <t>Prefixes are ugly. :(</t>
         </section>
         <section anchor="why-">
            <name>Why "__"?</name>
            <t>We started with <spanx style="verb">$</spanx>, but ran into issues with servers that had implemented <xref target="RFC2109"/>-style cookies. <spanx style="verb">__</spanx> is a prefix used for a number of well-known cookies in the wild (notably Google Analytics's <spanx style="verb">__ut*</spanx> cookies, and CloudFlare's <spanx style="verb">__cfduid</spanx>), and so is unlikely to produce such compatibility issues, while being uncommon enough to mitigate the risk of collisions.</t>
         </section>
      </section>
      <section anchor="security-considerations">
         <name>Security Considerations</name>
         <section anchor="secure-origins-only">
            <name>Secure Origins Only</name>
            <t>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 <xref target="SECURE-CONTEXTS"/>, <xref target="POWERFUL-FEATURES"/>, and <xref target="DEPRECATING-HTTP"/>). 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.</t>
            <t>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.</t>
         </section>
         <section anchor="limitations">
            <name>Limitations</name>
            <t>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 <spanx style="verb">User-Agent</spanx> request header, if such assurances were deemed necessary.</t>
         </section>
      </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="RFC2109">
            <front>
               <title>HTTP State Management Mechanism</title>
               <author fullname="D. Kristol" initials="D." surname="Kristol"/>
               <author fullname="L. Montulli" initials="L." surname="Montulli"/>
               <date month="February" year="1997"/>
            </front>
            <seriesInfo name="RFC" value="2109"/>
            <seriesInfo name="DOI" value="10.17487/RFC2109"/>
         </reference>
         <reference anchor="POWERFUL-FEATURES"
                     target="https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features">
            <front>
               <title>Prefer Secure Origins for Powerful New Features</title>
               <author fullname="Chris Palmer" initials="C." surname="Palmer"/>
               <date year="2015"/>
            </front>
         </reference>
         <reference anchor="SECURE-CONTEXTS"
                     target="https://w3c.github.io/webappsec-secure-contexts/">
            <front>
               <title>Secure Contexts</title>
               <author fullname="Mike West" initials="M." surname="West"/>
               <date year="2016"/>
            </front>
         </reference>
         <reference anchor="DEPRECATING-HTTP"
                     target="https://blog.mozilla.org/security/2015/04/30/deprecating-non-secure-http/">
            <front>
               <title>Deprecating Non-Secure HTTP</title>
               <author fullname="Richard Barnes" initials="R." surname="Barnes"/>
               <date day="30" month="April" year="2015"/>
            </front>
         </reference>
         <reference anchor="Lawrence2015"
                     target="http://textslashplain.com/2015/10/09/duct-tape-and-baling-wirecookie-prefixes/">
            <front>
               <title>Duct Tape and Baling Wire -- Cookie Prefixes</title>
               <author fullname="Eric Lawrence" initials="E." surname="Lawrence"/>
               <date day="09" month="October" year="2015"/>
            </front>
         </reference>
      </references>
      <section anchor="acknowledgements">
         <name>Acknowledgements</name>
         <t>Eric Lawrence had this idea a million years ago, and wrote about its genesis in <xref target="Lawrence2015"/>. Devdatta Akhawe helped justify the potential impact of the scheme on real-world websites. Thomas Broyer pointed out the issues with a leading <spanx style="verb">$</spanx> in the prefixes, and Brian Smith provided valuable contributions to the discussion around a replacement (ISO C indeed).</t>
      </section>
   </back>
</rfc>
