NShiftKey-Rule-Guide logo NShiftKey-Rule-Guide

1. Vulnerability Description

[picture 1. CRLF Vulnerability]

2. How to check vulnerability

[picture 2. Example of vulnerability checking]

3. Vulnerability Countermeasure

4. Sample Code

throws IOException, ServletException
{
    response.setContentType("text/html");
    String author = request.getParameter("authorName");Cookie cookie = new Cookie("replidedAuthor", author);
    cookie.setMaxAge(1000);
    response.addCookie(cookie);
    RequestDispatcher frd = request.getRequestDispatcher("cookieTest.jsp");
    frd.forward(request, response);
}
throws IOException, ServletException
{
    response.setContentType("text/html");
    String author = request.getParameter("authorName");
    if (author == null || "".equals(author)) return;
    String filtered_author = author.replaceAll("\r", "").replaceAll("\n", "");
    Cookie cookie = new Cookie("replidedAuthor", filtered_author);
    cookie.setMaxAge(1000);
    cookie.setSecure(true);
    response.addCookie(cookie);
    RequestDispatcher frd = request.getRequestDispatcher("cookieTest.jsp");
    frd.forward(request, response);
}