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: scan list in global security page sql injection fix #5808

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,13 @@

func (impl ImageScanDeployInfoRepositoryImpl) ScanListingWithFilter(request *securityBean.ImageScanFilter, size int, offset int, deployInfoIds []int) ([]*ImageScanListingResponse, error) {
var models []*ImageScanListingResponse
var err error
query := impl.scanListingQueryBuilder(request, size, offset, deployInfoIds)
_, err := impl.dbConnection.Query(&models, query, size, offset)
if len(request.Severity) > 0 {
_, err = impl.dbConnection.Query(&models, query, pg.In(request.Severity), pg.In(request.Severity))

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query depends on a
user-provided value
.
} else {
_, err = impl.dbConnection.Query(&models, query)

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query depends on a
user-provided value
.
}
if err != nil {
impl.logger.Error("err", err)
return []*ImageScanListingResponse{}, err
Expand Down Expand Up @@ -177,8 +182,8 @@
query = query + " AND res.cve_store_name ILIKE '%" + request.CVEName + "%'"
}
if len(request.Severity) > 0 {
severities := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(request.Severity)), ","), "[]")
query = query + fmt.Sprintf(" AND (cs.standard_severity IN (%s) OR (cs.severity IN (%s) AND cs.standard_severity IS NULL))", severities, severities)
// use pg.In to inject values here wherever calling this func in case severity exists, to avoid sql injections
query = query + " AND (cs.standard_severity IN (?) OR (cs.severity IN (?) AND cs.standard_severity IS NULL))"
}
if len(request.EnvironmentIds) > 0 {
envIds := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(request.EnvironmentIds)), ","), "[]")
Expand Down Expand Up @@ -239,8 +244,7 @@
}

if len(request.Severity) > 0 {
severities := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(request.Severity)), ","), "[]")
query = query + fmt.Sprintf(" AND (cs.standard_severity IN (%s) OR (cs.severity IN (%s) AND cs.standard_severity IS NULL))", severities, severities)
query = query + " AND (cs.standard_severity IN (?) OR (cs.severity IN (?) AND cs.standard_severity IS NULL))"
}
if len(request.EnvironmentIds) > 0 {
envIds := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(request.EnvironmentIds)), ","), "[]")
Expand Down
Loading