// Rule: 检查DoS漏洞 from MethodAccess methodAccess, Method method, Parameter parameter, ClassType classType, Expr pageSize, Expr list where methodAccess.getMethod() = method and methodAccess.getArgument(parameter.getIndex()) = pageSize and methodAccess.getMethod().getDeclaringType() = classType and methodAccess.getQualifier() = classType and hasUnrestrictedQuery(_, pageSize) or hasUnrestrictedPageSize(pageSize) or hasUnrestrictedParameter(classType, parameter) or hasUnrestrictedListSize(list) select methodAccess, "Potential DoS vulnerability: unrestricted parameter usage"
/** * @name Arbitrary file write during archive extraction ("Zip Slip") * @description Extracting files from a malicious archive without validating that the * destination file path is within the destination directory can cause files outside * the destination directory to be overwritten. * @kind path-problem * @id java/zipslip * @problem.severity error * @security-severity 7.5 * @precision high * @tags security * external/cwe/cwe-022 * Zip Slip是一个广泛存在的关键存档提取(critical archive extraction)漏洞, * 该漏洞允许攻击者在系统中任意写文件,尤其是会导致远程命令执行。 * * zip解压,任意文件上传 * source应该是识别外面输入的压缩文件 * sink应该是解压操作 */
// ZipSlipFlow 也是调用的 DataFlow::Node,识别sink为 archive entry // A sink that represents a file creation, such as a file write, copy or move operation. from ZipSlipFlow::PathNode source, ZipSlipFlow::PathNode sink where ZipSlipFlow::flowPath(source, sink) select source.getNode(), source, sink, "Unsanitized archive entry, which may contain '..', is used in a $@.", sink.getNode(), "file system operation"
// from Class c, Parameter p // where p.getType().(Class) = c // // and not exists(c.getName().indexOf("<")) // and c.getName() = "MultipartFile" // // c.getAField().getType() // select c.getName(), c.getAField(), c.getAField().getType(), p.getName()
// 判断方法中是否包含类参数 // predicate isListParameter(MethodAccess m) { // exists(Class c | m.getParameter) // }
predicate hasSize(Class c){ exists(Annotation a, Parameter p | p.getType().(Class) = c and not exists(c.getName().indexOf("<")) and exists(c.getAField().toString().indexOf("List<")) and a.getAnnotatedElement() = c.getAField() and a.toString() = "Size" ) }