Skip to content

Lesson 12 of 18 · 20m

HTTP on the Wire: Framing, Semantics, and Redirects That Rewrite You

The request as bytes, Content-Length vs chunked framing and request smuggling, method safety, and what h2/h3 actually fixed.

Here is a complete, legal HTTP client:

printf 'GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n' | nc example.com 80

That's the protocol. A request line, headers, a blank line, done. Everything else — browsers, fetch, REST clients, proxies, WAFs — is tooling on top of a text framing convention that hasn't fundamentally changed since HTTP/1.0 in 1996. Once you see it as bytes on a TCP connection, half the "mysteries" of production HTTP (redirects eating your POST, proxies disagreeing about where a request ends) become mechanical.

The request is bytes, the framing is the contract

An HTTP/1.1 request is METHOD /path HTTP/1.1, headers as Name: value, an empty \r\n\r\n, then an optional body. The response mirrors it: HTTP/1.1 200 OK, headers, blank line, body. Two fields decide where the body ends: Content-Length (count bytes) or Transfer-Encoding: chunked (read size-prefixed chunks until a zero chunk). The body length is not discoverable any other way — which is why intermediaries must agree on which field to believe.

When they don't agree, you get request smuggling: a front proxy honors Content-Length, the backend honors Transfer-Encoding, and the leftover bytes get parsed as the next request — which happens to be someone else's. James Kettle's 2019 desync research turned this into a whole CVE class (CL.TE/TE.CL); the fix is boring and total: frontends reject ambiguous requests, and h2/h3's binary framing removes the ambiguity by construction.

Host deserves its own note: it's the only required header in 1.1, it's how one IP serves a thousand sites (name-based vhosts — the HTTP analog of TLS's SNI), and because the server believes it, it's an attack surface. Host-header injection is how poisoned password-reset links get generated; your app should validate Host/absolute URI against an allowlist, and your CDN should be the thing that sets it.

Semantics the intermediaries enforce

Methods have contracts: GET and HEAD are safe — no state change, because prefetchers, crawlers, and browser "restore tabs" will fire them without asking. The "GET /admin/delete that a link-preview bot happily clicked" bug is a real incident pattern. PUT and DELETE are idempotent — retry-safe by contract, which is why proxies may resend them on failure. POST is neither — the "are you sure you want to resubmit" dialog exists because the spec doesn't promise retryability.

Status codes are a routing table for blame:

  • 3xx: 301/302 historically let browsers rewrite POST→GET on the follow-up — the classic "my API client's POST became a GET after the redirect" bug. 307 and 308 preserve method and body; if your endpoint redirects non-GET traffic, return those.
  • 4xx: 401 is unauthenticated (give me credentials — the name is wrong, the meaning is right), 403 is unauthorized (I know who you are; no), 404, 405, 429 with Retry-After (a polite rate limit you should honor).
  • 5xx: 502 bad gateway = the proxy's upstream answered garbage, 503 unavailable = deliberately refusing (deploy, overload), 504 = upstream too slow. Which layer emitted the code matters: a 502 from your nginx is a different owner than a 502 from the CDN's edge.

h1 vs h2 vs h3: what multiplexing fixed

HTTP/1.1 does one outstanding request per connection — which is why browsers open ~6 connections per origin and "connection count" used to be a tuning knob. HTTP/2 (RFC 9113) keeps one TCP connection and multiplexes numbered streams inside it: dozens of requests in flight, headers compressed (HPACK). It fixes HTTP's head-of-line blocking but not TCP's — one lost segment still stalls every stream. HTTP/3 (RFC 9114) runs the same request/response semantics over QUIC (UDP/443): per-stream delivery, so a lost packet stalls only the stream it belongs to. Version negotiation is ALPN — the TLS extension — which is why curl --http2/--http3 needs TLS to prove the other end speaks it:

curl -sv --http2 https://example.com -o /dev/null    # watch 'ALPN ... h2'
curl -sv --http1.1 https://example.com -o /dev/null

The headers that matter in production

Connection (hop-by-hop — a proxy must strip it), Via (each proxy appends itself — read it to count the boxes), Forwarded/X-Forwarded-* (the de-facto client-IP channel, and only as trustworthy as whoever wrote it — see the NAT/proxies lesson), Cache-Control (what shared caches may store), Retry-After, Strict-Transport-Security. h2 lowercases all header names; some old backends break on that, and it has been an actual bug class.

Try this

curl -sv https://example.com -o /dev/null                    # read the request/response raw
echo | openssl s_client -connect example.com:443 -alpn http/1.1 -quiet
GET / HTTP/1.1                                               # type it yourself
Host: example.com
Connection: close

Type the request by hand inside TLS once. After that, "the client sent a request" will never feel like an abstraction again — and when a 301 eats your POST or a smuggling report lands, you'll read it as what it is: two parties disagreeing about where the bytes end.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.

What is a Web Server? Apache, Nginx, and How the Internet Delivers Web Pages

A web server accepts HTTP requests and returns responses. Apache has been doing this since 1995. Nginx rebuilt the model in 2004 and took over the cloud. Here's how they work, how they differ, and how to pick between them.

Article

How to Install NGINX on Debian & Ubuntu: Server Blocks, HTTPS and Reverse Proxy

When it comes to running a web server for all of my online projects, NGINX is the first that comes to mind for me. By default, it follows my guidelines of running a piece of software – meaning that the software is security-minded, performance-driven, and honestly, really easy to manage all the aspects of it. NGINX is most likely the most popular web server software in the world, and it's well known for being the backbone of some of the biggest sites on the internet to date. It is a lightweight

Article

Minecraft 26.4 Replaced Its Decade-Old Login Crypto. Here's What key-rotation-period-seconds Actually Does.

26.4 Snapshot 9 rewrote how a Java Edition client and server agree on an encryption key. RSA-1024 is out, X25519 is in, and a new key-rotation-period-seconds setting decides how often the server's key changes. I opened the snapshot server jar, timed the login crypto, and checked what changes for...

Article

The Same Researcher Broke apt the Same Way Twice, Seven Years Apart

In 2019 Max Justicz showed apt would install a package an attacker swapped in over a redirect. In November 2026 he did it again, CVE-2026-109518, through a different door that ends in the same place: code as root from a man in the middle. The fix shows how apt reuses files on disk.

Article