Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unsafe raw database query #1332

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion handlers/dashboard_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/utils"
"github.com/uptrace/bun"
)

func (handler *ApiHandler) DashboardStatsHandler(c *gin.Context) {
Expand Down Expand Up @@ -197,7 +198,7 @@ func (handler *ApiHandler) CostBreakdownHandler(c *gin.Context) {
return
}
} else {
err = handler.db.NewRaw(fmt.Sprintf(`%s DATE(fetched_at) BETWEEN '%s' AND '%s' GROUP BY period, %s;`, query, input.Start, input.End, input.Group)).Scan(handler.ctx, &groups)
err = handler.db.NewRaw(`? DATE(fetched_at) BETWEEN ? AND ? GROUP BY period, ?;`, query, bun.Ident(input.Start), bun.Ident(input.End), input.Group).Scan(handler.ctx, &groups)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
Expand Down
Loading