Is it necessary to refer to previous anti-injection documents in languages such as php or java? It’s really hard to find anti-injection documentation related to python
黄舟2017-06-14 10:52:54
1.Pass
cursor.execute("select * from table where name=%s", "name")
Anti-injection.
2.If passed
sql = "select * from table where name=%s" % MySQLdb.escape_string(name)
This format requires MySQLdb.escape_string(name) to prevent injection.
It is recommended to use the first one.
欧阳克2017-06-14 10:52:54
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('webmaster@python.org', 'very-secret'))
One thing I know is not to use sql.format("x1", "x2"), but to pass the parameters to cursor.execute for processing