← PHP / Laravel · Contents

PHP-097 / Intermediate

HTTP header CRLF injection (response splitting)

A03:2021 Injection · CWE-113 HTTP Response Splitting

Why is this a problem?

New headers or body content are injected through CRLF (\r\n) in the input.

How to fix it

php
$lang = preg_replace('/[^a-z\-]/i', '', $request->input('lang'));   // Allowed characters only
return response('ok')->header('X-Lang', $lang);

Further reading