扫码关注官方订阅号
有没有必要参考以往的php或者java之类的语言的防注入文档呢?python相关的防注入文档实在不好找
1.通过
cursor.execute("select * from table where name=%s", "name")
可以防注入。
2.如果通过
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'))
我知道的一点是不要使用 sql.format("x1", "x2"), 要把参数传给cursor.execute去处理
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
1.通过
可以防注入。
2.如果通过
这种格式,需要MySQLdb.escape_string(name),可以防注入.
推荐使用第一种。
我知道的一点是不要使用 sql.format("x1", "x2"), 要把参数传给cursor.execute去处理