CRLF Injection Lab: Inject a Header Into the Response

✨ AI Summary
RedirectorApp takes a URL from the query string and drops it straight into the Location response header. HTTP headers are separated by a carriage-return and line-feed (CRLF). Put those characters in your input and you are no longer supplying a value — you are writing new headers.
Lab at a glance: Intermediate · 90 XP · about 15 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

CRLF injection (HTTP response splitting, CWE-93) happens when untrusted input is placed into an HTTP response header without stripping the CR and LF characters that separate headers. An attacker who can inject a newline can add headers of their own — setting cookies, or in the worst case splitting the response into two.

The lesson: the structure of an HTTP response is defined by CRLFs. Let the user supply those and they control the structure.

How RedirectorApp builds the Location header

RedirectorApp concatenates your URL parameter into the Location header to send a redirect. It never removes CR or LF, so a newline in your input ends the Location header early and begins a new header line that you control — such as an attacker-chosen Set-Cookie.

The attack approach

  • Notice your URL parameter is reflected into the Location header.
  • Encode CRLF characters into the parameter so the header line can be terminated early.
  • After the break, write a new header — a Set-Cookie of your choosing.
  • Send it and confirm the injected header appears in the response.

Full walkthrough (spoiler)

If your extra header is not appearing, the newline encoding is being passed through literally — open the steps.

Show the step-by-step solution
  1. Put the redirect target in the URL parameter, then append encoded CRLF characters.
  2. After the CRLF, add a Set-Cookie header that sets session=SE_LAB_CRLF_INJECT_2026.
  3. Submit. Because the value is concatenated without stripping CR/LF, the response now carries your injected Set-Cookie header.
  4. The lab detects the injected cookie header and marks you solved.

Why it works

HTTP separates headers with CRLF. The app treats your input as a flat string and copies it into a header, but the bytes you send include the very characters that mean 'next header'. The parser on the other end obeys them, so your text becomes structure — an extra header the server never intended to send.

Core principleStrip or reject CR and LF in anything that goes into a response header, and prefer framework APIs that encode header values for you.

Where this happens in the real world

Response splitting (CWE-93) can set malicious cookies, poison caches, or in older stacks split a response and serve attacker content. Modern servers and frameworks reject bare CR/LF in headers, which is why it is rarer now — but it still appears where apps build headers (redirects, custom headers) by hand. It maps to Injection (A03) in the OWASP Top 10 (2021).

How to defend against it

  • Reject or strip CR and LF from any value placed in a response header.
  • Use framework header APIs that validate and encode header values rather than string concatenation.
  • Validate redirect targets against an allowlist instead of reflecting raw input into Location.
  • Keep your server and framework current — modern versions reject malformed header characters by default.
Mr Elite tip: When testing header-building endpoints you are authorised to assess, try an encoded newline in reflected parameters. If a second header you chose appears in the response, CR/LF is not being filtered.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is CRLF injection?
Injecting carriage-return and line-feed characters into data that gets placed in an HTTP response header, letting an attacker add their own headers or split the response (CWE-93).
What can an attacker do with it?
Set malicious cookies, poison caches, redirect users, and in older stacks split the response to serve attacker-controlled content.
Why is it rarer today?
Modern web servers and frameworks reject bare CR/LF in header values. It still appears where apps build headers by hand from user input.
How do I prevent it?
Strip or reject CR/LF in header values, use framework header APIs instead of concatenation, and validate redirect targets against an allowlist.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *