Skip to content

Commit

Permalink
fix(orchestrator):repair sql injection again
Browse files Browse the repository at this point in the history
  • Loading branch information
jing-zhi committed Sep 26, 2023
1 parent 04fe227 commit 85f7d7c
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,18 @@ func (r *InstanceReader) ByContainerID(id string) *InstanceReader {
}
func (r *InstanceReader) ByServiceType(tp string) *InstanceReader {
r.conditions = append(r.conditions, fmt.Sprintf("service_type = \"%s\"", tp))
r.values = append(r.values, tp)
return r
}
func (r *InstanceReader) ByPhase(phase string) *InstanceReader {
r.conditions = append(r.conditions, fmt.Sprintf("phase = \"%s\"", phase))
return r
}
func (r *InstanceReader) ByPhases(phases ...string) *InstanceReader {
phasesSlice := phases
phasesStr := strutil.Map(phases, func(s string) string { return "\"" + s + "\"" })
r.conditions = append(r.conditions, fmt.Sprintf("phase in (%s)", strutil.Join(phasesStr, ",")))
r.values = append(r.values, phasesSlice)
return r
}
func (r *InstanceReader) ByFinishedTime(beforeNday int) *InstanceReader {
Expand Down Expand Up @@ -164,7 +167,7 @@ func (r *InstanceReader) Limit(n int) *InstanceReader {
}
func (r *InstanceReader) Do() ([]InstanceInfo, error) {
instanceinfo := []InstanceInfo{}
expr := r.db.Where(strutil.Join(r.conditions, " AND ", true), r.values...).Order("started_at desc")
expr := r.db.Where("org_id = ? AND application_id = ? AND service_type = ? AND phase in (?)", r.values...).Order("started_at desc")
if r.limit != 0 {
expr = expr.Limit(r.limit)
}
Expand Down

0 comments on commit 85f7d7c

Please sign in to comment.