Java: adjust BarrierPrefix to handle prepended chars

This commit is contained in:
Jami Cogswell
2024-03-13 16:27:25 -04:00
parent 5ac453eb38
commit 1b01f26d09
2 changed files with 4 additions and 3 deletions

View File

@@ -71,6 +71,8 @@ private class BarrierPrefix extends InterestingPrefix {
// Matches strings that look like when prepended to untrusted input, they will restrict
// the path of a URL: for example, anything containing `?` or `#`.
exists(this.getStringValue().regexpFind("[?#]", 0, offset))
or
this.(CharacterLiteral).getValue() = ["?", "#"] and offset = 0
}
override int getOffset() { result = offset }

View File

@@ -389,7 +389,7 @@ public class UrlForwardTest extends HttpServlet implements Filter {
}
}
// Test `StringBuilder.append` sequence with `?` appended before the user input
// GOOD: char `?` appended before the user input
private static final String LOGIN_URL = "/UI/Login";
public void doPost2(HttpServletRequest request, HttpServletResponse response)
@@ -399,14 +399,13 @@ public class UrlForwardTest extends HttpServlet implements Filter {
String queryString = request.getQueryString();
// should be sanitized due to the `?` appended
forwardUrl.append('?').append(queryString);
String fUrl = forwardUrl.toString();
ServletConfig config = getServletConfig();
RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(fUrl); // $ SPURIOUS: hasUrlForward
RequestDispatcher dispatcher = config.getServletContext().getRequestDispatcher(fUrl);
dispatcher.forward(request, response);
}
}