http-request-smuggling web-security reverse-proxy http-desync penetration-testing

HTTP Request Smuggling: Exploiting Desync Vulnerabilities and Defending Modern Proxies

A practical intermediate-level guide to HTTP request smuggling: how Content-Length and Transfer-Encoding disagreements desynchronize front-end and back-end parsers, how CL.TE, TE.CL, and obfuscated variants are exploited in labs, and how to harden reverse proxies and load balancers.

11 min read

Introduction

Most production web applications are not a single process. A typical request passes through a CDN, a load balancer, a reverse proxy, and finally an application server or framework before reaching your code. Each hop parses the HTTP message independently, and each hop must agree on one deceptively simple question: where does this request end and the next one begin?

HTTP/1.1 gives two different mechanisms for answering that question — the Content-Length header and the Transfer-Encoding: chunked coding — and the protocol specification has historically permitted a degree of latitude in how conflicts between them are resolved. When two parsers in the same chain resolve the conflict differently, the connection becomes desynchronized. An attacker who can reliably cause that disagreement can append bytes to a request that the front end considers finished but the back end still considers part of the body. Those bytes become the prefix of the next request on that reused connection — which may belong to a different user.

This is HTTP request smuggling, and it is one of the highest-impact classes of web vulnerabilities because it attacks the infrastructure layer rather than the application layer. This article assumes you are working in an authorized lab or a system you own, and it uses PortSwigger’s Web Security Academy labs and self-hosted Docker setups as the reference environment. The techniques described are parser- and configuration-dependent; nothing here works universally.

Core Concepts

Framing: Content-Length versus chunked encoding

Content-Length is a decimal count of body bytes. It is simple, but it requires the sender to know the body size up front.

Transfer-Encoding: chunked allows streaming. The body is a sequence of chunks:

<hex-size>CRLF
<data>CRLF
<hex-size>CRLF
<data>CRLF
0CRLF
CRLF

A zero-length chunk followed by an empty line terminates the body. Trailers may follow the final CRLF. Because the parser must read chunk headers to find the end, a body with Transfer-Encoding: chunked has no fixed length.

Why ambiguity exists

A request that contains both headers is inherently ambiguous. RFC 9112 (which obsoletes RFC 7230) states that Transfer-Encoding overrides Content-Length, that such a message may indicate a smuggling attempt, and that a server should either reject it or, if it processes it, close the connection afterwards and remove Content-Length before forwarding downstream.

That guidance is exactly what many real deployments fail to do. Older proxies, custom middleware, HTTP client libraries, and language-specific servers have all, at some point, chosen one header over the other inconsistently. The result is a desync: the front end and back end disagree on the boundary.

The desync primitive

Back-end connections are pooled and reused for performance. Suppose the front end believes a request body is 13 bytes and forwards it. Suppose the back end believes the body is chunked and ends after 5 bytes. The front end then sends the next legitimate request down the same socket, and the back end — still expecting nothing — reads the residual bytes plus that request as a single new message. The attacker has effectively prepended data to someone else’s request.

The main variant families

VariantFront-end usesBack-end uses
CL.TEContent-LengthTransfer-Encoding
TE.CLTransfer-EncodingContent-Length
TE.TETransfer-Encoding (one variant)Transfer-Encoding (another variant)
CL.0Content-LengthIgnores body entirely
H2.CL / H2.TEHTTP/2 framingHTTP/1.1 after downgrade

TE.TE relies on obfuscating the Transfer-Encoding header so that one parser fails to recognize it and falls back to Content-Length semantics. CL.0 exploits routing rules where the back end does not expect a body on certain endpoints (for example, static file routes) and therefore ignores leftover bytes. H2.CL/H2.TE arise when an HTTP/2 front end downgrades to HTTP/1.1 and either forwards a client-supplied content-length verbatim or forwards a transfer-encoding header that HTTP/2 forbids (RFC 9113 permits only TE: trailers).

Practical Walkthrough

Assumptions and lab setup

These examples assume a lab deployment with a front-end proxy and a back-end HTTP/1.1 server connected over keep-alive, with the front end configured to forward requests without normalizing conflicting headers. PortSwigger’s Web Security Academy provides ready-made targets for each variant; self-hosted equivalents can be built with Docker (for example, an nginx or HAProxy front end in front of a Python or Node back end, deliberately misconfigured for testing). Note two prerequisites: the connection between hops must be reused, and the front end must not reject ambiguous requests. Neither is guaranteed in the wild.

CL.TE: front end trusts Content-Length, back end trusts chunked

POST / HTTP/1.1
Host: shop.example
Content-Length: 13
Transfer-Encoding: chunked

0

SMUGGLED

The front end reads exactly 13 bytes of body: 0, CRLF, CRLF, then SMUGGLED. It forwards all of it. The back end sees Transfer-Encoding: chunked, reads a zero-length chunk, and treats the body as complete after five bytes. The remaining eight bytes — SMUGGLED — stay in the socket buffer and are prepended to the next request the front end sends down that connection.

A realistic payload replaces SMUGGLED with a full request line and headers. A useful proof of concept is to smuggle a request that the front end would normally block, then observe the back end’s response:

POST / HTTP/1.1
Host: shop.example
Content-Length: 116
Transfer-Encoding: chunked

0

GET /admin HTTP/1.1
Host: shop.example
X-Ignore: X

The Content-Length must be adjusted so it exactly covers 0 + CRLF + CRLF + the smuggled request. If the front end enforces an access rule on /admin but the back end does not, the smuggled request reaches the protected route.

TE.CL: front end trusts chunked, back end trusts Content-Length

POST / HTTP/1.1
Host: shop.example
Content-Length: 3
Transfer-Encoding: chunked

8
SMUGGLED
0

The front end parses a valid chunked body: an 8-byte chunk containing SMUGGLED, then the terminating zero chunk. It forwards the whole body. The back end honours Content-Length: 3, consumes only the first three bytes (8, CRLF), and treats everything after — SMUGGLED, CRLF, 0, CRLF, CRLF — as the beginning of the next request. This variant requires the front end to actually validate the chunked body, which is why it is often harder to trigger than CL.TE.

Obfuscation techniques

Because TE.TE depends on getting one parser to ignore the header, practitioners try many syntactic variations. Common candidates include:

Transfer-Encoding: xchunked
Transfer-Encoding : chunked
Transfer-Encoding: chunked
Transfer-Encoding: identity
Transfer-Encoding: chunked
Transfer-Encoding: x
Transfer-Encoding:[tab]chunked
X: X
Transfer-Encoding: chunked

Related tricks target the chunk-size line itself: some parsers accept a vertical tab or form feed instead of CRLF, or tolerate leading whitespace before the hex size. Deprecated line folding (obs-fold) is another avenue against parsers that still support it.

These are hypotheses, not guarantees. The correct way to approach obfuscation is to enumerate the parsers in the chain, test each candidate against a lab instance, and measure — never assume a payload will work because it worked somewhere else.

Detecting a desync with timing

A common detection heuristic for CL.TE is to send a body that leaves the back end waiting for more chunk data:

POST / HTTP/1.1
Host: shop.example
Transfer-Encoding: chunked
Content-Length: 4

1
A
X

The front end forwards the first four bytes (1, CRLF, A). The back end starts a one-byte chunk, receives A, and then blocks waiting for the terminating CRLF. The response is delayed until the back end times out. A reproducible delay of several seconds, absent from an equivalent well-formed request, is a signal worth investigating.

Timing tests produce false positives (slow endpoints, rate limiters) and false negatives (fast timeouts, connection teardown). They should be corroborated with a differential-response test: smuggle a request for a path that returns a distinctive status or header, then send an innocuous follow-up request and check whether its response is the smuggled one. Burp Suite’s HTTP Request Smuggler extension automates much of this probing and is a reasonable starting point in a lab.

Security Implications

Bypassing front-end controls

The classic abuse is access-control bypass. Front-end proxies frequently enforce path-based rules — block /admin, require authentication on /api/internal, rate-limit /login. If the back end applies those rules differently, or not at all, a smuggled prefix that the front end never sees as a request can reach the protected handler.

Cache poisoning

When a shared cache sits in front of the application, a smuggled request can cause the next user’s request to be interpreted together with attacker-controlled data, storing an attacker-chosen response under a legitimate cache key. The poisoned entry then serves to every subsequent visitor. This turns a request-level primitive into a site-wide impact.

Capturing other users’ requests

An attacker can smuggle a request whose Content-Length is deliberately too large, so the back end keeps reading the body and appends the victim’s next request — including cookies and authorization headers — into a stored object the attacker can later retrieve. This is the most severe outcome and the reason request smuggling is treated as critical rather than informational.

Detection signals

From a defender’s perspective, smuggling often leaves traces: repeated 400 Bad Request or 501 Not Implemented responses clustered on one connection, front-end logs showing a different URL than back-end logs for the same transaction, unexpected latency spikes, connection resets while parsing bodies, and requests carrying both Content-Length and Transfer-Encoding. Correlating front-end and back-end access logs by connection identifier is one of the most effective detection techniques available.

Defensive Considerations

Prefer HTTP/2 end to end. Smuggling is fundamentally an HTTP/1.1 framing problem. If the front end and back end both speak HTTP/2 with binary framing, the classic CL.TE and TE.CL primitives largely disappear. Where downgrading is unavoidable, treat the downgrade path as a high-risk component and test it explicitly.

Reject ambiguity outright. Following RFC 9112, a server that receives both Content-Length and Transfer-Encoding should reject the message with a 400 and close the connection — or, if it must process it, strip Content-Length before forwarding and close the connection afterwards. It should also reject multiple Transfer-Encoding headers and any transfer coding it does not understand, rather than silently ignoring the header.

Normalize and validate header syntax. Reject whitespace between a header name and the colon, reject obs-fold, reject non-hexadecimal chunk sizes, and reject control characters in header values. Many smuggling variants survive only because one hop is lenient about syntax that another hop is strict about. Strictness must be consistent across every hop.

Avoid body-less back-end routes. CL.0 exploits endpoints where the back end does not expect a body. Ensure that any route the back end serves either consumes the body or causes the connection to be closed; never let a back end ignore bytes and keep the socket alive.

Do not rely on a WAF. A WAF in front of a vulnerable chain can be bypassed because the desync happens after inspection. WAFs may help with detection signatures, but the fix belongs in the parser configuration.

Reduce connection reuse where it is affordable. Disabling keep-alive between the front end and back end removes the shared-socket precondition for cross-user attacks. It costs performance and does not address self-contained smuggling, so treat it as defence in depth rather than a primary control.

Test continuously. Add regression tests that send conflicting Content-Length/Transfer-Encoding requests and chunked bodies with malformed size lines against staging deployments, and fail the build if any hop returns a success response instead of a 400. Track vendor advisories for every proxy, load balancer, and HTTP client library in the chain, and pin versions so that a silent upgrade on one hop does not introduce a parser mismatch.

Conclusion

HTTP request smuggling is not a bug in one library; it is a class of failures that emerges from composition. The individual components — a reverse proxy, a load balancer, an application server — may each be internally consistent and still disagree with one another about where a message ends. Attackers exploit that disagreement to bypass access controls, poison caches, and capture other users’ requests.

The practical lessons are straightforward. Understand the framing rules before attempting to exploit or defend them. Treat Content-Length and Transfer-Encoding coexisting in a single message as an error, not a preference to resolve. Keep parsing strictness uniform across every hop, and prefer HTTP/2 end to end where topology allows. And verify assumptions with real tests on lab instances: payload behaviour is highly deployment-specific, and a technique that works in one lab may be silently rejected by the next proxy in line.