问题描述
%s的概念是将数据与查询隔离。当您传递两个参数时,它们将在模块中组合。目的是减轻注入,但我会犹豫地说“ 100%”
编辑:比我更聪明的人(甚至是现实生活中的安全专家!)在这里也很重要:https://security.stackexchange.com/questions/15214/are-prepared- statements-100-safe-against-sql- injection
解决方法
请让我知道以下代码会100%阻止python中的SQL注入
样品1
username = request.GET('username') # non-filtered user input
connection.execute("SELECT id,name,email FROM user WHERE username=%s LIMIT 1",(username,))
样品2
username = request.POST('username') # non-filtered user input
name = request.POST('name') # non-filtered user input
email = request.POST('email') # non-filtered user input
connection.execute("UPDATE user SET name=%s,email= %s WHERE username=%s LIMIT 1",(name,email,username,))