Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Injection Prevention in Python - is using parameterized query enough?

I have the following python code:

row = conn.execute('''SELECT admin FROM account WHERE password = ?''',
(request.headers.get('X-Admin-Pass'),)).fetchone()

My question is whether this code is secure for SQL injection? Since I use parameterized query it should be. However, since I am passing user information straight from the header, I am a little worried :)

Any thoughts about the issue?

like image 526
oldbam Avatar asked Nov 28 '25 15:11

oldbam


1 Answers

The way that you are inserting the data into the database will ensure that an SQL attack will not work, the execute method will automatically escape the parameters that you passed as a tuple as its second parameter to the query.

You are doing that correctly.

like image 87
Dominic Santos Avatar answered Dec 01 '25 06:12

Dominic Santos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!