My URL looks like the following:
http://example.com/value=S%0a%0d"><'script>alert(0)<'/script'>%20"
When I print value of the value
request parameter in my Servlet, using the following code:
String Value=request.getParameter("value");
System.out.print("URL :"+Value);
The output is as follows:
URL :S
"><'script>alert(0)<'/script'>%20
It printed two lines (which makes this possibly vulnerable to XSS attacks). I tried the code below to replace the %0A%0D
characters:
Value = value.replace('\n', ' ');
Value = value.replace('\r', ' ');
Value = value.replace("\n", "");
value = value.replace("\r", "");
value = value.replaceAll("0A", "");
value = value.replaceAll("0D", "");
value = value.replaceAll("%0A", "");
value = value.replaceAll("%0D", "");
value = value.replaceAll("%0A%0D", "");
But it only checks the first line of the output. How can I remove these characters from the URL, in order to mitigate XSS attacks?