mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-04 08:26:24 +08:00
fix: whitelist names of embed models
This commit is contained in:
@@ -24,6 +24,16 @@ func (m *{{.TableName}}) TableName() string {
|
||||
return "{{.RawTableName}}"
|
||||
}
|
||||
{{end}}
|
||||
`
|
||||
|
||||
tableColumnsTmpl *template.Template
|
||||
tableColumnsTmplRaw = `
|
||||
// {{.TableName}}ColumnNames Whitelist for custom query fields to prevent sql injection attacks
|
||||
var {{.TableName}}ColumnNames = map[string]bool{
|
||||
{{- range .Fields}}
|
||||
"{{.ColName}}": true,
|
||||
{{- end}}
|
||||
}
|
||||
`
|
||||
|
||||
modelTmpl *template.Template
|
||||
@@ -730,6 +740,10 @@ func initTemplate() {
|
||||
if err != nil {
|
||||
errSum = errors.Wrap(err, "modelStructTmplRaw")
|
||||
}
|
||||
tableColumnsTmpl, err = template.New("tableColumns").Parse(tableColumnsTmplRaw)
|
||||
if err != nil {
|
||||
errSum = errors.Wrap(err, "tableColumnsTmplRaw")
|
||||
}
|
||||
modelTmpl, err = template.New("goFile").Parse(modelTmplRaw)
|
||||
if err != nil {
|
||||
errSum = errors.Wrap(errSum, "modelTmplRaw:"+err.Error())
|
||||
|
Reference in New Issue
Block a user