Skip to content

Commit

Permalink
better sql injection protection
Browse files Browse the repository at this point in the history
  • Loading branch information
ghernandez345 committed Sep 30, 2024
1 parent c8c718b commit e141764
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions server/datastore/mysql/maintained_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"errors"
"fmt"

"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
"github.com/fleetdm/fleet/v4/server/fleet"
Expand Down Expand Up @@ -129,11 +128,15 @@ WHERE NOT EXISTS (
)
)`

if opt.MatchQuery != "" {
stmt += fmt.Sprintf(`AND (fla.name LIKE '%%%s%%')`, opt.MatchQuery)
args := []any{teamID, teamID}

if match := opt.MatchQuery; match != "" {
match = likePattern(match)
stmt += ` AND (fla.name LIKE ?)`
args = append(args, match)
}

stmtPaged, args := appendListOptionsWithCursorToSQL(stmt, []any{teamID, teamID}, &opt)
stmtPaged, args := appendListOptionsWithCursorToSQL(stmt, args, &opt)

var avail []fleet.MaintainedApp
if err := sqlx.SelectContext(ctx, ds.reader(ctx), &avail, stmtPaged, args...); err != nil {
Expand Down

0 comments on commit e141764

Please sign in to comment.