1 Star 1 Fork 20

吴文凯 / gen

forked from gorm / gen 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sec_check.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
package gen
import (
"fmt"
"gorm.io/gorm/clause"
"gorm.io/hints"
)
func checkConds(conds []clause.Expression) error {
for _, cond := range conds {
if err := checkClause(cond); err != nil {
return err
}
}
return nil
}
var banClauses = map[string]bool{
"INSERT": true,
"VALUES": true,
// "ON CONFLICT": true,
"SELECT": true,
"FROM": true,
"WHERE": true,
"GROUP BY": true,
"ORDER BY": true,
"LIMIT": true,
"FOR": true,
"UPDATE": true,
"SET": true,
"DELETE": true,
}
func checkClause(cond clause.Expression) error {
switch cond := cond.(type) {
case hints.Hints, hints.IndexHint:
return nil
case clause.OnConflict:
return checkOnConflict(cond)
case clause.Interface:
if banClauses[cond.Name()] {
return fmt.Errorf("clause %s is banned", cond.Name())
}
return nil
}
return fmt.Errorf("unknown clause %v", cond)
}
func checkOnConflict(cond clause.OnConflict) error {
for _, item := range cond.DoUpdates {
switch item.Value.(type) {
case clause.Expr, *clause.Expr:
return fmt.Errorf("OnConflict clause assignment with gorm.Expr is banned for security reasons for now")
}
}
return nil
}
Go
1
https://gitee.com/whilew/gen.git
git@gitee.com:whilew/gen.git
whilew
gen
gen
v0.1.38

搜索帮助