Skip to content

Conversation

@picatz
Copy link
Owner

@picatz picatz commented Jul 4, 2025

Summary

  • detect SQL injection in more Go SQL packages
  • add stub and tests for xorm
  • include more packages in README and analyzer
  • fix minor typos
  • add tests for go-pg, rqlite, squirrel, alt gorm path, sqlite3 driver
  • improve query argument handling for function sinks

Testing

  • go fmt ./...
  • go test ./...

https://chatgpt.com/codex/tasks/task_e_6867eda11a8483319c076a37c0dc5edf

@picatz picatz requested a review from Copilot July 4, 2025 15:56

This comment was marked as outdated.

@picatz picatz requested a review from Copilot July 6, 2025 19:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR expands SQL injection detection to additional Go SQL packages by adding stubs, tests, and updating the analyzer and README.

  • Added mock implementations and test cases for xorm, go-pg, rqlite, squirrel, sqlx, etc.
  • Extended injectableSQLMethods and imports logic to cover more SQL libraries and improved query-argument handling.
  • Updated README to list newly supported packages and fixed minor typos.

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sql/injection/testdata/src/xorm.io/xorm/mock.go Added xorm engine and session stubs for new SQLi tests
sql/injection/testdata/src/[n–v]/main.go Introduced test apps triggering SQL sinks in various packages
sql/injection/injection.go Expanded sinks list, improved imports recursion and arg logic
sql/injection/injection_test.go Added TestNTestV for new testdata directories
README.md Listed additional supported SQL packages and fixed typos
Comments suppressed due to low confidence (1)

README.md:84

  • [nitpick] For better readability, sort the list of supported SQL packages alphabetically or group them by category (e.g., drivers, ORM libraries).
Supported SQL packages include:

var userControlledValues = taint.NewSources(
// Function (and method) calls
// Function (and method) calls that are user controlled
// over the netork. These are all taken into account as
Copy link

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spelling of 'netork' to 'network'.

Suggested change
// over the netork. These are all taken into account as
// over the network. These are all taken into account as

Copilot uses AI. Check for mistakes.
if strings.HasSuffix(imp.Path(), pkg) {
imported = true
break
if strings.HasSuffix(p.Path(), pkg) {
Copy link

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using exact import path matching (e.g., p.Path() == pkg) instead of suffix matching to avoid accidental false positives when package paths share common suffixes.

Suggested change
if strings.HasSuffix(p.Path(), pkg) {
if p.Path() == pkg {

Copilot uses AI. Check for mistakes.
"(*github.com/jinzhu/gorm.DB).Raw",
"(*github.com/jinzhu/gorm.DB).Exec",
"(*github.com/jinzhu/gorm.DB).Order",
// GORM v2
Copy link

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The injectableSQLMethods list is growing large and repetitive; consider grouping method patterns per package or generating this list programmatically to simplify future maintenance.

Copilot uses AI. Check for mistakes.

// Skip the context argument, if using a *Context query variant.
if strings.HasPrefix(queryEdge.Site.Value().Call.Value.String(), "Context") {
if strings.HasSuffix(queryEdge.Site.Value().Call.Value.String(), "Context") {
Copy link

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Relying on string suffix matching may be brittle; consider inspecting the method's name or signature directly (e.g., using Signature().Name()) to accurately detect Context variants like QueryContext, ExecContext, etc.

Suggested change
if strings.HasSuffix(queryEdge.Site.Value().Call.Value.String(), "Context") {
if strings.Contains(queryEdge.Site.Common().Signature().Name(), "Context") {

Copilot uses AI. Check for mistakes.
@picatz picatz merged commit 1f58616 into main Jul 6, 2025
1 check passed
@picatz picatz deleted the codex/extend-sqli-analysis-for-more-go-sql-packages branch July 6, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants