2

I ran Veracode scan on my project and it gave me CWE ID 113 issue under HTTP response splitting. I tried to resolve the issue with there recommendations but it did not work. e.g.

try
    {
        String selNhid = req.getParameter("selNhid");
        String redirectURL = "/nhwhoods?action=membersNH&selNhid="+selNhid;
         res.sendRedirect(req.getContextPath() + redirectURL);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

above code is from one of the file. And report showing error at line

res.sendRedirect(req.getContextPath() + redirectURL);

Any suggestions, how to resolve the issue ?

Pavan Divekar
  • 449
  • 2
  • 14

3 Answers3

0

This can be fixed using ESAPI 2.1.0.1 library with:

import org.owasp.esapi.ESAPI;

ESAPI.httpUtilities().setHeader(response, param, value);
ESAPI.httpUtilities().addCookie(response, cookie);
devwebcl
  • 2,866
  • 3
  • 27
  • 46
0

how about just removing CRLF sequences from redirectURL parameter, like the error message suggests?

A simple .replaceAll("[\\r\\n]+", "") should do it.

eis
  • 51,991
  • 13
  • 150
  • 199
0

There is a missing URL encoding for the selNhid.

String redirectURL = "/nhwhoods?action=membersNH&selNhid="
        + URLEncoder.encode(selNhid, StandardCharsets.UTF_8);

The above assumes you are working with UTF-8. Now nasty content will be disarmed as %XX bytes.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138