Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response Header validation in java

I am passing directly a user defined parameter in my response header. Which I have learned is not a good idea since that way user can manipulate header and it can lead to Cross site scripting attacks and other kind of multiple attacks.

https://www.fortify.com/vulncat/en/vulncat/python/header_manipulation.html

What I am doing for preventing this is validate the user input for "http response splitting" by replacing "\r" and "\n" characters with empty string "". Is this enough or I have to check for other characters also. Any pointers would be of great help.

This is my code.

if(response != null)
  {
   newResponse = response.replaceAll("[\r\n]", "");
  }

Is this enough for preventing this kind of attack or I should also validate for other characters.

like image 967
Muneeb Ahmad Avatar asked Jun 17 '26 02:06

Muneeb Ahmad


1 Answers

A whitelist is much safer than a blacklist. Whether you can use a whitelist depends on how much you know about the user defined parameter.

More here:

http://cwe.mitre.org/data/definitions/113.html

like image 104
artbristol Avatar answered Jun 19 '26 14:06

artbristol