Browse Source

python 指标运算,禁止特殊命令

xyxie 1 year ago
parent
commit
2e94e6fae0
1 changed files with 9 additions and 0 deletions
  1. 9 0
      services/base_from_python.go

+ 9 - 0
services/base_from_python.go

@@ -69,6 +69,15 @@ func ExecPythonCode(edbCode, reqCode string) (dataMap models.EdbDataFromPython,
 		}
 	}()
 
+	// 限制python代码的执行,如果包含特殊的关键词,则报错
+	wordsSlice := strings.Split(edbCode, " ")
+	for _, v := range wordsSlice {
+		if strings.ToLower(v) == "drop" || strings.ToLower(v) == "delete" || strings.ToLower(v) == "update" || strings.ToLower(v) == "alter" || strings.ToLower(v) == "truncate" {
+			err = fmt.Errorf("不支持该命令")
+			return
+		}
+	}
+
 	//获取python文件的绝对地址
 	pythonFile, err := getPythonFileAbsolutePath(edbCode)
 	if err != nil {