
1 fanzheng 2012-09-21 20:24:40 +08:00 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-09-21 20:32:30 +08:00 我现在在犹豫要不要用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-09-21 21:23:45 +08:00 |
5 fanzheng 2012-09-21 21:26:39 +08:00 他说不要这样 user = query_db('select * from users where username = %s' % 请求的参数) 因为%s 里面可以另外构造一个SQL语句。 |
7 gamexg 2012-09-22 09:10:07 +08:00 &bsp; user = query_db('select * from users where username = ?', [the_username], One=True) 这里系统会自动对危险字符进行转义。一般将客户端输入的内容作为 query_db 之类函数参数进行提交的都不用担心注入,而自己通过 %s 之类的构建查询字符串就要小心了。 |
8 stackpop 2012-09-22 17:43:53 +08:00 我用django是自己实现了一个简单的db类 |