正常是这样的,
order_str = 'id desc'
Post.order(order_str)
但是 order_str 可能是用户输入的,假如
order_str = 'id desc; DELETE from USERS ;'
Post.order(order_str)
后台看到
Post Load (0.5ms) SELECT `posts`.* FROM `posts` ORDER BY id desc; DELETE from USERS
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
SQL 语句是出来的,但攻击就失败了,是 AR 做了防护吗?我是可以给 order_str 加个 whitelist 的,但有点好奇这里为什么会攻击失败。。求指点
参考: rails-sqli