多谢各位,另,测的时候第一次发现mysql中select userID,password from user where userID
='3810752;insert into t values(883)' 执行结果等价于 select userID,password
from user where userID =3810752,神奇。。。
On May 4, 4:06 pm, agentzh <agen...@gmail.com> wrote:
> 2012/5/4 huang kun <kun...@gmail.com>:
>
> > 正在使用ngx_lua+lua-resty-mysql,有什么方法可以比较方便的避免SQL注入呢?
>
> ngx_lua 提供了一个没有文档的 ngx.quote_sql_str() 方法,用法是:
>
> local quoted_value = ngx.quote_sql_str(value)
>
> 当然,通过 ndk.set_var API 访问 ngx_set_misc 模块的 set_quote_sql_str 指令也是可以的,例如:
>
> local quoted_value = ndk.set_var.set_quote_sql_str(value)
>
> 不过你需要确保 ngx_set_misc 已包含在你的 nginx 中(默认的 openresty 是包含的)。当然,第一种方法比第二种更加高效一些。
>
> Best regards,
> -agentzh