CRLF Injection Explained: The Small Bug That Splits Responses and Poisons Logs
Some of the most dangerous bugs are the smallest. CRLF injection needs just two characters — a carriage return (\r, encoded as %0d) and a line feed (\n, encoded as %0a) — smuggled into a place where the server trusts user input. From there it can forge log entries, inject fake HTTP headers and, in the worst case, split a response and put attacker content in front of a victim.
Only ever test this on systems you own or have written permission to test — a bug bounty program’s in-scope target, your own lab, or a CTF challenge.
What CRLF actually is
HTTP is a text protocol. Headers end with a CRLF sequence, and a blank line (two CRLFs) separates headers from the body. If an application takes your input and pastes it into a header or a log line without cleaning it, your %0d%0a becomes a real line break — and everything after it becomes a brand-new line that you control.
Attack 1: Log poisoning
A login form logs failed attempts like this:
Failed login for user: anony
If the username field accepts CRLF, an attacker submits:
hacker%0a[2026-11-16] Admin logged in successfully from 10.0.0.1
The log now contains a fake success entry. An analyst — or an automated alert system — reads a lie. In a real investigation, poisoned logs can hide an intrusion or frame an innocent user.
Attack 2: HTTP response splitting
If user input lands in a response header — a redirect URL, a cookie value, a language setting — an attacker can inject a second set of headers and a whole fake body:
https://example.com/redirect?url=/homeContent-Length:%200HACKED
The victim’s browser sees two responses. The second one is fully attacker-controlled — a classic setup for cache poisoning and defacement.
Attack 3: Header injection
Injecting a Set-Cookie header through a CRLF can overwrite a victim’s session cookie. Injecting a Location header redirects the victim to a phishing page. The payload is small; the damage is not.
How to find it (legally)
- Look for places where your input comes back in a response header: redirects, Set-Cookie, Content-Disposition filenames, custom headers.
- Try %0d%0aInjected-Header: test and check whether Injected-Header appears in the response.
- Try it in form fields that get logged — then check the log output if you have access to it in your lab.
- Burp Suite’s scanner flags many CRLF issues automatically on your own targets.
How to prevent it
- Never put raw user input in headers or logs. Strip \r and \n from any value before it touches a header or a log line.
- Use your framework’s safe APIs. Modern frameworks encode or reject CRLF in header values by default — do not bypass them with raw header construction.
- Validate redirects. Only redirect to URLs on an allowlist, and reject anything containing control characters.
- Encode log output. Treat logs as untrusted data: encode newlines when writing them, so one entry can never become two.
CRLF injection rarely makes headlines, but it shows up in real bug bounty reports again and again — precisely because developers forget that two invisible characters are still characters. Learn to spot them, and you will find bugs other hunters walk straight past.



Comments
Post a Comment