01Issue
Overview
Carriage return (CR) and line feed (LF) are characters used to end a line. HTTP headers, text logs, and some message formats use line breaks to separate fields or records. CRLF injection occurs when input is copied into one of those outputs and the receiving component treats the supplied line break as a real boundary. In an HTTP response, this may become response splitting; in a log, it may create a misleading extra entry.
Common causes
- The application joins untrusted text into a header, log, or message without handling line breaks for that format.
- The application checks encoded input, then decodes it after the check.
- Different layers normalize newline characters differently.
- The application logs plain text instead of using structured fields.
References: CWE-93: CRLF Injection ↗OWASP WSTG: HTTP Response Splitting ↗RFC 9112: HTTP/1.1 message parsing ↗
02Examples
Illustrative header test: submit name=report%0d%0aX-Test-Probe: marker-1 to a test redirect feature and inspect the raw response. A separate X-Test-Probe header would show that line data reached the header parser. A literal string in the body does not show that. For logs, search the test record and confirm the marker has not created a second event.
03Impact
A user-controlled value must reach a line-oriented output, and the receiving protocol or viewer must interpret the inserted CR/LF as a new field or record. A string containing %0d%0a in a response body is only a clue unless it becomes a separate parsed line.
If a new line is accepted, an attacker may be able to alter a response header, forge or confuse log records, or affect a downstream parser. The exact result depends on the output and consumer. A visible marker or generic server error does not prove header injection or log forgery.
04Testing
Test cases
1. Check whether line breaks create new headers
Insert encoded carriage return and line feed characters into input used in a response header. Inspect the raw response for a separate test header.
Example: The string appearing in the response body is only a clue. A separate parsed header is stronger evidence.
GET /redirect?next=%2Fhome%0d%0aX-Test-Marker%3A%20demo HTTP/1.1
Host: app.example.test
2. Check line breaks in log records
Submit a marker containing a line break through an input recorded in application logs. Inspect the resulting test log entries and their boundaries.
Example: A viewer may display text across lines without creating a new record. Compare the underlying log structure.
GET /search?q=test%0d%0aLOG-MARKER HTTP/1.1
Host: app.example.test
3. Compare decoding and downstream handling
Repeat with supported input formats and inspect how the proxy, application, and log viewer decode the value. Record the exact output and consumer.
Example: Double encoding may be decoded at different layers. Test only the transformations relevant to the application.
Testing references: CWE-93: CRLF Injection ↗OWASP WSTG: HTTP Response Splitting ↗RFC 9112: HTTP/1.1 message parsing ↗
05Mitigation
Use framework APIs to set response headers rather than building raw header lines. Reject CR and LF in values that are not supposed to contain line breaks, and encode data for the destination format. Use structured logging so user input stays within a field. Validate after canonicalization, and ensure downstream log collectors apply the same record boundaries.
Retest
Repeat newline variants against each affected output. Inspect the raw response and parsed log or message record, and confirm the value stays within its intended field while ordinary values continue to work.