Picture a mail room. The front desk receives a stack of paper and passes it to the back office. Both need to agree where one letter ends and the next begins. If the front desk thinks it handed over one long letter, but the back office sees one short letter plus the first page of a second, that extra page gets stapled onto whatever arrives next, which is somebody else's letter.

That is HTTP request smuggling. It is also called a desync attack, and it was first documented in a 2005 Watchfire paper. It came back in a big way in 2019 when James Kettle at PortSwigger published HTTP Desync Attacks, and he showed in 2025 that it is still widespread with HTTP/1.1 must die, which also added newer variants such as 0.CL.

This post explains it with pictures and a tiny Python script you can run offline.

TL;DR

  • Modern sites put a proxy (CDN, load balancer, WAF) in front of the app server, and the two often reuse one connection for many users' requests.
  • HTTP/1.1 has two ways to say how long a body is: Content-Length and Transfer-Encoding: chunked. Send both, and each server may pick a different one.
  • The bytes one side ignores become the start of the next request, which belongs to someone else.
  • Fix: HTTP/2 end to end, or reject ambiguous requests and close the connection on any parse error.

Why there are two servers at all

Your browser rarely talks to the app directly. It talks to a front-end: Cloudflare, an AWS load balancer, nginx, HAProxy, a WAF. That front-end forwards requests to the back-end server, and for speed it keeps a few connections open and sends many users' requests down the same one, one after another.

This only works if both sides cut the stream in exactly the same places.

One connection shared by many users carries three pieces in a row: the attacker's POST, a hidden GET /admin prefix, and the victim's GET /cart. The proxy, which reads Content-Length, sees request 1 as the POST plus the prefix and request 2 as the victim's request. The server, which reads chunked, sees request 1 as the POST alone and request 2 as the prefix glued onto the victim's request.

Two ways to measure a body

An HTTP/1.1 request with a body has to say where the body stops. There are two ways:

  • Content-Length: 37 means "the body is exactly 37 bytes".
  • Transfer-Encoding: chunked means "the body comes in chunks, each prefixed with its size in hex, and a chunk of size 0 marks the end".

Both are fine on their own. The trouble starts when a request carries both and two servers resolve the conflict differently.

The actual bytes

Here is a classic CL.TE request: the front-end trusts Content-Length, the back-end trusts Transfer-Encoding.

The request byte for byte, with its CRLF line endings: POST /search HTTP/1.1, Host: shop.example, Content-Length: 37, Transfer-Encoding: chunked, a blank line, 0, a blank line, GET /admin HTTP/1.1, X-Ignore: X. The proxy reads the headers, then a 37-byte body as Content-Length says. The server reads the same headers, ends the body at the 0-size chunk, and leaves GET /admin HTTP/1.1 and X-Ignore: X over, read as the next request.

The front-end counts 37 bytes, sees one complete POST and forwards it. The back-end reads the chunked body, hits 0 and stops. The last two lines are still sitting on the connection. The back-end assumes they are the beginning of the next request and waits for the rest.

The next request on that connection belongs to another user. Their GET /cart with their session cookie gets appended to X-Ignore: X, so their real request line turns into a harmless header value, and the back-end serves GET /admin with the victim's cookie attached. The victim gets back a response to a request they never made. To read the /admin response themselves, attackers send their own follow-up request on the same connection instead of waiting for a victim.

Run it yourself (no network)

This script plays both servers on the same bytes. It never opens a socket, so it is safe to run anywhere.

"""Two toy HTTP/1.1 parsers read the same bytes. One trusts Content-Length, the other Transfer-Encoding. No network: it only shows where each one thinks the first request ends.""" BODY = b"0\r\n\r\nGET /admin HTTP/1.1\r\nX-Ignore: X" RAW = (b"POST /search HTTP/1.1\r\n" b"Host: shop.example\r\n" b"Content-Length: " + str(len(BODY)).encode() + b"\r\n" b"Transfer-Encoding: chunked\r\n" b"\r\n" + BODY) def split_head(buf): head, _, rest = buf.partition(b"\r\n\r\n") headers = dict(l.split(b": ", 1) for l in head.split(b"\r\n")[1:]) return headers, rest def front_end(buf): """Proxy that only looks at Content-Length.""" h, rest = split_head(buf) n = int(h[b"Content-Length"]) return rest[:n], rest[n:] def back_end(buf): """Server that honors chunked encoding (RFC 9112 says Transfer-Encoding wins when both are present).""" h, rest = split_head(buf) body = b"" while True: size_line, _, rest = rest.partition(b"\r\n") size = int(size_line, 16) if size == 0: return body, rest[2:] # skip the CRLF after the last chunk body, rest = body + rest[:size], rest[size + 2:] def show(b): for line in b.decode().rstrip("\r\n").split("\r\n"): print(" | " + line) fb, fleft = front_end(RAW) bb, bleft = back_end(RAW) print(f"front-end: Content-Length says the body is {len(fb)} bytes, {len(fleft)} left over -> ONE request") print(f"back-end : chunked body is {len(bb)} bytes, {len(bleft)} left over -> start of a SECOND request:") show(bleft) nxt = b"GET /cart HTTP/1.1\r\nHost: shop.example\r\nCookie: session=victim\r\n\r\n" print("the next user's request lands on the same connection, so the back-end reads:") show(bleft + nxt) 

Output:

front-end: Content-Length says the body is 37 bytes, 0 left over -> ONE request back-end : chunked body is 0 bytes, 32 left over -> start of a SECOND request: | GET /admin HTTP/1.1 | X-Ignore: X the next user's request lands on the same connection, so the back-end reads: | GET /admin HTTP/1.1 | X-Ignore: XGET /cart HTTP/1.1 | Host: shop.example | Cookie: session=victim 

Same bytes, two different answers, and that disagreement is the bug.

The family names

The variants are named by what the front-end reads, then what the back-end reads.

Table of four variants. CL.TE: the proxy trusts Content-Length, the server trusts Transfer-Encoding; the classic, used in this post. TE.CL: the mirror image. TE.TE: both trust Transfer-Encoding, but one side misses a malformed header. H2.CL and H2.TE: the proxy trusts the HTTP/2 frame length, the server trusts a smuggled CL or TE header; HTTP/2 in front, HTTP/1.1 behind.

The H2 variants matter because many teams think "we use HTTP/2, so we're fine". If the front-end downgrades to HTTP/1.1 for the back-end, the ambiguity comes right back. HTTP/2 removes this length ambiguity because every frame carries its own length, though buggy implementations still exist.

What an attacker gets, and what stops it

Two lists. What an attacker gets: past the proxy's access rules; a prefix glued onto a stranger's request; other users' requests, cookies included; a poisoned cache, served to everyone. What stops it: HTTP/2 end to end with no downgrade; reject requests with both length headers; normalize ambiguous requests or drop them; close the connection after a parse error; patch, then test with a smuggling scanner.

The fixes, in the order I would apply them:

  1. Use HTTP/2 from the front-end to the back-end. No downgrade means no Content-Length versus Transfer-Encoding ambiguity. Kettle's 2025 research makes this case strongly.
  2. Reject requests with both Content-Length and Transfer-Encoding. RFC 9112 says Transfer-Encoding wins and such a message "ought to be handled as an error" (section 6.3), that a proxy forwarding it must strip Content-Length first, and that a server must close the connection after responding (section 6.1). Rejecting it outright is simpler and safer.
  3. Normalize at the front-end. The proxy should rewrite every request into one clean, unambiguous form before forwarding, or refuse it. Malformed Transfer-Encoding headers (whitespace before the colon, values like chunked, identity, duplicate lines) get a 400, not a best guess.
  4. Close the connection on any parse error. A server that keeps the connection after a confusing request is the one that lets leftover bytes survive.
  5. Patch and test. Proxy and server vendors fix desync bugs regularly. Burp Suite's free HTTP Request Smuggler extension finds these in your own stack. Test only systems you own or are allowed to test.

Disabling connection reuse between the front-end and back-end also kills most variants, but it costs performance, so most teams treat it as a stopgap.

Why this keeps coming back

DNS tunneling, the subject of the previous post in this series, abuses a channel that everyone trusts. Request smuggling abuses the assumption that two well-behaved programs will read the same bytes the same way. Every new proxy, CDN feature or protocol downgrade is another chance for them not to.

If you run a proxy in front of anything, the one question to ask this week is: does every hop between the browser and the app speak HTTP/2, and if not, what does each hop do when it sees both length headers?

References