Created
June 10, 2020 17:20
-
-
Save tylerstillwater/99311a4e20dc63b98e844ecb2aa61189 to your computer and use it in GitHub Desktop.
Example of failed SQL Language type injection for GoLand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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