Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix XSS Reflected in java

Tags:

java

xss

I got fortify report which shows XSS Reflected defect from the below 2nd line.

String name = request.getParameter("name");

response.getWriter().write("Name: " + name);

Recommendation given: All user input displayed to web clients should HTML encoded and validated. This is java code and I am not sure about how to fix this.

like image 721
SuRa Avatar asked Mar 16 '23 13:03

SuRa


1 Answers

A simple way, you can just use the OWASP Enterprise Security API (Java Edition) :

 String safe = ESAPI.encoder().encodeForHTML( request.getParameter( "input" ) );

See those link:

OWASP Enterprise Security API (Java Edition) Documentation

OWASP Enterprise Security API (Java Edition) Code Example

like image 181
Nadhir Loghmari Avatar answered Mar 28 '23 20:03

Nadhir Loghmari