CRLF injection: line breaks where data should be

CRLF stands for carriage return and line feed, the two characters that end a line in HTTP headers and in many log formats. CRLF injection is an attack in which input containing them reaches a header or a log line, so the attacker can start a new header, a new log entry or, in the worst case, a whole new HTTP response. Its relatives, response splitting and host header injection, abuse the same trust in what arrives in headers.

Section Web attacks Updated Weaknesses CWE-93, CWE-113

Quick facts

CRLF
Carriage return and line feed, the line ending in HTTP/1.1 headers
Weaknesses
CWE-93 CRLF injection; CWE-113 HTTP response splitting
OWASP category
A05:2025 Injection
Also written as
CR LF, \r\n, and %0D%0A when percent-encoded in a URL
Where it lands
Redirect locations, cookies set from input, custom headers, log files
Main fix
Refuse or strip line breaks in any value that becomes a header or log line

Definitions follow OWASP and the CWE entries above; header syntax is in RFC 9110.

What CRLF is, and why it matters

In an HTTP/1.1 message, each header sits on its own line, and an empty line separates the headers from the body. A server or client decides where one header ends and the next begins by looking for the line ending.

If an application copies input into a header, for example the target of a redirect, and the input contains a line ending, everything after it becomes a new header. The application meant to send one value; the attacker has written part of the response. The same mistake in a mail form is email header injection.

How CRLF is written: CR LF, \r\n and %0D%0A

CRLF is two control characters in a row. Carriage return is the byte 0x0D and line feed is 0x0A. The HTTP/1.1 message grammar puts a CRLF after the start line and after every header line (RFC 9112, built on the core rules of RFC 5234). Code writes the pair as \r\n. In a URL or a form value it travels percent-encoded, a percent sign followed by two hexadecimal digits (RFC 3986), so a CRLF reads %0D%0A.

That makes the flaw straightforward to probe. Put %0D%0A into each parameter that ends up in a redirect, a cookie or a log line, then read the response headers and the log for a line that was not there before. The method is the one used for other injection flaws; compare command injection examples and sql injection how to test.

HTTP response splitting

With two line endings in a row, the attacker ends the headers and starts the body, or even a second response. That is HTTP response splitting. A cache in between may store the forged response under a legitimate address and serve it to other users, which turns one injection into a persistent attack. A cache can store such a response and serve it to others; see web cache poisoning.

Modern frameworks and servers refuse line breaks in header values, which has made response splitting rarer. It survives in hand-built headers, older components and proxies that rewrite requests. Proxies are also where HTTP request smuggling starts.

THE HEADER-INJECTION FAMILY NEEDS A LINE BREAK AFFECTS OTHER USERS FIXED BY ENCODING OUTPUT HEADER INJECTION RESPONSE SPLITTING LOG INJECTION HOST HEADER INJECTION // host header injection trusts a value instead of breaking a line
// four attacks that start in headers

Host header injection

Host header injection needs no line break. The application trusts the Host header to build absolute links, for example in password reset emails, and the attacker sends a request with their own domain in it. The victim receives a genuine email whose reset link points to the attacker.

The fix is to build links from a configured site address, never from the request, and to answer only for host names the site expects.

Log injection

Log files are text with one event per line. If an application writes user input into a log without removing line breaks, an attacker can add a line of their own: a fake successful sign-in, an entry that hides their real activity, or text that misleads whoever reads the log later. This is CWE-117, improper output neutralization for logs.

The fix is the same as for headers: encode or strip carriage return and line feed in anything written to a log, or use a structured log format that keeps each field separate. Logs read in a browser-based viewer also need HTML escaping, or the injected text can carry script.

Email header injection

Email headers are separated by the same CRLF sequence as HTTP headers. A contact form that puts the visitor's address or subject into the message headers without checking can be fed a line break followed by Bcc: and a list of addresses, which turns the form into a spam relay sending from your server.

It belongs to the same family, CWE-93, improper neutralization of CRLF sequences. Refuse any line break in fields that end up in headers, and send mail through a library that builds headers itself rather than by joining strings.

What a WAF catches, and what it misses

Encoded line endings inside parameters that should be single-line values are a clear signal, and rule sets match them. Unexpected Host values can be refused at the edge if the list of valid names is known.

A filter misses line breaks that arrive in forms it does not decode, and values that become headers only after the application combines them. The safe behaviour has to be in the code that writes headers and logs. The same limit applies to encoded command injection and SQL injection payloads.

In monitor mode a rule match on an encoded line ending is recorded and the request is still served, so the activity log shows which requests carry %0D%0A before block is switched on.

How to prevent CRLF injection

  1. Use framework functions to set headers. They refuse values containing line breaks.
  2. Validate redirect targets. Allow only relative paths or listed hosts, which also prevents open redirects.
  3. Encode log entries. Replace line breaks so one request cannot write several log lines.
  4. Build absolute links from configuration. Never from the Host header of the request.
  5. Keep proxies and servers updated. Request and response parsing bugs are fixed there.

Questions

What is CRLF injection?

CRLF injection is an attack in which input containing carriage return and line feed characters reaches an HTTP header or log line, letting the attacker add headers, log entries or even a whole response.

What is HTTP response splitting?

HTTP response splitting uses CRLF injection to end a response's headers early and write the body or a second response, which a cache may then serve to other users.

What is host header injection?

Host header injection abuses an application that trusts the Host header to build links, so password reset or other emails contain links to the attacker's domain.

How do you prevent CRLF injection?

Set headers through framework functions that refuse line breaks, validate redirect targets, encode log entries, and build absolute links from configuration rather than from the request.

What does CRLF mean?

CRLF stands for carriage return and line feed, the line ending written \r\n in code and %0D%0A when percent-encoded in a URL. HTTP/1.1 places it after the start line and after each header line.