Skip to content

Instantly share code, notes, and snippets.

@tylerstillwater
Created June 10, 2020 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerstillwater/99311a4e20dc63b98e844ecb2aa61189 to your computer and use it in GitHub Desktop.
Save tylerstillwater/99311a4e20dc63b98e844ecb2aa61189 to your computer and use it in GitHub Desktop.
Example of failed SQL Language type injection for GoLand
package main
import "database/sql"
type executor struct {
db *sql.DB
}
func (e executor) exec(query string) {
e.db.Exec(query)
}
func main() {
e := executor{}
testDirect(nil)
testExecutor(e)
}
func testDirect(db *sql.DB) {
// this DOES inject SQL as the language for the fragment below
const exampleQuery = `
SELECT user_id,
first_name,
last_name
FROM users
WHERE user_id = :user_id;
`
db.Exec(exampleQuery)
}
func testExecutor(e executor) {
// this DOES NOT inject SQL as the language for the fragment below
const exampleQuery = `
SELECT user_id,
first_name,
last_name
FROM users
WHERE user_id = :user_id;
`
e.exec(exampleQuery)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment