用户
 找回密码
 入住 CI 中国社区
搜索
查看: 17542|回复: 8
收起左侧

CI 防注入方面,到底过滤特殊字符没有?

[复制链接]
发表于 2013-10-26 20:29:01 | 显示全部楼层 |阅读模式
1CI币
本帖最后由 马云 于 2013-10-26 20:30 编辑

用户名:select|inert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|UNION|into|load_file|outfile
密码: select * from admin

echo $name = $this->input->post('name',true);
echo $passwd = $this->input->post('passwd',true);

用上面过滤后输出的内容,跟没过滤一模一样。



添加到数据库后,记录的内容:还是跟没过滤一模一样。






发表于 2013-10-26 21:17:58 | 显示全部楼层
看这里
https://github.com/EllisLab/Code ... sql_driver.php#L301

$this->input->post('name',true);
这个是XSS过滤
手册有注明的
http://codeigniter.org.cn/user_guide/libraries/input.html
回复

使用道具 举报

发表于 2013-10-26 21:24:27 | 显示全部楼层
首先要搞清 xss 过滤,和sql注入是两码事,两个转义的方式不同,你给出的需要过滤的串 不需要转义。
你可以验证xss 过滤 <script> xss 过滤是可以的,至于说防止sql注入,不要怀疑ci 防注入的能力,你可以亲自注入一下。就知道结果了
回复

使用道具 举报

 楼主| 发表于 2013-10-26 21:35:35 | 显示全部楼层
论坛还是有挺多热心的朋友,感谢朋友的回复,
回复

使用道具 举报

 楼主| 发表于 2013-10-26 21:43:00 | 显示全部楼层
lamtin 发表于 2013-10-26 21:17
看这里
https://github.com/EllisLab/CodeIgniter/blob/2.1.4/system/database/drivers/mysql/mysql_driver ...

谢谢版主,我这样写,就是下面的代码,应该不用担心安全问题吧?
$this->db->insert('news', $data); 直接添加到数据库安全吗?入库前需要escape_str过滤吗?

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

        function __construct()
        {
                parent::__construct();
                $this->load->database();
                $this->load->helper('url');
               
                $this->load->helper('form');
        }
       
        function index() {
               
                $data['title'] = '登录';
                $this->load->view('vip/login.php', $data);
               
                echo $name = $this->input->post('name',true);
               
                echo $passwd = $this->input->post('passwd',true);
               
                $this->add();
        }
       
        function add() {
               
                $data['name'] = $this->input->post('name',true);
                $data['passwd'] = $this->input->post('passwd',true);
               
                return $this->db->insert('news', $data);
        }




回复

使用道具 举报

 楼主| 发表于 2013-10-26 21:45:41 | 显示全部楼层
马云 发表于 2013-10-26 21:43
谢谢版主,我这样写,就是下面的代码,应该不用担心安全问题吧?
$this->db->insert('news', $data); 直 ...

刚刚接触CI框架,真的没经验,还请各位朋友多多指教
回复

使用道具 举报

发表于 2013-10-28 16:32:01 | 显示全部楼层
马云 发表于 2013-10-26 21:43
谢谢版主,我这样写,就是下面的代码,应该不用担心安全问题吧?
$this->db->insert('news', $data); 直 ...

这个CI的AR已经帮你处理了.
回复

使用道具 举报

发表于 2013-10-28 17:59:32 | 显示全部楼层
如果这个都没有处理好,还是ci框架吗
回复

使用道具 举报

发表于 2016-6-2 15:40:04 | 显示全部楼层
马云 发表于 2013-10-26 21:43
**** 作者被禁止或删除 内容自动屏蔽 ****

我就是想问问你这个是单个的post数据,要是post所有的数据怎么写。类似这样的  $data = $this->input->post(); $data就是代表全部post过来的数据,这样的应该怎么写。
回复

使用道具 举报

本版积分规则