<?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.23 -->

<!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-prefixes-00" category="std" updates="6265">

  <front>
    <title>Cookie Prefixes</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="2" day="23"/>

    <area>General</area>
    <workgroup>HTTP</workgroup>
    <keyword>Internet-Draft</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>


  </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, 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" 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="prefixes" title="Prefixes">

<section anchor="the-secure-prefix" title="The “__Secure-“ prefix">

<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><![CDATA[
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><![CDATA[
Set-Cookie: __Secure-SID=12345; Secure; Domain=example.com
]]></artwork></figure>

</section>
<section anchor="the-host-prefix" title="The “__Host-“ prefix">

<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><![CDATA[
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><![CDATA[
Set-Cookie: __Host-SID=12345; Secure; Path=/
]]></artwork></figure>

</section>
</section>
<section anchor="user-agent-requirements" title="User Agent Requirements">

<t>This document updates Section 5.3 of <xref target="RFC6265"/> 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" title="Aesthetic Considerations">

<section anchor="not-pretty" title="Not pretty.">

<t>Prefixes are ugly. :(</t>

</section>
<section anchor="why-" title="Why “__”?">

<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" title="Security Considerations">

<section anchor="secure-origins-only" title="Secure Origins Only">

<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" title="Limitations">

<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' 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='RFC2109' target='http://www.rfc-editor.org/info/rfc2109'>
<front>
<title>HTTP State Management Mechanism</title>
<author initials='D.' surname='Kristol' fullname='D. Kristol'><organization /></author>
<author initials='L.' surname='Montulli' fullname='L. Montulli'><organization /></author>
<date year='1997' month='February' />
<abstract><t>This 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]</t></abstract>
</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 initials="C." surname="Palmer" fullname="Chris Palmer">
      <organization></organization>
    </author>
    <date year="2015"/>
  </front>
</reference>
<reference anchor="SECURE-CONTEXTS" target="https://w3c.github.io/webappsec-secure-contexts/">
  <front>
    <title>Secure Contexts</title>
    <author initials="M." surname="West" fullname="Mike West">
      <organization></organization>
    </author>
    <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 initials="R." surname="Barnes" fullname="Richard Barnes">
      <organization></organization>
    </author>
    <date year="2015" month="April" day="30"/>
  </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 initials="E." surname="Lawrence" fullname="Eric Lawrence">
      <organization></organization>
    </author>
    <date year="2015" month="October" day="09"/>
  </front>
</reference>


    </references>


<section anchor="acknowledgements" title="Acknowledgements">

<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>

