Skip to content

Commit 5ac453e

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add spurious test case for StringBuilder.append
1 parent 04d27f2 commit 5ac453e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

java/ql/test/query-tests/security/CWE-552/UrlForwardTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,25 @@ protected void doGet2(HttpServletRequest request, HttpServletResponse response)
388388
sc.getRequestDispatcher(VALID_FORWARD).forward(request, response);
389389
}
390390
}
391+
392+
// Test `StringBuilder.append` sequence with `?` appended before the user input
393+
private static final String LOGIN_URL = "/UI/Login";
394+
395+
public void doPost2(HttpServletRequest request, HttpServletResponse response)
396+
throws ServletException, IOException {
397+
StringBuilder forwardUrl = new StringBuilder(200);
398+
forwardUrl.append(LOGIN_URL);
399+
400+
String queryString = request.getQueryString();
401+
402+
// should be sanitized due to the `?` appended
403+
forwardUrl.append('?').append(queryString);
404+
405+
String fUrl = forwardUrl.toString();
406+
407+
ServletConfig config = getServletConfig();
408+
409+
RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(fUrl); // $ SPURIOUS: hasUrlForward
410+
dispatcher.forward(request, response);
411+
}
391412
}

0 commit comments

Comments
 (0)