-
Notifications
You must be signed in to change notification settings - Fork 0
Fix CodeQL issues #14
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
base: main
Are you sure you want to change the base?
Conversation
| err := GetQueue().EnqueueOperation(func() error { | ||
| var err error | ||
| rows, err = db.Query(query, args...) | ||
| stmt, err := db.Prepare(query) |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the problem, we need to ensure that user-provided data is safely embedded into SQL queries using placeholder parameters or prepared statements. Specifically, we should avoid directly concatenating user-provided keys into the query string. Instead, we can use a switch-case or if-else structure to handle different keys and construct the query string safely.
- Modify the
QueryCoursefunction indatabase/course.goto use a switch-case structure to handle different keys and construct the query string safely. - Ensure that the
QueuedQueryfunction indatabase/queue.gouses the constructed query string with placeholder parameters.
-
Copy modified lines R227-R228 -
Copy modified lines R232-R233 -
Copy modified lines R235-R236 -
Copy modified lines R238-R239 -
Copy modified line R242
| @@ -226,2 +226,4 @@ | ||
| var err error | ||
| var query string | ||
| var args []interface{} | ||
|
|
||
| @@ -229,9 +231,13 @@ | ||
| case "title": | ||
| rows, err = QueuedQuery("SELECT term_crn FROM courses WHERE title LIKE ?", "%"+values[0]+"%") | ||
| query = "SELECT term_crn FROM courses WHERE title LIKE ?" | ||
| args = append(args, "%"+values[0]+"%") | ||
| case "subject-number": | ||
| rows, err = QueuedQuery("SELECT term_crn FROM courses WHERE subject_code = ? AND course_number LIKE ?", values[0], "%"+values[1]+"%") | ||
| query = "SELECT term_crn FROM courses WHERE subject_code = ? AND course_number LIKE ?" | ||
| args = append(args, values[0], "%"+values[1]+"%") | ||
| default: | ||
| rows, err = QueuedQuery("SELECT term_crn FROM courses WHERE "+key+" = ?", values[0]) | ||
| query = "SELECT term_crn FROM courses WHERE " + key + " = ?" | ||
| args = append(args, values[0]) | ||
| } | ||
|
|
||
| rows, err = QueuedQuery(query, args...) | ||
| if err != nil { |
No description provided.