mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -11,8 +11,10 @@ public class WallConfig {
|
||||
|
||||
private boolean selelctAllow = true;
|
||||
private boolean selectIntoAllow = true;
|
||||
private boolean selectIntoOutfileAllow = false;
|
||||
private boolean selectWhereAlwayTrueCheck = true;
|
||||
private boolean selectHavingAlwayTrueCheck = true;
|
||||
private boolean selectUnionCheck = true;
|
||||
|
||||
private boolean deleteAllow = true;
|
||||
private boolean deleteWhereAlwayTrueCheck = true;
|
||||
@@ -90,6 +92,22 @@ public class WallConfig {
|
||||
this.selectIntoAllow = selectIntoAllow;
|
||||
}
|
||||
|
||||
public boolean isSelectIntoOutfileAllow() {
|
||||
return selectIntoOutfileAllow;
|
||||
}
|
||||
|
||||
public void setSelectIntoOutfileAllow(boolean selectIntoOutfileAllow) {
|
||||
this.selectIntoOutfileAllow = selectIntoOutfileAllow;
|
||||
}
|
||||
|
||||
public boolean isSelectUnionCheck() {
|
||||
return selectUnionCheck;
|
||||
}
|
||||
|
||||
public void setSelectUnionCheck(boolean selectUnionCheck) {
|
||||
this.selectUnionCheck = selectUnionCheck;
|
||||
}
|
||||
|
||||
public boolean isSelectWhereAlwayTrueCheck() {
|
||||
return selectWhereAlwayTrueCheck;
|
||||
}
|
||||
|
||||
@@ -167,15 +167,16 @@ public class MySqlWallVisitor extends MySqlASTVisitorAdapter implements WallVisi
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlOutFileExpr x) {
|
||||
violations.add(new IllegalSQLObjectViolation(SQLUtils.toMySqlString(x)));
|
||||
return false;
|
||||
if (!config.isSelectIntoOutfileAllow()) {
|
||||
violations.add(new IllegalSQLObjectViolation(SQLUtils.toMySqlString(x)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLUnionQuery x) {
|
||||
if (WallVisitorUtils.queryBlockFromIsNull(x.getLeft()) || WallVisitorUtils.queryBlockFromIsNull(x.getRight())) {
|
||||
violations.add(new IllegalSQLObjectViolation(SQLUtils.toMySqlString(x)));
|
||||
}
|
||||
WallVisitorUtils.checkUnion(this, x);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -113,9 +113,7 @@ public class OracleWallVisitor extends OracleASTVIsitorAdapter implements WallVi
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLUnionQuery x) {
|
||||
if (WallVisitorUtils.queryBlockFromIsNull(x.getLeft()) || WallVisitorUtils.queryBlockFromIsNull(x.getRight())) {
|
||||
violations.add(new IllegalSQLObjectViolation(SQLUtils.toMySqlString(x)));
|
||||
}
|
||||
WallVisitorUtils.checkUnion(this, x);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.alibaba.druid.filter.wall.IllegalSQLObjectViolation;
|
||||
import com.alibaba.druid.filter.wall.WallVisitor;
|
||||
import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
@@ -36,6 +37,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlBooleanExpr;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
@@ -59,7 +61,7 @@ public class WallVisitorUtils {
|
||||
visitor.getViolations().add(new IllegalSQLObjectViolation(visitor.toSQL(x)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!visitor.getConfig().isSelectWhereAlwayTrueCheck()) {
|
||||
return;
|
||||
}
|
||||
@@ -445,6 +447,16 @@ public class WallVisitorUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkUnion(WallVisitor visitor, SQLUnionQuery x) {
|
||||
if (!visitor.getConfig().isSelectUnionCheck()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (WallVisitorUtils.queryBlockFromIsNull(x.getLeft()) || WallVisitorUtils.queryBlockFromIsNull(x.getRight())) {
|
||||
visitor.getViolations().add(new IllegalSQLObjectViolation(SQLUtils.toMySqlString(x)));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean queryBlockFromIsNull(SQLSelectQuery query) {
|
||||
if (query instanceof SQLSelectQueryBlock) {
|
||||
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query;
|
||||
|
||||
Reference in New Issue
Block a user