fix sql inject

This commit is contained in:
UlricQin 2021-01-12 18:38:12 +08:00
parent 7161c1ac4e
commit 903a1654b6
1 changed files with 7 additions and 2 deletions

View File

@ -411,14 +411,19 @@ func (n *Node) RoleList(username string, limit, offset int) ([]NodeRole, error)
sql = fmt.Sprintf(sql, n.Id, n.Path+".%")
var args []interface{}
if username != "" {
sql += fmt.Sprintf(" and node_role.username = '%s'", username)
sql += fmt.Sprintf(" and node_role.username = ?")
args = append(args, username)
}
sql += " order by node.path limit ? offset ?"
args = append(args, limit)
args = append(args, offset)
var objs []NodeRole
err := DB["rdb"].SQL(sql, limit, offset).Find(&objs)
err := DB["rdb"].SQL(sql, args...).Find(&objs)
return objs, err
}