|
|
@ -41,11 +41,11 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
if(boo){ |
|
|
|
if(boo){ |
|
|
|
// 获取文件名称类型判断是否配置文件权限
|
|
|
|
// 获取文件名称类型判断是否配置文件权限
|
|
|
|
var interiorInvoIf = new InteriorInvoIf(); |
|
|
|
var interiorInvoIf = new InteriorInvoIf(); |
|
|
|
((MethodTree) tree).block().accept(interiorInvoIf); |
|
|
|
interiorInvoIf.check(((MethodTree) tree).block()); |
|
|
|
if(interiorInvoIf.fileType != ""){ |
|
|
|
if(interiorInvoIf.fileType != ""){ |
|
|
|
// 判断是否对文件后缀进行限制
|
|
|
|
// 判断是否对文件后缀进行限制
|
|
|
|
NodeIf nodeIf = new NodeIf(interiorInvoIf.fileType); |
|
|
|
NodeIf nodeIf = new NodeIf(interiorInvoIf.fileType); |
|
|
|
((MethodTree) tree).block().accept(nodeIf); |
|
|
|
nodeIf.check(((MethodTree) tree).block()); |
|
|
|
if (nodeIf.boo){ |
|
|
|
if (nodeIf.boo){ |
|
|
|
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型"); |
|
|
|
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型"); |
|
|
|
} |
|
|
|
} |
|
|
@ -53,7 +53,7 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
if(interiorInvoIf.fileName != ""){ |
|
|
|
if(interiorInvoIf.fileName != ""){ |
|
|
|
// 判断是否对文件后缀进行限制
|
|
|
|
// 判断是否对文件后缀进行限制
|
|
|
|
NodeIf nodeIf = new NodeIf(interiorInvoIf.fileName); |
|
|
|
NodeIf nodeIf = new NodeIf(interiorInvoIf.fileName); |
|
|
|
((MethodTree) tree).block().accept(nodeIf); |
|
|
|
nodeIf.check(((MethodTree) tree).block()); |
|
|
|
if (nodeIf.boo){ |
|
|
|
if (nodeIf.boo){ |
|
|
|
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型"); |
|
|
|
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型"); |
|
|
|
} |
|
|
|
} |
|
|
@ -65,8 +65,7 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
if(interiorInvoIf.sizeName != ""){ |
|
|
|
if(interiorInvoIf.sizeName != ""){ |
|
|
|
// 判断是否对文件大小进行限制
|
|
|
|
// 判断是否对文件大小进行限制
|
|
|
|
NodeIf nodeIf = new NodeIf(interiorInvoIf.sizeName); |
|
|
|
NodeIf nodeIf = new NodeIf(interiorInvoIf.sizeName); |
|
|
|
//nodeIf.check(((MethodTree) tree).block());
|
|
|
|
nodeIf.check(((MethodTree) tree).block()); |
|
|
|
((MethodTree) tree).block().accept(nodeIf); |
|
|
|
|
|
|
|
if (nodeIf.boo){ |
|
|
|
if (nodeIf.boo){ |
|
|
|
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型"); |
|
|
|
context.reportIssue(this, node.simpleName(), "程序设计时,应以“白名单”方式限制允许用户上传的文件的类型"); |
|
|
|
} |
|
|
|
} |
|
|
@ -80,7 +79,7 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 內部文件名称类型获取类
|
|
|
|
// 內部文件名称类型获取类
|
|
|
|
private class InteriorInvoIf extends BaseTreeVisitor { |
|
|
|
private class InteriorInvoIf extends IssuableSubscriptionVisitor{ |
|
|
|
// 文件全名字
|
|
|
|
// 文件全名字
|
|
|
|
public String fileName = ""; |
|
|
|
public String fileName = ""; |
|
|
|
// 文件后缀名
|
|
|
|
// 文件后缀名
|
|
|
@ -91,9 +90,15 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
public boolean privType = true; |
|
|
|
public boolean privType = true; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void visitMethodInvocation(MethodInvocationTree tree) { |
|
|
|
public List<Tree.Kind> nodesToVisit() { |
|
|
|
|
|
|
|
return Collections.singletonList(Tree.Kind.METHOD_INVOCATION); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void visitNode(Tree tree){ |
|
|
|
|
|
|
|
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) tree; |
|
|
|
// 获取到方法调用的参数
|
|
|
|
// 获取到方法调用的参数
|
|
|
|
ExpressionTree expressionTree = tree.methodSelect(); |
|
|
|
ExpressionTree expressionTree = methodInvocationTree.methodSelect(); |
|
|
|
if(expressionTree instanceof MemberSelectExpressionTree){ |
|
|
|
if(expressionTree instanceof MemberSelectExpressionTree){ |
|
|
|
MemberSelectExpressionTree expressionTree1 = (MemberSelectExpressionTree) expressionTree; |
|
|
|
MemberSelectExpressionTree expressionTree1 = (MemberSelectExpressionTree) expressionTree; |
|
|
|
// 对调用方法进行判断
|
|
|
|
// 对调用方法进行判断
|
|
|
@ -132,22 +137,32 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void check(Tree tree){ |
|
|
|
|
|
|
|
this.scanTree(tree); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NodeIf extends BaseTreeVisitor { |
|
|
|
public class NodeIf extends IssuableSubscriptionVisitor{ |
|
|
|
|
|
|
|
|
|
|
|
private String name; |
|
|
|
private String name; |
|
|
|
public boolean boo = true; |
|
|
|
public boolean boo = true; |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public List<Tree.Kind> nodesToVisit() { |
|
|
|
|
|
|
|
return Collections.singletonList(Tree.Kind.IF_STATEMENT); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public NodeIf(String name) { |
|
|
|
public NodeIf(String name) { |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void check(Tree tree){ |
|
|
|
|
|
|
|
this.scanTree(tree); |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void visitIfStatement(IfStatementTree tree) { |
|
|
|
public void visitNode(Tree tree){ |
|
|
|
|
|
|
|
IfStatementTree tree1 = (IfStatementTree) tree; |
|
|
|
// 获取到if表达式
|
|
|
|
// 获取到if表达式
|
|
|
|
ExpressionTree condition = tree.condition(); |
|
|
|
ExpressionTree condition = tree1.condition(); |
|
|
|
if(condition instanceof BinaryExpressionTree){ |
|
|
|
if(condition instanceof BinaryExpressionTree){ |
|
|
|
BinaryExpressionTree binaryExpressionTree = (BinaryExpressionTree) condition; |
|
|
|
BinaryExpressionTree binaryExpressionTree = (BinaryExpressionTree) condition; |
|
|
|
// 判断是否进行if判断
|
|
|
|
// 判断是否进行if判断
|
|
|
|