I have been told the following is insecure:
cursor.execute("""SELECT currency FROM exchange_rates WHERE date='%s'"""%(self.date))
Why exactly is the '%s' bad? How would someone actually do a SQL injection here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Imagine if
self.dateis"'; DROP TABLE exchange_rates --". Then you’ll execute:SELECT currency FROM exchange_rates WHERE date=''; DROP TABLE exchange_rates -- 'and boom, you’re hosed. You have to escape the
'so the value ofself.datewill be completely contained in the string, not executed as a query.