Java HTTP头中CRLF序列的不正确中和

Java HTTP头中CRLF序列的不正确中和,java,xss,veracode,Java,Xss,Veracode,我在我的项目上运行了Veracode扫描,它在HTTP响应拆分下给了我CWEID113问题。我试图用这些建议来解决这个问题,但没有成功。e、 g try { String selNhid = req.getParameter("selNhid"); String redirectURL = "/nhwhoods?action=membersNH&selNhid="+selNhid; res.sendRedirect(req.get

我在我的项目上运行了Veracode扫描,它在HTTP响应拆分下给了我CWEID113问题。我试图用这些建议来解决这个问题,但没有成功。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();
    }
以上代码来自其中一个文件。并报告第行显示错误

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

任何建议,如何解决问题?

可以使用ESAPI 2.1.0.1库修复此问题,包括:

import org.owasp.esapi.ESAPI;

ESAPI.httpUtilities().setHeader(response, param, value);
ESAPI.httpUtilities().addCookie(response, cookie);

如错误消息所示,从redirectURL参数中删除CRLF序列如何


一个简单的
.replaceAll(“[\\r\\n]+”,”)
应该可以做到这一点。

selNhid缺少URL编码

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

以上假设您正在使用UTF-8。现在,恶意内容将以%XX字节的形式解除防护。

您尝试的哪些内容无效?