CRLF Injection
What is CRLF Injection?
CRLF InjectionAn attack that inserts carriage-return and line-feed characters into HTTP headers, log files, or other text protocols to forge new lines and change semantics.
CRLF injection abuses the special meaning of the CR (0x0D) and LF (0x0A) byte sequence that terminates lines in many text-based protocols. When an application reflects unvalidated user input into HTTP response headers, log entries, SMTP commands, or LDAP queries, an attacker can inject a CRLF pair followed by additional content to forge headers, split responses, hide entries in logs, or smuggle commands. The weakness is catalogued as CWE-93 (improper neutralization of CRLF sequences); its HTTP-header-specific child is CWE-113, which covers HTTP request/response splitting.
In web contexts the most damaging form is HTTP response splitting, first described by Amit Klein of Sanctum in a 2004 paper. Because the injected CRLF closes the header block, the attacker can append a second, fully attacker-controlled response — poisoning shared caches, setting arbitrary cookies, or injecting XSS into a body the browser treats as trusted. The bug recurs in standard libraries: CVE-2019-9740 let CRLF sequences in a URL passed to Python's urllib.request.urlopen inject HTTP headers (even Redis commands via the query string), and it was patched in Python 2.7.17 and 3.5.10/3.6.10/3.7.4. Defenses include rejecting or percent-encoding CR/LF in any input destined for headers, using high-level APIs that refuse control characters in header values, and strict, structured log encoders rather than raw string concatenation.
flowchart TD
A[User input<br/>name=foo%0d%0aSet-Cookie: admin=true] --> B{Validate / strip CR LF?}
B -->|No| C[Input written raw into header]
C --> D[CRLF ends current header]
D --> E[Attacker-controlled header or response body]
E --> F[Cache poisoning / cookie injection / XSS]
B -->|Yes, reject CR LF| G[Safe response]● Examples
- 01
Set-Cookie: id=foo%0d%0aSet-Cookie: admin=true — adds a second cookie via CRLF.
- 02
Location: /redir%0d%0aContent-Length:0%0d%0a%0d%0a<html>... — HTTP response splitting.
● Frequently asked questions
What is CRLF Injection?
An attack that inserts carriage-return and line-feed characters into HTTP headers, log files, or other text protocols to forge new lines and change semantics. It belongs to the Attacks & Threats category of cybersecurity.
What does CRLF Injection mean?
An attack that inserts carriage-return and line-feed characters into HTTP headers, log files, or other text protocols to forge new lines and change semantics.
How do you defend against CRLF Injection?
Defences for CRLF Injection typically combine technical controls and operational practices, as detailed in the full definition above.
What are other names for CRLF Injection?
Common alternative names include: Carriage return line feed injection, Log injection.