Query to detect unsafe request dispatcher usage

This commit is contained in:
luchua-bc
2021-12-02 04:00:29 +00:00
parent 9f8326a3fa
commit 8bcffc2886
11 changed files with 543 additions and 21 deletions

View File

@@ -347,3 +347,27 @@ predicate isRequestGetParamMethod(MethodAccess ma) {
ma.getMethod() instanceof ServletRequestGetParameterMapMethod or
ma.getMethod() instanceof HttpServletRequestGetQueryStringMethod
}
/** The Java EE RequestDispatcher. */
library class RequestDispatcher extends RefType {
RequestDispatcher() {
this.hasQualifiedName(["javax.servlet", "jakarta.servlet"], "RequestDispatcher") or
this.hasQualifiedName("javax.portlet", "PortletRequestDispatcher")
}
}
/** The `getRequestDispatcher` method. */
library class GetRequestDispatcherMethod extends Method {
GetRequestDispatcherMethod() {
this.getReturnType() instanceof RequestDispatcher and
this.getName() = "getRequestDispatcher"
}
}
/** The request dispatch method. */
library class RequestDispatchMethod extends Method {
RequestDispatchMethod() {
this.getDeclaringType() instanceof RequestDispatcher and
this.hasName(["forward", "include"])
}
}