这是 codeigniter 漏洞吗?
我在 CodeIgniter 中的分页脚本上发现了一个错误:
$this->db->where("by_id",$user_id);
$this->db->order_by("date","desc");
$this->db->limit(10,$from);
$query = $this->db->get("status");
url 如下所示: server/demo/page/10
所以如果用户输入 server/nedjma/baniss/1000000000000000000000
错误号:1064
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 5 行“1000000000000000000000, 10”附近使用的正确语法
SELECT * FROM (
status
) WHEREby_id
= '58' ORDER BYdate
desc LIMIT 1000000000000000000000, 10
你能告诉我有什么错误吗?
I discovered an error on my pagination script within CodeIgniter:
$this->db->where("by_id",$user_id);
$this->db->order_by("date","desc");
$this->db->limit(10,$from);
$query = $this->db->get("status");
The url looks like this : server/demo/page/10
so if user type server/nedjma/baniss/1000000000000000000000
Error Number: 1064
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 '1000000000000000000000, 10' at line 5
SELECT * FROM (
status
) WHEREby_id
= '58' ORDER BYdate
desc LIMIT 1000000000000000000000, 10
can you tell me please what's the bug ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是 CodeIgniter 漏洞或错误。这只是一个 SQL/MySQL 问题。我用 phpMyAdmin 做了一些测试,您可以使用的最大偏移量约为 18000000000000000000。
任何更大的偏移量,您都会收到 SQL 语法错误。如果您想防止发生此错误,只需检查以确保
$from
不大于 18 x 10^18,或者创建您自己的自定义错误页面。您也可以关闭错误报告 - 在 CI 的 index.php 顶部,error_reporting(0);
最后一点 - 您发布的代码不支持 SQL 注入。 CodeIgniter 的 Active Record 类会转义并检查您的输入。如果
$from
不是数字,则 Active Record 在创建 SQL 时不会生成 LIMIT 子句。It's not a CodeIgniter vulnerability or bug. It's simply an SQL/MySQL issue. I did a little testing with phpMyAdmin, the largest offset you can use is somewhere around 18000000000000000000.
Anything larger, and you will get an SQL syntax error. If you want to prevent this error from happening, just check to make sure
$from
isn't greater than 18 x 10^18, or create your own custom error pages. You could also just turn error reporting off - at the top of CI's index.php,error_reporting(0);
One final note - the code you posted isn't open to SQL injection. CodeIgniter's Active Record class escapes and checks your input for you. If
$from
is not a number, then Active Record won't generate a LIMIT clause when creating the SQL.