<?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.2.2 -->
<?rfc toc="yes"?>
<?rfc tocindent="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc docmapping="yes"?>
<rfc xmlns:x="http://purl.org/net/xml2rfc/ext"
     category="std"
     docName="draft-ietf-httpbis-replay-00"
     ipr="trust200902"
     submissionType="IETF">
   <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="HTTP Early Data">Using Early Data in HTTP</title>
      <author fullname="Martin Thomson" initials="M." surname="Thomson">
         <organization>Mozilla</organization>
         <address>
            <email>martin.thomson@gmail.com</email>
         </address>
      </author>
      <author fullname="Mark Nottingham" initials="M." surname="Nottingham">
         <organization>true</organization>
         <address>
            <email>mnot@mnot.net</email>
         </address>
      </author>
      <author fullname="Willy Tarreau" initials="W." surname="Tarreau">
         <organization>HAProxy Technologies</organization>
         <address>
            <email>willy@haproxy.org</email>
         </address>
      </author>
      <date day="06" month="September" year="2017"/>
      <area>Applications and Real-Time</area>
      <workgroup>httpbis</workgroup>
      <keyword>Internet-Draft</keyword>
      <abstract>
         <t>This document explains the risks of using early data for HTTP and describes techniques for reducing them. In particular, it defines a mechanism that enables clients to communicate with servers about early data, to assure correct operation.</t>
      </abstract>
   </front>
   <middle>
      <section anchor="introduction" title="Introduction">
         <t>TLS 1.3 <xref target="TLS13"/> introduces the concept of early data (also known as zero round trip data or 0-RTT data). Early data allows a client to send data to a server in the first round trip of a connection, without waiting for the TLS handshake to complete if the client has spoken to the same server recently.</t>
         <t>When used with HTTP <xref target="HTTP"/>, early data allows clients to send requests immediately, avoiding the one or two round trip delay needed for the TLS handshake. This is a significant performance enhancement; however, it has significant limitations.</t>
         <t>The primary risk of using early data is that an attacker might capture and replay the request(s) it contains. TLS <xref target="TLS13"/> describes techniques that can be used to reduce the likelihood that an attacker can successfully replay a request, but these techniques can be difficult to deploy, and still leave some possibility of a successful attack.</t>
         <t>Note that this is different from automated or user-initiated retries; replays are initiated by an attacker without the awareness of the client.</t>
         <t>To help mitigate the risk of replays in HTTP, this document gives an overview of techniques for controlling these risks in servers, and defines requirements for clients when sending requests in early data.</t>
         <t>The advice in this document also applies to use of 0-RTT in HTTP over QUIC <xref target="HQ"/>.</t>
         <section anchor="conventions-and-definitions"
                  title="Conventions and Definitions">
            <t>The words “MUST”, “MUST NOT”, “SHOULD”, and “MAY” are used in this document. It’s not shouting; when they are capitalized, they have the special meaning defined in <xref target="RFC2119"/>.</t>
         </section>
      </section>
      <section anchor="early-data-in-http" title="Early Data in HTTP">
         <t>Conceptually, early data is concatenated with other application to form a single stream. This can mean that requests are entirely contained within early data, or only part of a request is early. In a multiplexed protocol, like HTTP/2 <xref target="RFC7540"/> or HTTP/QUIC <xref target="HQ"/>, multiple requests might be partially delivered in early data.</t>
         <t>The model that this document assumes is that once the TLS handshake completes, the early data received on that TLS connection is known to not be a replayed copy of that data. However, it is important to note that this does not mean that early data will not be or has not been replayed on another connection.</t>
      </section>
      <section anchor="supporting-early-data-in-http-servers"
               title="Supporting Early Data in HTTP Servers">
         <t>A server decides whether or not to offer a client the ability to send early data on future connections when sending the TLS session ticket.</t>
         <t>When a server enables early data, there are a number of techniques it can use to mitigate the risks of replay:</t>
         <t>
            <list style="numbers">
               <t>TLS <xref target="TLS13"/> mandates the use of replay detection strategies that reduce the ability of an attacker to successfully replay early data. These anti-replay techniques reduce but don’t completely eliminate the chance of data being replayed and ensure a fixed upper limit to the number of replays.</t>
               <t>The server can choose whether it will process early data before the TLS handshake completes. By deferring processing, it can ensure that only a successfully completed connection is used for the request(s) therein. Assuming that a replayed ClientHello will not result in additional connections being made by the client, this provides the server with some assurance that the early data was not replayed.</t>
               <t>If the server receives multiple requests in early data, it can determine whether to defer HTTP processing on a per-request basis. This may require buffering the responses to preserve ordering in HTTP/1.1.</t>
               <t>The server can cause a client to retry a request and not use early data by responding with the 4NN (Too Early) status code (<xref target="status"/>), in cases where the risk of replay is judged too great.</t>
            </list>
         </t>
         <t>For a given request, the level of tolerance to replay risk is specific to the resource it operates upon (and therefore only known to the origin server). In general, if processing a request does not have state-changing side effects, the consequences of replay are not significant.</t>
         <t>The request method’s safety (<xref target="RFC7231" x:fmt="," x:sec="4.2.1"/>) is one way to determine this. However, some resources do elect to associate side effects with safe methods, so this cannot be universally relied upon.</t>
         <t>It is RECOMMENDED that origin servers allow resources to explicitly configure whether early data is appropriate in requests. Absent such explicit information, they SHOULD mitigate against early data in requests that have unsafe methods, using the techniques outlined above.</t>
         <t>A request might be sent partially in early data with the remainder of the request being sent after the handshake completes. This does not necessarily affect handling of that request; what matters is when the server starts acting upon the contents of a request. Any time a server might initiate processing prior to completion of the handshake it needs to consider how a possible replay of early data could affect that processing (see also <xref target="be-consistent"/>).</t>
         <t>A server can partially process requests that are incomplete. Parsing header fields - without acting on the values - and determining request routing is likely to be safe from side-effects, but other actions might not be.</t>
         <t>Intermediary servers do not have sufficient information to make this determination, so <xref target="status"/> describes a way for the origin to signal to them that a particular request isn’t appropriate for early data. Intermediaries that accept early data MUST implement that mechanism.</t>
         <t>Note that a server cannot choose to selectively reject early data at the TLS layer. TLS only permits a server to accept all early data, or none of it. Once a server has decided to accept early data, it MUST process all requests in early data, even if the server rejects the request by sending a 4NN (Too Early) response.</t>
         <t>A server can limit the amount of early data with the <spanx style="verb">max_early_data_size</spanx> field of the <spanx style="verb">early_data</spanx> TLS extension. This can be used to avoid committing an arbitrary amount of memory for deferred requests. A server SHOULD ensure that when it accepts early data, it can defer processing of requests until after the TLS handshake completes.</t>
      </section>
      <section anchor="using-early-data-in-http-clients"
               title="Using Early Data in HTTP Clients">
         <t>A client that wishes to use early data commences sending HTTP requests immediately after sending the TLS ClientHello.</t>
         <t>By their nature, clients have control over whether a given request is sent in early data – thereby giving the client control over risk of replay. Absent other information, clients MAY send requests with safe HTTP methods (see <xref target="RFC7231" x:fmt="," x:sec="4.2.1"/>) in early data when it is available, and SHOULD NOT send unsafe methods (or methods whose safety is not known) in early data.</t>
         <t>If the server rejects early data at the TLS layer, a client MUST start sending again as though the connection was new. For HTTP/2, this means re-sending the connection preface. Any requests sent in early data MUST be sent again, unless the client decides to abandon those requests.</t>
         <t>This automatic retry exposes the request to a potential replay attack. An attacker sends early data to one server instance that accepts and processes the early data, but allows that connection to proceed no further. The attacker then forwards the same messages from the client to another server instance that will reject early data. The client the retries the request, resulting in the request being processed twice. Replays are also possible if there are multiple server instances that will accept early data, or if the same server accepts early data multiple times (though this would be in violation of requirements in TLS).</t>
         <t>Clients that use early data MUST retry requests upon receipt of a 4NN (Too Early) status code; see <xref target="status"/>.</t>
         <t>An intermediary MUST NOT use early data when forwarding a request unless early data was used on a previous hop, or it knows that the request can be retried safely without consequences (typically, using out-of-band configuration). Absent better information, that means that an intermediary can only use early data if the request either arrived in early data or arrived with the <spanx style="verb">Early-Data</spanx> header field set to “1”.</t>
      </section>
      <section anchor="extensions-for-early-data-in-http"
               title="Extensions for Early Data in HTTP">
         <t>Because HTTP requests can span multiple “hops”, it is necessary to explicitly communicate whether a request has been sent in early data on a previous connection. Likewise, some means of explicitly triggering a retry when early data is not desirable is necessary. Finally, it is necessary to know whether the client will actually perform such a retry.</t>
         <t>To meet these needs, two signalling mechanisms are defined:</t>
         <t>
            <list style="symbols">
               <t>The <spanx style="verb">Early-Data</spanx> header field is included in requests that are received in early data.</t>
               <t>The 4NN (Too Early) status code is defined for a server to indicate that a request could not be processed due to the consequences of a possible replay attack.</t>
            </list>
         </t>
         <t>They are designed to enable better coordination of the use of early data between the user agent and origin server, and also when a gateway (also “reverse proxy”, “Content Delivery Network”, or “surrogate”) is present.</t>
         <t>Gateways typically don’t have specific information about whether a given request can be processed safely when it is sent in early data. In many cases, only the origin server has the necessary information to decide whether the risk of replay is acceptable. These extensions allow coordination between a gateway and its origin server.</t>
         <section anchor="header" title="The Early-Data Header Field">
            <t>The <spanx style="verb">Early-Data</spanx> request header field indicates that the request has been conveyed in early data, and additionally indicates that a client understands the 4NN (Too Early) status code.</t>
            <t>It has just one valid value: “1”. Its syntax is defined by the following ABNF <xref target="ABNF"/>:</t>
            <figure>
               <artwork>
Early-Data = "1"
</artwork>
            </figure>
            <t>For example:</t>
            <figure>
               <artwork>
GET /resource HTTP/1.0
Host: example.com
Early-Data: 1
</artwork>
            </figure>
            <t>An intermediary that forwards a request received in TLS early data MUST send it with the <spanx style="verb">Early-Data</spanx> header field set to “1” (i.e., it adds it if not present in the request).</t>
            <t>An intermediary MUST NOT remove this header field if it is present in a request.</t>
            <t>The <spanx style="verb">Early-Data</spanx> header field is not intended for use by user agents (that is, the original initiator of a request). Sending a request in early data implies that the client understands this specification and is willing to retry a request in response to a 4NN (Too Early) status code. A user agent that sends a request in early data does not need to include the <spanx style="verb">Early-Data</spanx> header field.</t>
            <t>A server cannot make a request that contains the Early-Data header field safe for processing by waiting for the handshake to complete. A request that is marked with Early-Data was sent in early data on a previous hop. Requests that contain the Early-Data field and cannot be safely processed MUST be rejected using the 4NN (Too Early) status code.</t>
         </section>
         <section anchor="status" title="The 4NN (Too Early) Status Code">
            <t>A 4NN (Too Early) status code indicates that the server is unwilling to risk processing a request that might be replayed.</t>
            <t>Clients (user-agents and intermediaries) that sent the request in early data MUST automatically retry the request when receiving a 4NN (Too Early) response status code. Such retries MUST NOT be sent in early data, and SHOULD NOT be sent if the TLS handshake on the original connection does not successfully complete.</t>
            <t>Intermediaries that receive a 4NN (Too Early) status code MAY automatically retry requests after allowing the handshake to complete unless the original request contained the <spanx style="verb">Early-Data</spanx> header field when it was received. Otherwise, an intermediary MUST forward the 4NN (Too Early) status code.</t>
            <t>The server cannot assume that a client is able to retry a request unless the request is received in early data or the <spanx style="verb">Early-Data</spanx> header field is set to “1”. A server SHOULD NOT emit the 4NN status code unless one of these conditions is met.</t>
            <t>The 4NN (Too Early) status code is not cacheable by default. Its payload is not the representation of any identified resource.</t>
         </section>
      </section>
      <section anchor="security-considerations" title="Security Considerations">
         <t>Using early data exposes a client to the risk that their request is replayed. A retried or replayed request can produce different side effects on the server. In addition to those side effects, replays and retries might be used for traffic analysis to recover information about requests or the resources those requests target.</t>
         <section anchor="gateways-and-early-data" title="Gateways and Early Data">
            <t>A gateway that forwards requests that were received in early data MUST only do so if it knows that the server that receives those requests understands the <spanx style="verb">Early-Data</spanx> header field and will correctly generate a 4NN (Too Early) status code. A gateway that isn’t certain about server support SHOULD either delay forwarding the request until the TLS handshake completes, or send a 4NN (Too Early) status code in response. A gateway that is uncertain about whether an origin server supports the <spanx style="verb">Early-Data</spanx> header field SHOULD disable early data.</t>
         </section>
         <section anchor="be-consistent" title="Consistent Handling of Early Data">
            <t>Consistent treatment of a request that arrives in - or partially in - early data is critical to avoiding inappropriate processing of replayed requests. If a request is not safe to process before the TLS handshake completes, then all instances of the server need to agree and either reject the request or delay processing.</t>
         </section>
         <section anchor="denial-of-service" title="Denial of Service">
            <t>Accepting early data exposes a server to potential denial of service through the replay of requests that are expensive to handle. A server that is under load SHOULD prefer rejecting TLS early data as a whole rather than accepting early data and selectively processing requests. Generating a 503 (Service Unavailable) or 4NN (Too Early) status code often leads to clients retrying requests, which could result in increased load.</t>
         </section>
      </section>
      <section anchor="iana-considerations" title="IANA Considerations">
         <t>This document registers the <spanx style="verb">Early-Data</spanx> header field in the “Message Headers” registry <xref target="HEADERS"/>.</t>
         <t>
            <list style="hanging">
               <t hangText="Header field name:">Early-Data</t>
               <t hangText="Applicable protocol:">http</t>
               <t hangText="Status:">standard</t>
               <t hangText="Author/Change controller:">IETF</t>
               <t hangText="Specification document(s):">This document</t>
               <t hangText="Related information:">(empty)</t>
            </list>
         </t>
         <t>This document registers the 4NN (Too Early) status code in the “Hypertext Transfer Protocol (HTTP) Status Code” registry established in <xref target="RFC7231"/>.</t>
         <t>
            <list style="hanging">
               <t hangText="Value:">4NN</t>
               <t hangText="Description:">Too Early</t>
               <t hangText="Reference:">This document</t>
            </list>
         </t>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="TLS13">
            <front>
               <title>The Transport Layer Security (TLS) Protocol Version 1.3</title>
               <author fullname="Eric Rescorla" initials="E" surname="Rescorla"/>
               <date day="3" month="July" year="2017"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-tls-tls13-21"/>
         </reference>
         <reference anchor="HTTP">
            <front>
               <title>Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7230"/>
            <seriesInfo name="DOI" value="10.17487/RFC7230"/>
         </reference>
         <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="RFC7231">
            <front>
               <title>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7231"/>
            <seriesInfo name="DOI" value="10.17487/RFC7231"/>
         </reference>
         <reference anchor="ABNF">
            <front>
               <title>Augmented BNF for Syntax Specifications: ABNF</title>
               <author fullname="D. Crocker"
                       initials="D."
                       role="editor"
                       surname="Crocker"/>
               <author fullname="P. Overell" initials="P." surname="Overell"/>
               <date month="January" year="2008"/>
            </front>
            <seriesInfo name="STD" value="68"/>
            <seriesInfo name="RFC" value="5234"/>
            <seriesInfo name="DOI" value="10.17487/RFC5234"/>
         </reference>
         <reference anchor="HEADERS">
            <front>
               <title>Registration Procedures for Message Header Fields</title>
               <author fullname="G. Klyne" initials="G." surname="Klyne"/>
               <author fullname="M. Nottingham" initials="M." surname="Nottingham"/>
               <author fullname="J. Mogul" initials="J." surname="Mogul"/>
               <date month="September" year="2004"/>
            </front>
            <seriesInfo name="BCP" value="90"/>
            <seriesInfo name="RFC" value="3864"/>
            <seriesInfo name="DOI" value="10.17487/RFC3864"/>
         </reference>
      </references>
      <references title="Informative References">
         <reference anchor="HQ">
            <front>
               <title>Hypertext Transfer Protocol (HTTP) over QUIC</title>
               <author fullname="Mike Bishop" initials="M" surname="Bishop"/>
               <date day="16" month="August" year="2017"/>
            </front>
            <seriesInfo name="Internet-Draft" value="draft-ietf-quic-http-05"/>
         </reference>
         <reference anchor="RFC7540">
            <front>
               <title>Hypertext Transfer Protocol Version 2 (HTTP/2)</title>
               <author fullname="M. Belshe" initials="M." surname="Belshe"/>
               <author fullname="R. Peon" initials="R." surname="Peon"/>
               <author fullname="M. Thomson"
                       initials="M."
                       role="editor"
                       surname="Thomson"/>
               <date month="May" year="2015"/>
            </front>
            <seriesInfo name="RFC" value="7540"/>
            <seriesInfo name="DOI" value="10.17487/RFC7540"/>
         </reference>
      </references>
      <section anchor="acknowledgments" title="Acknowledgments">
         <t>This document was not easy to produce. The following people made substantial contributions to the quality and completeness of the document: Subodh Iyengar, Benjamin Kaduk, Ilari Liusavaara, Kazuho Oku, and Victor Vasiliev.</t>
      </section>
   </back>
</rfc>
