← Blog

LLM Request Smuggling with Content-Length and Transfer-Encoding

Parminder Singh
Parminder Singh··7 min read
Summarize with AI

LLM request smuggling begins when two HTTP recipients disagree about where one request ends and the next begins. Conflicting Content-Length and Transfer-Encoding fields are the classic fault line. In an AI gateway chain, the disagreement can place hidden bytes beyond the inspected prompt and ahead of the next authenticated request. This guide covers strict rejection, canonical reserialization, connection handling, protocol translation, and negative tests.

Problem-Awareai-securityllm-securitycybersecurityzero-trustinline-enforcement
LLM Request Smuggling with Content-Length and Transfer-Encoding

An HTTP/1.1 connection can carry several requests in sequence. Every recipient has to agree on the byte where one request ends. If an ingress proxy follows Content-Length while a downstream LLM adapter follows Transfer-Encoding, attacker-controlled bytes can become part of the first request for one parser and the start of a second request for the other. Authentication at the front door does not repair that disagreement.

TL;DR

  • Reject requests that contain both Content-Length and Transfer-Encoding; close the connection after the response.
  • Reject conflicting or invalid length fields, malformed chunk syntax, and transfer codings the gateway cannot decode.
  • Parse once, inspect the decoded prompt, then serialize one clean downstream request with fresh framing.
  • Test every HTTP version transition and verify that rejected bytes never enter a reusable provider connection.

Request smuggling is a disagreement between recipients

RFC 9112 Section 11.2 defines request smuggling as exploiting differences in protocol parsing among recipients to hide additional requests inside an apparently harmless request. The attack needs at least two parsers on a chain. An AI route often has several: a CDN, load balancer, API gateway, AI policy proxy, model adapter, and provider-facing client.

Each parser may receive a different protocol version or library-normalized view. One may tolerate whitespace that another rejects. One may combine duplicate fields. Another may honor Transfer-Encoding and ignore Content-Length. Persistent connections turn the leftover bytes into a second request.

The LLM-specific consequence is concrete. A gateway can inspect and approve one JSON prompt while an adapter interprets bytes after that prompt as another model call. The hidden call may inherit a pooled provider credential or land ahead of the next user's request on a shared connection. The vulnerability remains HTTP request smuggling. The protected asset happens to be an authenticated LLM route.

Content-Length and Transfer-Encoding define competing boundaries

Content-Length gives a decimal body length in octets. Transfer-Encoding: chunked frames the body as hexadecimal chunk sizes, chunk data, a zero-sized final chunk, and an optional trailer section. RFC 9112 Sections 6.1 through 6.3 define the precedence and error handling.

When both fields arrive, Transfer-Encoding overrides Content-Length under the specification. The combination can still signal smuggling because another recipient may implement different behavior. RFC 9112 allows a server to reject such a request or process only the transfer coding, but it requires connection closure after the response. An intermediary that forwards the message must remove Content-Length and process Transfer-Encoding first.

For an authenticated AI gateway, rejection is the better policy. The caller can send one unambiguous framing mode. Accepting ambiguous input creates no business value and expands the parser agreement the deployment must prove.

Duplicate lengths need exact handling

Multiple unequal Content-Length values make framing invalid. A repeated identical value can arise when an intermediary combines duplicate fields into a comma-separated list such as 42, 42. RFC 9112 permits a recipient to reject that form or replace it with one valid value.

Choose one deployment rule and apply it at every ingress. Strict rejection is simpler to test. If compatibility requires normalization of identical values, parse every member as a decimal integer, require exact equality, enforce an upper bound without integer overflow, and emit one canonical field. A value such as 42, 042 deserves rejection even if a permissive numeric conversion produces the same integer. Parser differentials thrive on representations that two libraries normalize differently.

Invalid signs, internal whitespace, empty members, huge numerals, and conflicting duplicates should return 400 followed by connection closure. The LLM gateway security guide puts this rejection before identity-bound prompt policy because a stable message boundary is a prerequisite for inspecting the prompt.

Chunked decoding has to finish before inspection is complete

A chunked message ends when the decoder reads a zero-sized chunk, processes any permitted trailers, and reaches the final empty line. Chunk sizes are hexadecimal. Chunk extensions can appear after the size. A gateway that scans raw network buffers for JSON boundaries has skipped HTTP parsing and created a second interpretation of the message.

Use one maintained HTTP parser at the byte-facing boundary. Enforce limits on total decoded body bytes, individual chunk size, extension bytes, chunk count, trailer bytes, and read duration. Reject bare line-ending variations or extension syntax that the deployed server and downstream stack would interpret differently. RFC 9112 requires recipients to anticipate large hexadecimal numerals and prevent integer overflow or precision loss.

Only the decoded content becomes the prompt-policy input. After redaction or approval, serialize the provider request with a freshly calculated Content-Length when the length is known. The outbound client owns that framing. Copying the inbound Transfer-Encoding field after decoding is a protocol error.

Canonical reserialization breaks the ambiguity chain

A security proxy should terminate the inbound HTTP message rather than relay its original bytes. The control sequence is:

  1. Parse the complete inbound message under one strict grammar.
  2. Reject ambiguous framing and close the inbound connection.
  3. Decode transfer codings and enforce body limits.
  4. Authenticate the user or agent and evaluate the decoded prompt.
  5. Build a new provider request from validated method, route, fields, and body.
  6. Let the outbound HTTP client generate framing for its own connection.

That sequence gives the downstream adapter one canonical message. The concrete test artifact is a provider-side capture containing one Content-Length field whose value matches the exact UTF-8 body bytes after any redaction. No chunk syntax or extra bytes from the client survive.

The AI gateway TLS termination guide covers the related connection boundary. The LLM request signing guide addresses integrity for the canonical message after framing is stable.

Connection closure is part of rejection

Returning 400 while retaining the TCP connection leaves uncertain bytes in the receive buffer. A later request can begin at a position selected by the parser that lost the disagreement. RFC 9112 repeatedly pairs framing errors with connection closure for this reason.

The edge listener should mark the connection non-reusable as soon as it finds conflicting framing, an invalid length, an unsupported request transfer coding, or malformed chunks. It should consume no more requests from that connection. The provider connection should remain unopened because the message never reached policy approval.

For errors detected after an outbound connection exists, discard the affected response or request state and remove that connection from the pool. Never place unparsed remainder bytes back into a shared pool. The AI gateway fail-closed guide provides the adjacent operating posture for policy and audit dependency failures.

Protocol translation needs its own smuggling tests

HTTP/2 and HTTP/3 frame messages differently and prohibit Transfer-Encoding in the HTTP/1.1 sense. Risk returns when an intermediary translates a request into HTTP/1.1. The translator must derive one body length and generate valid downstream framing. It must also reject forbidden connection-specific fields rather than converting them into an ambiguous HTTP/1.1 message.

Test each actual path: HTTP/1.1 to HTTP/1.1, HTTP/2 to HTTP/1.1, HTTP/1.1 to HTTP/2, and every CDN or service-mesh hop that changes versions. Direct tests against the application server prove only one parser.

Include malformed transfer-coding names, duplicate pseudo-header equivalents, conflicting authority values, oversized lengths, early end-of-stream, extra bytes after the declared body, and a hidden second request after a zero chunk. The expected outcome is one rejection, one closed inbound connection, zero provider calls, and a bounded audit event without the hidden prompt body.

Audit evidence should describe the parser outcome

A rejected smuggling attempt happens before normal LLM policy evaluation. Record the listener protocol, framing fields in a redacted normalized form, parser reason code, connection-close action, authenticated subject if already established, and provider-call count. Avoid storing raw authorization fields or the complete malicious body.

Separate a protocol rejection from a model-policy denial. The first says the gateway never established one valid HTTP request. The second says a valid request reached identity and content policy. Combining both as "blocked" erases the control that fired and makes incident review slower.

A useful release test reconciles ingress and provider telemetry by request ID. Every malformed fixture should appear once at ingress and zero times in provider traces. Any provider-side record is a release blocker.

DeepInspect

DeepInspect applies this control only when authenticated user or agent traffic is deliberately routed over HTTP through the proxy to an LLM endpoint. At that boundary, strict framing validation can stop ambiguous requests before prompt inspection and provider forwarding. Direct provider traffic, local execution, stolen credentials used outside the route, and bypass connections remain outside control.

For a valid routed request, DeepInspect can bind the canonical body to verified identity, content classification, destination model, policy version, and decision. A framing rejection should produce a separate protocol event and no model call. That separation proves the hidden bytes never crossed the AI request boundary.

Book a demo today.