Skip to content
← Back to the module
Lesson 0214 min read

Anatomy of an HTTP Request

Methods, status codes, headers, bodies and protocol versions: every part of HTTP you will read, tamper with and abuse.

Why HTTP is your main weapon

Almost everything you do as a web hacker is reading, crafting and replaying HTTP messages. Browsers hide them behind pretty pages; a proxy shows them naked. Once you read HTTP fluently, a login form stops being a form and becomes POST /login with two parameters you control. An "Add to cart" button becomes a request with a price field you may be able to change.

HTTP (HyperText Transfer Protocol, specified in RFC 9110 for semantics and RFC 9112 for HTTP/1.1 message syntax) is:

  • Request/response: the client asks, the server answers, one request gets one final response.
  • Stateless: each request carries everything the server needs; state is rebuilt using cookies, tokens or server-side lookups.
  • Extensible: new headers and methods can be added without breaking old software, which is also why implementations disagree on edge cases.

Anatomy of a request

POST /api/login?next=/dashboard HTTP/1.1
Host: app.example.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64) Firefox/130.0
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Content-Length: 31
Cookie: session=abc123; theme=dark
Origin: https://app.example.com
Referer: https://app.example.com/login

username=alice&password=hunter2

A request has four parts:

  1. Request line: method, request target (path plus optional query) and protocol version.
  2. Headers: Name: value lines, one per line.
  3. Blank line (CRLF CRLF) separating headers from body. Its position is what parsers use to decide where the body begins; disagreements here underpin smuggling.
  4. Body (optional): the payload.

Lines end with \r\n (CRLF). Injecting CR and LF characters into a value that ends up in a header is called header injection or CRLF injection and lets an attacker add headers or even a whole second response.

Methods

The method states the intended action.

Method Intended use Safe? Idempotent? Has body?
GET Retrieve a resource Yes Yes No (normally)
HEAD Same as GET, response without body Yes Yes No
POST Submit data, create, trigger actions No No Yes
PUT Replace a resource No Yes Yes
PATCH Partially modify a resource No No Yes
DELETE Remove a resource No Yes Optional
OPTIONS Ask what is allowed; CORS preflight Yes Yes No
TRACE Echo the request back (diagnostic) Yes Yes No
CONNECT Open a tunnel through a proxy No No No

"Safe" means the method should not change server state. "Idempotent" means repeating it has the same effect as doing it once.

Security consequences:

  • State-changing GET requests (GET /delete?id=5) are trivial to forge with an <img> tag: a CSRF building block, and a bug in design.
  • Method confusion: a route may be protected for POST but not PUT or DELETE. Try other methods and check the Allow header returned by OPTIONS.
  • Method override headers such as X-HTTP-Method-Override: DELETE let a POST act as another method on some frameworks.
  • TRACE can reflect headers (including HttpOnly cookies in old attacks, "Cross-Site Tracing") and should be disabled.
  • Idempotency matters for race conditions: sending the same "redeem coupon" request in parallel may succeed several times.

Request target and the Host header

GET /products?id=42 is the path plus query. HTTP/1.1 requires a Host header, which names the site, allowing one IP to serve many sites (virtual hosting). Applications use it to build absolute URLs: in password reset emails, redirects and canonical links. If the app trusts a Host (or X-Forwarded-Host) you control, you get host header injection, for instance poisoned reset links.

Status codes

The response begins with a status line: HTTP/1.1 404 Not Found.

Class Meaning Examples
1xx Informational 100 Continue, 101 Switching Protocols (WebSocket upgrade)
2xx Success 200 OK, 201 Created, 204 No Content
3xx Redirection 301 permanent, 302 found, 303, 307/308 keep method, 304 Not Modified
4xx Client error 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 405 Method Not Allowed, 409, 413, 429 Too Many Requests
5xx Server error 500 Internal Server Error, 502 Bad Gateway, 503, 504 Gateway Timeout

What they tell a tester:

  • 401 means "who are you?" (not authenticated). 403 means "I know who you are, and no" (not authorized). A server that returns 403 for resources that exist and 404 for ones that do not leaks existence; the difference enumerates users, files and ids.
  • 500 after you sent odd input often means unhandled errors: investigate for injection. Verbose error pages expose stack traces, file paths and SQL fragments.
  • 3xx with a Location header whose value derives from a parameter is an open redirect candidate.
  • 405 plus an Allow header lists permitted methods.
  • 502/504 hint at a proxy in front of a failing backend.
  • 429 reveals rate limiting; its absence on login is a finding.
  • Differences in status, body length or timing between "user exists" and "user does not exist" enable user enumeration.

Headers

Headers are metadata. Every request header is attacker-controlled. Grouped by purpose:

Identity and context (request)

Header Purpose
Host Target site
User-Agent Client software; trivially spoofed
Accept, Accept-Language, Accept-Encoding Preferred content types, languages, compression
Referer The page that linked here (note the historical misspelling)
Origin Scheme+host+port that initiated a cross-origin or POST request
Cookie Cookies for this site
Authorization Credentials: Basic base64(user:pass), Bearer <token>
X-Forwarded-For, X-Forwarded-Proto, X-Real-IP Added by proxies; spoofable if not stripped

Describing the body (both directions)

Header Purpose
Content-Type Format of the body: application/json, multipart/form-data ...
Content-Length Body size in bytes
Transfer-Encoding: chunked Body sent in chunks; conflict with Content-Length causes smuggling
Content-Encoding Compression such as gzip or br

Caching

Cache-Control (no-store, private, public, max-age=3600), ETag, Last-Modified, Age, Vary. Mistakes here cause private responses to be cached or poisoned.

Response headers that matter to hackers

Header What it does
Set-Cookie Creates a cookie, with attributes (see the cookies lesson)
Location Redirect target
Server, X-Powered-By Technology fingerprinting
WWW-Authenticate Which auth scheme is required
Access-Control-Allow-Origin and friends CORS policy
Content-Disposition Download vs display, filename

Security headers

These are instructions from the server telling the browser to enforce extra protections. They are defense in depth; their absence is a weakness, not by itself a critical vulnerability.

Header Purpose Example
Content-Security-Policy (CSP) Restricts where scripts, styles, frames and images may load from; the main mitigation for XSS impact default-src 'self'; script-src 'self'
Strict-Transport-Security (HSTS) Browser must use HTTPS for this host for a period max-age=31536000; includeSubDomains
X-Content-Type-Options Stops MIME sniffing nosniff
X-Frame-Options / CSP frame-ancestors Prevents framing, mitigating clickjacking DENY
Referrer-Policy Controls how much of the URL is leaked in Referer strict-origin-when-cross-origin
Permissions-Policy Allows or denies browser features (camera, geolocation) geolocation=()
Cross-Origin-Opener-Policy / Cross-Origin-Resource-Policy / Cross-Origin-Embedder-Policy Isolation between windows and resources same-origin

You can inspect them with curl -sI https://example.com. Tools such as securityheaders.com summarize them. When reporting a missing header, explain real impact; programs often rate "missing header" with no demonstrated exploit as informational.

Bodies and content types

The Content-Type header tells the server how to parse the body. The same logical data can be encoded several ways, and applications often accept more than one, which can bypass filters.

Form URL-encoded (default for HTML forms):

POST /login HTTP/1.1
Content-Type: application/x-www-form-urlencoded

username=alice&password=hunter2

JSON:

POST /api/login HTTP/1.1
Content-Type: application/json

{"username":"alice","password":"hunter2"}

Multipart (file uploads):

POST /upload HTTP/1.1
Content-Type: multipart/form-data; boundary=----X

------X
Content-Disposition: form-data; name="file"; filename="a.png"
Content-Type: image/png

<binary data>
------X--

XML, text/plain, application/octet-stream and others also appear. Security angles:

  • Switching Content-Type (form to JSON or XML) may bypass validation, WAF rules, or CSRF defenses. Switching to XML may expose XXE.
  • A server that trusts the client-provided Content-Type of an upload (image/png) rather than validating contents invites malicious uploads.
  • Response Content-Type decides how the browser treats the body: text/html executes scripts; a JSON response served as text/html becomes an XSS sink.
  • JSON bodies introduce type confusion: sending {"id": [1]} or {"admin": true} where the app expected a string or no such field (mass assignment).

Anatomy of a response

HTTP/1.1 200 OK
Date: Mon, 16 Nov 2026 10:00:00 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 58
Set-Cookie: session=abc123; Path=/; Secure; HttpOnly; SameSite=Lax
Cache-Control: no-store
X-Content-Type-Options: nosniff

{"id":7,"username":"alice","role":"user","plan":"free"}

Read every response like a detective: extra fields (role, isAdmin, internal ids), debug headers, version strings, timing, and differences between users.

HTTP/1.1, HTTP/2 and HTTP/3

HTTP/1.1 HTTP/2 HTTP/3
Format Text Binary frames Binary frames
Transport TCP TCP (usually with TLS) QUIC over UDP (TLS 1.3 built in)
Multiplexing No (one request at a time per connection, or pipelining) Yes: many streams per connection Yes, without TCP head-of-line blocking
Headers Plain text, repeated each time Compressed with HPACK Compressed with QPACK
Request line GET / HTTP/1.1 Pseudo-headers :method, :path, :authority, :scheme Same model as HTTP/2

The semantics (methods, status codes, headers) are the same in all versions; only the wire format changed. Your proxy shows an HTTP/1.1-style view even when the browser used HTTP/2.

Why it matters:

  • Request smuggling classically exploits disagreement between a front end and back end about Content-Length versus Transfer-Encoding in HTTP/1.1. HTTP/2 downgrading (front end speaks HTTP/2 to clients but HTTP/1.1 to the backend) reintroduced smuggling variants (H2.CL, H2.TE) because binary framing must be translated to text.
  • HTTP/2 allows header names or values with characters illegal in HTTP/1.1; when translated, they can inject CRLF.
  • Multiplexing is useful for attackers: sending many requests simultaneously in one connection improves timing precision for race conditions (the "single-packet attack" technique).
  • HTTP/3 over UDP can bypass network devices that only inspect TCP.

You can test versions: curl --http1.1 -I https://example.com, curl --http2 -I https://example.com, curl --http3 -I https://cloudflare.com (if your curl build supports it). In Chrome DevTools, right-click the Network column header and enable Protocol to see h2 or h3.

Crafting requests by hand

You can speak HTTP raw:

printf 'GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n' | openssl s_client -quiet -connect example.com:443 -servername example.com

With curl:

curl -i -X POST https://example.com/api -H 'Content-Type: application/json' -d '{"a":1}'
curl -i -H 'X-Forwarded-For: 127.0.0.1' https://example.com/
curl -i -X OPTIONS https://example.com/

Security relevance, a map

Attack HTTP element it relies on
IDOR / broken access control ids in path, query or body
SQLi, XSS, command injection any parameter, header or cookie value
CSRF state-changing methods, cookies, missing tokens
CORS misconfiguration Origin, Access-Control-*
Open redirect Location, redirect parameters
Request smuggling Content-Length, Transfer-Encoding, HTTP/2 downgrade
Cache poisoning unkeyed headers, Vary, Cache-Control
Host header attacks Host, X-Forwarded-Host
Clickjacking missing X-Frame-Options / frame-ancestors

Hands-on exercises

  1. Open DevTools, Network tab, load any page and click the main document request. Identify method, status, request headers, response headers and the protocol version.
  2. Run curl -sI https://github.com and make a table of the security headers present and absent. Write what each prevents.
  3. Use Copy as cURL on a request, modify one header (Accept-Language) and compare the responses with diff.
  4. Send curl -i -X OPTIONS to a site you own and read Allow. Then try a method that should not be allowed and read the status code.
  5. Request a non-existent path and an existing but forbidden one (for example /admin on a practice site). Compare status, length and body. What differences could enumerate resources?
  6. Switch between --http1.1 and --http2 and compare the output of curl -v. Spot the pseudo-headers in HTTP/2.

Checklist

  • I can write a valid HTTP request from memory.
  • I know the difference between 401 and 403, and 301 and 307.
  • I can name five security headers and what each blocks.
  • I know three ways content type changes parsing.
  • I can explain why HTTP/2 downgrading reintroduces smuggling.
  • I know which headers an attacker fully controls (all request headers).

Key takeaways

  • Every part of a request is input you control; trust none of it on the server.
  • Status codes, headers and response size are signals: read them.
  • Security headers are defense in depth enforced by the browser, not the server.
  • Versions change the wire format, not the semantics, but translation between them creates bugs.
  • Parser disagreements between components are the root of many advanced attacks.

Further reading

  • MDN: HTTP overview, HTTP methods, HTTP status codes, HTTP headers, CSP guide
  • RFC 9110 (HTTP semantics), RFC 9112 (HTTP/1.1), RFC 9113 (HTTP/2), RFC 9114 (HTTP/3)
  • OWASP Secure Headers Project and OWASP Testing Guide: HTTP methods
  • PortSwigger Web Security Academy: HTTP request smuggling, including HTTP/2 downgrade