Factor isGetServletMethod into the servlet library

This commit is contained in:
luchua-bc
2021-01-04 16:14:13 +00:00
parent ffe9d4a310
commit 496db4b42f
2 changed files with 12 additions and 8 deletions

View File

@@ -23,18 +23,13 @@ class SensitiveInfoExpr extends Expr {
}
}
/** GET servlet method of `javax.servlet.http.Servlet` and subtypes. */
private predicate isGetServletMethod(Callable c) {
c.getDeclaringType() instanceof ServletClass and
c.getNumberOfParameters() = 2 and
c.getParameter(1).getType() instanceof ServletResponse and
c.getName() = "doGet"
}
/** Holds if `c` is a call to some override of `HttpServlet.doGet`. */
private predicate isGetServletMethod(Callable c) { isServletMethod(c, "doGet") }
/** Sink of GET servlet requests. */
class GetServletMethodSink extends DataFlow::ExprNode {
GetServletMethodSink() {
exists(Method m, MethodAccess ma | ma.getMethod() = m |
exists(MethodAccess ma |
isGetServletMethod(ma.getEnclosingCallable()) and
ma.getAnArgument() = this.getExpr()
)

View File

@@ -322,3 +322,12 @@ class ServletWebXMLListenerType extends RefType {
// - `HttpSessionBindingListener`
}
}
/** Holds if `c` is a call to some override of methods of `HttpServlet`, for example `doGet` or `doPost`. */
predicate isServletMethod(Callable c, string methodName) {
c.getDeclaringType() instanceof ServletClass and
c.getNumberOfParameters() = 2 and
c.getParameter(0).getType() instanceof ServletRequest and
c.getParameter(1).getType() instanceof ServletResponse and
c.getName() = methodName
}