1
fanzheng 2012 年 9 月 21 日 http://flask.pocoo.org/docs/patterns/sqlite3/#easy-querying
To pass variable parts to the SQL statement, use a question mark in the statement and pass in the arguments as a list. Never directly add them to the SQL statement with string formatting because this makes it possible to attack the application using SQL Injections. |
2
Brutal 2012 年 9 月 21 日
我现在在犹豫要不要用ORM。。。
|
3
loading OP @fanzheng 下面这样就不会被注入了么?
user = query_db('select * from users where username = ?', [the_username], one=True) 请问怎么写的才是能被注入的,上面的我看起来像可以被注入的。。。 例如the_username=";delete * from users" |
4
fanzheng 2012 年 9 月 21 日
|
5
fanzheng 2012 年 9 月 21 日
他说不要这样
user = query_db('select * from users where username = %s' % 请求的参数) 因为%s 里面可以另外构造一个SQL语句。 |
7
gamexg 2012 年 9 月 22 日 user = query_db('select * from users where username = ?',
[the_username], one=True) 这里系统会自动对危险字符进行转义。一般将客户端输入的内容作为 query_db 之类函数参数进行提交的都不用担心注入,而自己通过 %s 之类的构建查询字符串就要小心了。 |
8
stackpop 2012 年 9 月 22 日
我用django是自己实现了一个简单的db类
|