xjlgod commented on code in PR #8032:
URL: https://github.com/apache/incubator-seata/pull/8032#discussion_r3784669536


##########
console/src/main/java/org/apache/seata/mcp/store/SqlSafetyValidator.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.mcp.store;
+
+import com.alibaba.druid.DbType;
+import com.alibaba.druid.sql.SQLUtils;
+import com.alibaba.druid.sql.ast.SQLStatement;
+import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
+import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
+import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
+import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
+import com.alibaba.druid.stat.TableStat;
+import org.apache.seata.common.exception.StoreException;
+import org.apache.seata.common.util.StringUtils;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Locale;
+
+@Component
+public class SqlSafetyValidator {
+
+    private static final String UNDO_LOG_TABLE = "undo_log";
+
+    public SQLSelectStatement validateMysqlSelect(String sql) {
+        if (StringUtils.isBlank(sql)) {
+            throw new StoreException("SQL cannot be empty");
+        }
+        List<SQLStatement> statements;
+        try {
+            statements = SQLUtils.parseStatements(sql, DbType.mysql);
+        } catch (Exception e) {
+            throw new StoreException("SQL parse failed");
+        }
+        if (statements.size() != 1) {
+            throw new StoreException("Only a single SELECT statement is 
allowed");
+        }
+        SQLStatement statement = statements.get(0);
+        if (!(statement instanceof SQLSelectStatement)) {
+            throw new StoreException("Only SELECT statements are allowed");
+        }
+        SQLSelectStatement selectStatement = (SQLSelectStatement) statement;

Review Comment:
   Please also reject `SELECT ... INTO OUTFILE/DUMPFILE`. They are SELECT 
statements, but they can write files on the database server. Should we care 
about this?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to