文章详情页
python 操作mysql如何经量防止自己的程序在之后被恶意注入(说白了就是问一下python防注入的一些要点)
浏览:62日期:2022-06-11 13:45:45
问题描述
有没有必要参考以往的php或者java之类的语言的防注入文档呢?python相关的防注入文档实在不好找
问题解答
回答1: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),可以防注入.
推荐使用第一种。
回答2:sql = 'INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)'cursor.execute(sql, (’webmaster@python.org’, ’very-secret’))
我知道的一点是不要使用 sql.format('x1', 'x2'), 要把参数传给cursor.execute去处理
相关文章:
1. 一个走错路的23岁傻小子的提问2. c++ - win764位环境下,我用GCC为什么指针占8个字节,而long是4个字节?3. html5 - HTML代码中的文字乱码是怎么回事?4. angular.js - angularjs 使用鼠标悬停时,标签一直闪5. java - Hibernate查询的数据是存放在session中吗?6. java - 安卓电视盒子取得了root权限但是不能安装第三方应用,请问该怎么办?7. node.js - 函数getByName()中如何使得co执行完后才return8. python 计算两个时间相差的分钟数,超过一天时计算不对9. python - django 里自定义的 login 方法,如何使用 login_required()10. javascript - SuperSlide.js火狐不兼容怎么回事呢
排行榜
