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

This library is not safe and should not be trusted to prevent SQL Injection Attacks. #2

Closed
kevburnsjr opened this issue Aug 1, 2022 · 2 comments

Comments

@kevburnsjr
Copy link

kevburnsjr commented Aug 1, 2022

Example shows

sql := sqlstring.Format("select * from users where name=? and age=? limit ?,?", "t'est", 10, 10, 10)
fmt.Printf("sql: %s\n", sql)

Outputting

sql: select * from users where name='t\'est' and age=10 limit 10,10

Which is correct. However, this protection can easily be defeated:

sql := sqlstring.Format("select * from users where name=? and age=? limit ?,?", `t\'est`, 10, 10, 10)
fmt.Printf("sql: %s\n", sql)

Outputting

sql: select * from users where name='t\\'est' and age=10 limit 10,10

The double backslash fails to escape the single quote resulting in SQL injection vulnerability.

https://go.dev/play/p/qVnax1F8P9M

@feiin
Copy link
Owner

feiin commented Aug 2, 2022

Thanks for the report @kevburnsjr

feiin added a commit that referenced this issue Aug 3, 2022
@feiin
Copy link
Owner

feiin commented Aug 3, 2022

It has been fixed.

@feiin feiin closed this as completed Aug 3, 2022
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

No branches or pull requests

2 participants