-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Revert "Fix code scanning alert no. 10: Database query built from user-controlled sources" #588
Conversation
…r-controlled sources"
@@ -177,7 +177,7 @@ | |||
|
|||
if err := ss.Session.Debug(). | |||
Table("user_settings"). | |||
Where("guid = ? AND username = ?", userObject.GUID, UserName).Find(&data).Error; err != nil { | |||
Where(sqlWhere).Find(&data).Error; err != nil { |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
This query depends on a
user-provided value
This query depends on a
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 20 days ago
To fix the problem, we should ensure that user-provided values are safely embedded into the SQL query using parameterized queries. GORM already provides a way to safely handle user input by using maps in the Where
method. However, we should explicitly use parameterized queries to ensure that the values are properly escaped.
We will modify the Get
, Delete
, and Update
methods in the UserSettingsService
to use parameterized queries with named placeholders. This will ensure that the user-provided values are safely embedded into the SQL query.
-
Copy modified lines R170-R171 -
Copy modified lines R174-R175 -
Copy modified lines R177-R178 -
Copy modified line R183 -
Copy modified lines R193-R194 -
Copy modified lines R197-R198 -
Copy modified lines R200-R201 -
Copy modified line R206 -
Copy modified lines R216-R217 -
Copy modified lines R220-R221 -
Copy modified lines R223-R224 -
Copy modified line R231
@@ -169,8 +169,11 @@ | ||
|
||
var sqlWhere = make(map[string]interface{}) | ||
var sqlWhere string | ||
var args []interface{} | ||
|
||
if !isAdmin { | ||
sqlWhere = map[string]interface{}{"guid": userObject.GUID, "username": UserName} | ||
sqlWhere = "guid = ? AND username = ?" | ||
args = append(args, userObject.GUID, UserName) | ||
} else { | ||
sqlWhere = map[string]interface{}{"guid": userObject.GUID} | ||
sqlWhere = "guid = ?" | ||
args = append(args, userObject.GUID) | ||
} | ||
@@ -179,3 +182,3 @@ | ||
Table("user_settings"). | ||
Where(sqlWhere).Find(&data).Error; err != nil { | ||
Where(sqlWhere, args...).Find(&data).Error; err != nil { | ||
return data, err | ||
@@ -189,8 +192,11 @@ | ||
|
||
var sqlWhere = make(map[string]interface{}) | ||
var sqlWhere string | ||
var args []interface{} | ||
|
||
if !isAdmin { | ||
sqlWhere = map[string]interface{}{"guid": userObject.GUID, "username": UserName} | ||
sqlWhere = "guid = ? AND username = ?" | ||
args = append(args, userObject.GUID, UserName) | ||
} else { | ||
sqlWhere = map[string]interface{}{"guid": userObject.GUID} | ||
sqlWhere = "guid = ?" | ||
args = append(args, userObject.GUID) | ||
} | ||
@@ -199,4 +205,3 @@ | ||
Table("user_settings"). | ||
Where(sqlWhere). | ||
Delete(model.TableUserSettings{}).Error; err != nil { | ||
Where(sqlWhere, args...).Delete(model.TableUserSettings{}).Error; err != nil { | ||
return err | ||
@@ -210,8 +215,11 @@ | ||
|
||
var sqlWhere = make(map[string]interface{}) | ||
var sqlWhere string | ||
var args []interface{} | ||
|
||
if !isAdmin { | ||
sqlWhere = map[string]interface{}{"guid": userObject.GUID, "username": UserName} | ||
sqlWhere = "guid = ? AND username = ?" | ||
args = append(args, userObject.GUID, UserName) | ||
} else { | ||
sqlWhere = map[string]interface{}{"guid": userObject.GUID} | ||
sqlWhere = "guid = ?" | ||
args = append(args, userObject.GUID) | ||
} | ||
@@ -222,3 +230,3 @@ | ||
Model(&model.TableUserSettings{}). | ||
Where(sqlWhere).Update(userObject).Error; err != nil { | ||
Where(sqlWhere, args...).Update(userObject).Error; err != nil { | ||
return err |
Reverts #587