Skip to content
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

Fix false negative for SQL injection when using DB.QueryRow.Scan() #757

Closed
wants to merge 17 commits into from

Conversation

kaiili
Copy link
Contributor

@kaiili kaiili commented Jan 9, 2022

Problem

fixes #713

Details :

can be seen in #713.
G201 regexp only match callexpr once.
If there is a sqlquery like the following, there will be problems with matching.

func main() {
	var name string
	db, err := sql.Open("sqlite3", ":memory:")
	if err != nil {
		panic(err)
	}
	q := fmt.Sprintf("SELECT name FROM users where id = '%s'", os.Args[1])
	err = db.QueryRow(q).Scan(&name)
	if err != nil {
		panic(err)
	}
	defer db.Close()
}

Solution

Add an extra check befor checkQuery.

@ccojocar
Copy link
Member

@kaiili Can you please rebase? Thanks

@ccojocar ccojocar changed the title fix issues/713 Fix false negative for SQL injection when using DB.QueryRow.Scan() Jan 10, 2022
@kaiili kaiili closed this Jan 11, 2022
@kaiili
Copy link
Contributor Author

kaiili commented Jan 11, 2022

I rebase my fork repo , and pull request on #759 for wasting some time with this pr, as I'm not very proficient with git.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negative for SQL injection when using DB.QueryRow.Scan()
3 participants