有沒(méi)有必要參考以往的php或者java之類的語(yǔ)言的防注入文檔呢?python相關(guān)的防注入文檔實(shí)在不好找
1.通過(guò)
cursor.execute("select * from table where name=%s", "name")
可以防注入。
2.如果通過(guò)
sql = "select * from table where name=%s" % MySQLdb.escape_string(name)
這種格式,需要MySQLdb.escape_string(name),可以防注入.
推薦使用第一種。
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('webmaster@python.org', 'very-secret'))
我知道的一點(diǎn)是不要使用 sql.format("x1", "x2"), 要把參數(shù)傳給cursor.execute去處理