mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Merge pull request #365 from aschackmull/java/response-splitting-whitelist-cookiename
Java: Whitelist Cookie::getName for HTTP response splitting.
This commit is contained in:
@@ -32,6 +32,7 @@ class HeaderSplittingSink extends DataFlow::ExprNode {
|
||||
|
||||
class WhitelistedSource extends RemoteUserInput {
|
||||
WhitelistedSource() {
|
||||
this.asExpr().(MethodAccess).getMethod() instanceof HttpServletRequestGetHeaderMethod
|
||||
this.asExpr().(MethodAccess).getMethod() instanceof HttpServletRequestGetHeaderMethod or
|
||||
this.asExpr().(MethodAccess).getMethod() instanceof CookieGetNameMethod
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ResponseSplitting extends HttpServlet {
|
||||
}
|
||||
|
||||
// BAD: setting a header with an unvalidated parameter
|
||||
// can lead to hTTP splitting
|
||||
// can lead to HTTP splitting
|
||||
response.addHeader("Content-type", request.getParameter("contentType"));
|
||||
response.setHeader("Content-type", request.getParameter("contentType"));
|
||||
|
||||
@@ -42,4 +42,10 @@ public class ResponseSplitting extends HttpServlet {
|
||||
private static String removeSpecial(String str) {
|
||||
return str.replaceAll("[^a-zA-Z ]", "");
|
||||
}
|
||||
|
||||
public void addCookieName(HttpServletResponse response, Cookie cookie) {
|
||||
// GOOD: cookie.getName() cannot lead to HTTP splitting
|
||||
Cookie cookie2 = new Cookie("name", cookie.getName());
|
||||
response.addCookie(cookie2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user