after the last starts of findbugs (FB) have been started, he complains about the vulnerability: security vulnerability - HTTP response. The following code launches it:
String referrer = req.getParameter("referrer"); if (referrer != null) { launchURL += "&referrer="+(referrer); } resp.sendRedirect(launchURL);
Basically, the http 'referrer' parameter contains the URL that the browser returns to when you click the return button in our application. It is added to the URL as a parameter. After a little research, I know that I need to sanitize the referrer URL. After a bit more research, I found the esapi project, which seems to offer such functionality:
//1st canonicalize import org.owasp.esapi.Encoder; import org.owasp.esapi.Validator; import org.owasp.esapi.reference.DefaultEncoder; import org.owasp.esapi.reference.DefaultValidator; [...] Encoder encoder = new DefaultEncoder(new ArrayList<String>()); String cReferrer = encoder.canonicalize(referrer);
However, I did not understand how to detect, for example. jscript code or other material that is not relevant to the referrer url. So how can I achieve this with esapi?
I tried:
Validator validator = new DefaultValidator(encoder); validator.isValidInput("Redirect URL",referrer,"HTTPParameterValue",512,false);
however this does not work. I need a function that leads to:
http://www.google.com (ok)
http://www.google.com/login?dest=http://google.com/%0D%0ALocation : javascript:% 0D% 0A% 0D% 0Aalert (document.cookie) (does not work)
Or is it enough to invoke the following statement?
encoder.encodeForHTMLAttribute(referrer);
Any help was appreciated.