← Java / Spring · Contents

JAVA-089 / Intermediate

HTTP header injection: raw user input in headers

A03:2021 Injection · CWE-113 HTTP Response Splitting

Why is this a problem?

Including CRLF (\r\n) splits the response.

How to fix it

java
response.setHeader("X-Name", name.replaceAll("[\\r\\n]", ""));   // Allowed characters only

Further reading