Skip to content

HTTP Request Smuggling, Explained: When Two Servers Disagree Where a Request Ends

Published Last updated 8 min read

Key takeaways

  • Request smuggling happens when a front-end proxy and a back-end server disagree about where one HTTP/1.1 request ends and the next one begins.
  • The classic case sends both Content-Length and Transfer-Encoding. The proxy trusts one header, the server trusts the other, and the leftover bytes get glued onto the next user's request.
  • It lets an attacker slip past the proxy's access rules, capture other users' requests and poison caches.
  • The strongest fix is HTTP/2 end to end with no downgrade to HTTP/1.1. Next best is to reject any request that carries both length headers and to close the connection after a parse error.

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.

The attacker sends one odd request to the front-end proxy, which reads Content-Length, and the proxy forwards it to the back-end server, which reads Transfer-Encoding chunked. On the shared connection the bytes are: the attacker's request, a hidden prefix, then the next user's request. The proxy sees the attacker's request plus hidden prefix as one request, then the user's request. The server sees the attacker's request end early, and treats the hidden prefix plus the user's request as request 2.

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 CL.TE request, line by line with its CRLF line endings: POST /search HTTP/1.1, Host: shop.example, Content-Length: 37, Transfer-Encoding: chunked, a blank line, then 0, a blank line, GET /admin HTTP/1.1, X-Ignore: X. The proxy trusts Content-Length, so the 37 bytes from 0 to X-Ignore: X are one body and it forwards one request. The server trusts chunked, so the chunk of size 0 means the body ends there. The leftover, GET /admin HTTP/1.1 and X-Ignore: X, sits on the connection as the start of 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.

Four variants. CL.TE: the proxy reads Content-Length, the server reads Transfer-Encoding; the classic, and the example in this post. TE.CL: the proxy reads Transfer-Encoding, the server reads Content-Length; the mirror image. TE.TE: both support chunked, but one is tricked into ignoring a malformed header such as a stray space or a second Transfer-Encoding line. H2.CL and H2.TE: the proxy speaks HTTP/2 to the client, then rewrites to HTTP/1.1 for the server and keeps a smuggled length header.

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

What an attacker gets: skip the proxy's access rules and reach /admin, glue a prefix onto a stranger's request, capture other users' requests including cookies, and poison a cache so everyone gets the attacker's response. What stops it: HTTP/2 all the way to the back-end with no downgrade, reject requests that carry both Content-Length and Transfer-Encoding, have the front-end normalize ambiguous requests or drop them, close the connection after any parsing error, and keep proxy and server software patched and tested 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

Frequently asked questions

Does HTTPS prevent HTTP request smuggling?
No. TLS protects the bytes between the client and the proxy. Smuggling is about how the proxy and the back-end interpret those bytes after decryption, so it works the same over HTTPS.
Does using HTTP/2 make me safe?
Only if HTTP/2 is used all the way to the back-end. Many setups speak HTTP/2 to the browser and rewrite to HTTP/1.1 for the server, which brings the ambiguity back and adds new variants such as H2.CL and H2.TE.
What does RFC 9112 say about a request with both Content-Length and Transfer-Encoding?
Transfer-Encoding overrides Content-Length, the message ought to be treated as an error because it may be a smuggling attempt (section 6.3), a proxy that forwards it must remove Content-Length first, and the server must close the connection after responding (section 6.1).
Share Share on X Share on LinkedIn

About the author

Portrait of Kiell Tampubolon

Security Engineer & Technical Writer

Security engineer and technical writer based in Batam, Indonesia. I review and harden MCP servers and AI agents, build security automation, and write up what holds and what fails. I also train on DNS security as a PANDI .id Academy trainer.

All writing | RSS | Markdown