SQL Injection Detection
Identifies SQL queries built with string concatenation or format strings where user input reaches execution sinks. See patterns.yaml for detection rules.
Detection Workflow
- Import check — look for database packages (
database/sql,gorm,sqlx, ORMs) - Call check — find SQL execution functions (
Query,QueryRow,Exec,Raw) - Context check — check if arguments include string concatenation or
fmt.Sprintf - Taint check — trace whether the concatenated variable is user-controlled (request params, form data, headers)
- Validate — confirm the variable is not a compile-time constant or allow-listed value before reporting
Vulnerable
db.Query("SELECT * FROM users WHERE id = " + userInput)
db.Query(fmt.Sprintf("SELECT * FROM users WHERE id = %s", userInput))
Safe
db.Query("SELECT * FROM users WHERE id = $1", userInput)