1

Here are the servelet cum JSP code, let me know how we could protect them from XSS?

Servlet Code:

String strRequestScrip = SecurityCheck.getStringParameter(request,PARAM_SCRIP_CODE);

 List arrScripLocator = MarketWatchUtils.getEqScripLocator(strRequestScrip, strExchangeCode, application);

 request.setAttribute("arrScripLocator", arrScripLocator);

 request.getRequestDispatcher("/ajax/ajaxScripLocator.jsp").forward(request, response);

Jsp Code:

final List arrScripLocator = (List) request.getAttribute("arrScripLocator");

int intScripLocatorSize = arrScripLocator != null ? arrScripLocator.size() : 0;

intScripLocatorSize = intScripLocatorSize <= 20 ? intScripLocatorSize : 20;

out.print(intScripLocatorSize);

1 Answer 1

1

You should use Jsoup to sanitize the request. The code will look like this:

String unsafe ="<p><a href='http://example.com/' onclick='stealCookies()'>Link</a></p>";
String safe = Jsoup.clean(unsafe, Whitelist.basic());
// now: <p><a href="http://example.com/" rel="nofollow">Link</a></p>

I recommend you also read the OWASP XSS Filter Evasion Sheet.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer. This would be great if I am able to help the IT admin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.