<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ietf-httpbis-optimistic-upgrade-06" number="9931" category="std" consensus="true" submissionType="IETF" updates="9112, 9298" obsoletes="" tocInclude="true" sortRefs="true" symRefs="true" version="3" xml:lang="en">

  <front>
    <title abbrev="Optimistic HTTP Upgrade Security">Security Considerations for Optimistic Protocol Transitions in HTTP/1.1</title>
    <seriesInfo name="RFC" value="9931"/>
    <author fullname="Benjamin M. Schwartz" initials="B" surname="Schwartz">
      <organization>Meta Platforms, Inc.</organization>
      <address>
        <email>ietf@bemasc.net</email>
      </address>
    </author>
    <date year="2026" month="March"/>

    <area>WIT</area>
    <workgroup>httpbis</workgroup>

<keyword>Request Smuggling</keyword>
<keyword>False Start</keyword>
<keyword>HTTP CONNECT</keyword>

    <abstract>
<t>In HTTP/1.1, the client can request a change to a new protocol on the existing connection.  This document discusses the security considerations that apply to data sent by the client before this request is confirmed and adds new requirements to RFCs 9112 and 9298 to avoid related security issues.</t>
    </abstract>

  </front>
  <middle>

    <section anchor="overview">
      <name>Overview</name>
      <t>This document discusses certain security considerations that arise when switching from HTTP/1.1 to a different protocol on the same connection.  It provides:</t>
      <ul spacing="normal">
        <li>
          <t>a review of the relevant standards,</t>
        </li>
        <li>
          <t>a discussion of the security risks that may apply if a client sends data before the transition is confirmed,</t>
        </li>
        <li>
          <t>a security evaluation of existing upgrade tokens, and</t>
        </li>
        <li>
          <t>guidance for implementations and future standards documents.</t>
        </li>
      </ul>
      <t>Updates to <xref target="RFC9112"/> and <xref target="RFC9298"/>, including new normative requirements, are provided in Sections <xref target="connect" format="counter"/> and <xref target="connect-udp" format="counter"/>, respectively.</t>
    </section>
    <section anchor="conventions-and-definitions">
      <name>Requirements Language</name>
      <t>
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
    "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
    NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>",
    "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are
    to be interpreted as described in BCP&nbsp;14 <xref target="RFC2119"/>
    <xref target="RFC8174"/> when, and only when, they appear in all capitals,
    as shown here. 
</t>
    </section>    
    <section anchor="background">
      <name>Background</name>
      <t>In HTTP/1.1 <xref target="RFC9112"/> and later, a single connection can be used for many requests.  In HTTP/2 <xref target="RFC9113"/> and HTTP/3 <xref target="RFC9114"/>, these requests can be multiplexed, as each request is distinguished explicitly by its stream ID.  However, in HTTP/1.1, requests are strictly sequential, and each new request is distinguished implicitly by the closure of the preceding request.</t>
      <t>HTTP/1.1 is also the only version of HTTP that allows the client to change the protocol used for the remainder of the connection.  There are two mechanisms to request such a protocol transition.  One
mechanism is the Upgrade header field (<xref section="7.8" sectionFormat="comma" target="RFC9110"/>).  When included
in a request, this field indicates that the client would like to use this connection for
a protocol other than HTTP/1.1. The server replies with a 101 (Switching Protocols) status code if it accepts the protocol change (<xref section="15.2.2" sectionFormat="comma" target="RFC9110"/>).</t>
      <t>The other mechanism is the HTTP CONNECT method (<xref section="9.3.6" sectionFormat="of" target="RFC9110"/>).  This method indicates that the client wishes to establish a TCP connection to the specified host and port.  If accepted, the server replies with a 2xx (Successful) response to indicate that the request was accepted and a TCP connection was established.  After this point, the TCP connection is acting as a TCP tunnel, not an HTTP/1.1 connection.</t>
      <t>Both of these mechanisms also permit the server to reject the request.  For example, <xref target="RFC9110" section="7.8"/> says:</t>
      <blockquote>
        <t>A server <bcp14>MAY</bcp14> ignore a received Upgrade header field if it wishes to continue using the current protocol on that connection.</t>
      </blockquote>
      <t>and <xref target="RFC9110" section="9.3.6"/> says:</t>
      <blockquote>
        <t>A server <bcp14>MUST</bcp14> reject a CONNECT request that targets an empty or invalid port number, typically by responding with a 400 (Bad Request) status code.</t>
      </blockquote>
      <t>Rejected upgrades are common and can happen for a variety of reasons, such as:</t>
      <ul spacing="normal">
        <li>
          <t>The server does not support any of the client's indicated upgrade tokens (i.e., the client's proposed new protocols), so it continues to use HTTP/1.1.</t>
        </li>
        <li>
          <t>The server knows that an upgrade to the offered protocol will not provide any improvement over HTTP/1.1 for this request to this resource, so it chooses to respond in HTTP/1.1.</t>
        </li>
        <li>
          <t>The server requires the client to authenticate before upgrading the protocol, so it replies with the status code 401 (Authentication Required) and provides a challenge in an Authorization response header field (<xref section="11.6.2" sectionFormat="comma" target="RFC9110"/>).</t>
        </li>
        <li>
          <t>The resource has moved, so the server replies with a 3xx (Redirection) status code (<xref section="3.4" sectionFormat="comma" target="RFC9110"/>).</t>
        </li>
      </ul>
      <t>Similarly, servers frequently reject HTTP CONNECT requests, such as when:</t>
      <ul spacing="normal">
        <li>
          <t>The server does not support HTTP CONNECT.</t>
        </li>
        <li>
          <t>The specified destination is not allowed under server policy.</t>
        </li>
        <li>
          <t>The destination cannot be resolved, is unreachable, or does not accept the connection.</t>
        </li>
        <li>
          <t>The proxy requires the client to authenticate before proceeding.</t>
        </li>
      </ul>
      <t>After rejecting a request, the server will continue to interpret bytes received on that connection in accordance with HTTP/1.1.</t>
      <t><xref section="7.8" target="RFC9110"/> also states:</t>
      <blockquote>
        <t>A client cannot begin using an upgraded protocol on the connection until it has completely sent the request message (i.e., the client can't change the protocol it is sending in the middle of a message).</t>
      </blockquote>
      <t>In other words, completion of the request message is a <strong>necessary</strong> condition for the client to begin using the new protocol.  However, it is important to clarify that this is not a <strong>sufficient</strong> condition because the server might reject the request.</t>
      <t>In some cases, the client might predict that the server is likely to accept a requested protocol transition.  For example, if a request using an upgrade token recently succeeded, the client might expect that subsequent requests with the same upgrade token will also succeed.  If this expectation is correct, the client can often reduce delay by immediately sending the first bytes of the new protocol "optimistically", without waiting for the server's response.  This document explores the security implications of this "optimistic" behavior.</t>
    </section>
    <section anchor="possible-security-issues">
      <name>Possible Security Issues</name>
      <t>When there are only two distinct parties involved in an HTTP/1.1 connection (i.e., the client and the server), protocol transitions introduce no new security issues: Each party must already be prepared for the other to send arbitrary data on the connection at any time.  However, HTTP connections often involve more than two parties if the requests or responses include third-party data.  For example, a browser (party 1) might send an HTTP request to an origin (party 2) with the path, headers, or content controlled by a website from a different origin (party 3).  Post-transition protocols, such as WebSocket <xref target="RFC6455"/>, are also frequently used to convey data chosen by a third party.</t>
      <t>If the third-party data source is untrusted, then the data it provides is potentially "attacker-controlled".  The combination of attacker-controlled data and optimistic protocol transitions results in two significant security issues.</t>
      <section anchor="request-smuggling">
        <name>Request Smuggling</name>
        <t>In a Request Smuggling attack (<xref section="11.2" sectionFormat="comma" target="RFC9112"/>), the attacker-controlled data is chosen in such a way that it is interpreted by the server as an additional HTTP request.  These attacks allow the attacker to speak on behalf of the client while bypassing the client's own rules about what requests it will issue.  Request Smuggling can occur if the client and server have distinct interpretations of the data that flows between them.</t>
        <t>If the server accepts a protocol transition request, it interprets the subsequent bytes in accordance with the new protocol.  If it rejects the request, it interprets those bytes as HTTP/1.1.  However, the client cannot know which interpretation the server will take until it receives the server's response status code.  If it uses the new protocol optimistically, this creates a risk that the server will interpret attacker-controlled data in the new protocol as an additional HTTP request issued by the client.</t>
        <t>As a trivial example, consider an HTTP CONNECT client providing connectivity to an untrusted application.  If the client is authenticated to the proxy server using a connection-level authentication method such as TLS Client Certificates (<xref section="4.4.2" sectionFormat="comma" target="RFC8446"/>), the attacker could send an HTTP/1.1 POST request (<xref section="9.3.3" sectionFormat="comma" target="RFC9110"/>) for the proxy server at the beginning of its TCP connection.  If the client delivers this data optimistically, and the CONNECT request fails, the server would misinterpret the application's data as a subsequent authenticated request issued by the client.</t>
        <figure>
          <name>Example Request Smuggling Attack Using HTTP CONNECT</name>
          <artwork><![CDATA[
## REQUESTS ##

# The malicious application requests a TCP connection to a nonexistent
# destination, which will fail.
CONNECT no-such-destination.example:443 HTTP/1.1
Host: no-such-destination.example:443

# Before connection fails, the malicious application sends data on the
# proxied TCP connection that forms a valid POST request to the proxy.
# The vulnerable client optimistically forwards this data to the proxy.
POST /upload HTTP/1.1
Host: proxy.example
Content-Length: 123456

<POST body controlled by the malicious application>

## RESPONSES ##

# When TCP connection establishment fails, the proxy responds by
# rejecting the CONNECT request, but the client has already forwarded
# the malicious TCP payload data to the proxy.
HTTP/1.1 504 Gateway Timeout
Content-Length: 0

# The proxy interprets the smuggled POST request as coming from the
# client.  If connection-based authentication is in use (e.g., using
# TLS client certificate authentication), the proxy treats this
# malicious request as authenticated.
HTTP/1.1 200 OK
Content-Length: 0]]></artwork>
        </figure>
      </section>
      <section anchor="parser-exploits">
        <name>Parser Exploits</name>
        <t>A related category of attacks use protocol disagreement to exploit vulnerabilities in the server's request parsing logic.  These attacks apply when the HTTP client is trusted by the server, but the post-transition data source is not.  If the server software was developed under the assumption that some or all of the HTTP request data is not attacker-controlled, optimistic transmission can cause this assumption to be violated, exposing vulnerabilities in the server's HTTP request parser.</t>
      </section>
    </section>
    <section anchor="operational-issues">
      <name>Operational Issues</name>
      <t>If the server rejects the transition request, the connection can continue to be used for HTTP/1.1.  There is no general requirement to close the connection in response to a rejected transition, and keeping the connection open has performance advantages if additional HTTP requests to this server are likely.  Thus, it is normally inappropriate to close the connection in response to a rejected transition.</t>
    </section>
    <section anchor="existing">
      <name>Impact on HTTP Upgrade with Existing Upgrade Tokens</name>
      <t>This section describes the impact of this document's considerations on some registered upgrade tokens <xref target="IANA-UPGR"/> that are believed to be in use at the time of writing.</t>
      <section anchor="tls">
        <name>"TLS"</name>
        <t>The "TLS" family of upgrade tokens was defined in <xref target="RFC2817"/>, which correctly highlights the possibility of the server rejecting the upgrade. If a client ignores this possibility and sends TLS data optimistically, the result cannot be valid HTTP/1.1: The first octet of a TLS connection must be 22 (ContentType.handshake), but this is not an allowed character in an HTTP/1.1 method (see <xref section="5.1" sectionFormat="comma" target="RFC8446"/> and <xref section="3" sectionFormat="comma" target="RFC9112"/>).  A compliant HTTP/1.1 server will treat this as a parsing error and close the connection without processing further requests.</t>
      </section>
      <section anchor="websocketwebsocket">
        <name>"WebSocket"/"websocket"</name>
        <t><xref section="4.1" sectionFormat="of" target="RFC6455"/> says:</t>
        <blockquote>
          <t>Once the client's opening handshake has been sent, the client <bcp14>MUST</bcp14> wait for a response from the server before sending any further data.</t>
        </blockquote>
        <t>Thus, optimistic use of HTTP Upgrade is already forbidden in the WebSocket protocol.  Additionally, the WebSocket protocol requires high-entropy masking of client-to-server frames (<xref section="5.1" sectionFormat="of" target="RFC6455"/>).</t>
      </section>
      <section anchor="connect-udp">
        <name>"connect-udp"</name>
        <t><xref section="5" sectionFormat="of" target="RFC9298"/> says:</t>
        <blockquote>
          <t>A client <bcp14>MAY</bcp14> optimistically start sending UDP packets in HTTP Datagrams before receiving the response to its UDP proxying request.</t>
        </blockquote>
        <t>However, in HTTP/1.1, this "proxying request" is an HTTP Upgrade request.  This upgrade is likely to be rejected in certain circumstances, such as when the UDP destination address (which is attacker-controlled) is invalid.  Additionally, the contents of the "connect-udp" protocol stream can include untrusted material (i.e., the UDP packets, which might come from other applications on the client device).  This creates the possibility of Request Smuggling attacks.  To avoid these concerns, this document replaces that text to exclude HTTP/1.1 from any optimistic sending, as follows:</t>
	<blockquote>
            <t>A client <bcp14>MAY</bcp14> optimistically start sending UDP packets in HTTP Datagrams before receiving the response to its UDP proxying request but only if the HTTP version in use is HTTP/2 or later. Clients <bcp14>MUST NOT</bcp14> send UDP packets optimistically in HTTP/1.x due to the risk of Request Smuggling attacks.</t>
	</blockquote>
      </section>
      <section anchor="connect-ip">
        <name>"connect-ip"</name>
        <t>The "connect-ip" upgrade token is defined in <xref target="RFC9484"/>.  <xref section="11" sectionFormat="of" target="RFC9484"/> forbids clients from sending packets optimistically in HTTP/1.1, avoiding this issue.</t>
      </section>
    </section>
    <section anchor="guidance-for-future-upgrade-tokens">
      <name>Guidance for Future Upgrade Tokens</name>
      <t>There are now several good examples of designs that reduce or eliminate the security concerns discussed in this document and may be applicable in future specifications:</t>
      <ul spacing="normal">
        <li>
          <t>Forbid optimistic use of HTTP Upgrade (<xref section="4.1" sectionFormat="of" target="RFC6455"/> and <xref section="11" sectionFormat="of" target="RFC9484"/>).</t>
        </li>
        <li>
          <t>Embed a fixed preamble that deliberately terminates HTTP/1.1 processing (<xref section="3.4" sectionFormat="of" target="RFC9113"/>).</t>
        </li>
        <li>
          <t>Apply high-entropy masking of client-to-server data (<xref section="5.1" sectionFormat="of" target="RFC6455"/>).</t>
        </li>
      </ul>
      <t>Future specifications for upgrade tokens should account for the security issues discussed here and provide clear guidance on how implementations can avoid them.</t>
      <section anchor="selection-of-request-methods">
        <name>Selection of Request Methods</name>
        <t>Some upgrade tokens, such as "TLS", are defined for use with any ordinary HTTP method.  The upgraded protocol continues to provide HTTP semantics and will convey the response to this HTTP request.</t>
        <t>The other upgrade tokens mentioned in <xref target="existing"/> do not preserve HTTP semantics, so the method is not relevant.  All of these upgrade tokens are specified only for GET requests with no content.</t>
        <t>Future specifications for upgrade tokens should restrict their use to GET requests with no content if the HTTP method is otherwise irrelevant and the request does not need to carry any message content.  This improves consistency with other upgrade tokens and simplifies server implementation.</t>
      </section>
    </section>
    <section anchor="connect">
      <name>Requirements for HTTP CONNECT</name>
      <t>This document updates <xref target="RFC9112"/> to include the remaining text of this section.  The requirements in this section apply only to HTTP/1.1.</t>
      <t>Proxy clients that send CONNECT requests on behalf of untrusted TCP clients <bcp14>MUST</bcp14> do one or both of the following:</t>
      <ol spacing="normal" type="1">
	<li>
          <t>Wait for a 2xx (Successful) response before forwarding any TCP payload data.</t>
        </li>
        <li>
          <t>Send a "Connection: close" request header.</t>
        </li>
      </ol>
      <t>Proxy clients that don't implement at least one of these two behaviors are vulnerable to a trivial Request Smuggling attack (<xref section="11.2" sectionFormat="comma" target="RFC9112"/>).</t>
      <t>At the time of writing, some proxy clients are believed to be vulnerable as described.  As a mitigation, proxy servers <bcp14>MUST</bcp14> close the underlying connection when rejecting a CONNECT request without processing any further requests on that connection.  This requirement applies whether or not the request includes a "close" connection option.</t>
      <t>Note that this mitigation will frequently cause slower connection establishment for correctly implemented clients, especially when returning a 407 (Proxy Authentication Required) response.  This performance loss can be avoided by using HTTP/2 or HTTP/3, which are not vulnerable to this attack.</t>
      <t>As a performance optimization, proxy servers <bcp14>MAY</bcp14> disable this mitigation if the client is known to wait for a 2xx (Successful) response before forwarding untrusted TCP payload data (i.e., complying with item 1 above).  Proxy servers can identify compliant clients using the request's User-Agent header field and the user agent vendor's documentation regarding its compliance.</t>
    </section>
    <section anchor="security-considerations">
      <name>Security Considerations</name>
      <t>This document describes security considerations related to optimistic use of protocol transitions in HTTP/1.1.</t>
    </section>
    <section anchor="iana-considerations">
      <name>IANA Considerations</name>
      <t>This document has no IANA actions.</t>
    </section>
  </middle>
  <back>
    <displayreference target="RFC9112" to="HTTP/1.1"/>
    <displayreference target="RFC9113" to="HTTP/2"/>
    <displayreference target="RFC9114" to="HTTP/3"/>
    <displayreference target="RFC6455" to="WEBSOCKET"/>
    <displayreference target="RFC9110" to="HTTP"/>
    <displayreference target="RFC8446" to="TLS"/>
    <displayreference target="RFC9484" to="CONNECT-IP"/>
    <displayreference target="RFC9298" to="CONNECT-UDP"/>
    <references anchor="sec-combined-references">
      <name>References</name>
      <references anchor="sec-normative-references">
        <name>Normative References</name>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9112.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9110.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9298.xml"/>
      </references>
      <references anchor="sec-informative-references">
        <name>Informative References</name>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9113.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9114.xml"/>
        <reference anchor="IANA-UPGR" target="https://www.iana.org/assignments/http-upgrade-tokens/">
          <front>
            <title>Hypertext Transfer Protocol (HTTP) Upgrade Token Registry</title>
            <author>
              <organization>IANA</organization>
            </author>
          </front>
        </reference>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.6455.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8446.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2817.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9484.xml"/>
      </references>
    </references>

    <section numbered="false" anchor="acknowledgments">
      <name>Acknowledgments</name>
      <t>This document benefited from valuable reviews and suggestions by:</t>
      <ul spacing="normal">
        <li>
          <t><contact fullname="Mike Bishop"/></t>
        </li>
        <li>
          <t><contact fullname="Mohamed Boucadair"/></t>
        </li>
        <li>
          <t><contact fullname="Gorry Fairhurst"/></t>
        </li>
        <li>
          <t><contact fullname="Mark Nottingham"/></t>
        </li>
        <li>
          <t><contact fullname="Kazuho Oku"/></t>
        </li>
        <li>
          <t><contact fullname="Lucas Pardue"/></t>
        </li>
        <li>
          <t><contact fullname="David Schinazi"/></t>
        </li>
        <li>
          <t><contact fullname="Glenn Strauss"/></t>
        </li>
        <li>
          <t><contact fullname="Michael Sweet"/></t>
        </li>
        <li>
          <t><contact fullname="Willy Tarreau"/></t>
        </li>
        <li>
          <t><contact fullname="Martin Thomson"/></t>
        </li>
      </ul>

    </section>
  </back>

</rfc>
