马云 发表于 2013-10-26 20:29:01

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

本帖最后由 马云 于 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);

用上面过滤后输出的内容,跟没过滤一模一样。
http://codeigniter.org.cn/forums/data/attachment/album/201310/26/202530rsfyotqto90dwdsr.png


添加到数据库后,记录的内容:还是跟没过滤一模一样。
http://codeigniter.org.cn/forums/data/attachment/album/201310/26/202256ueauwiaepiv268ea.png





lamtin 发表于 2013-10-26 21:17:58

看这里
https://github.com/EllisLab/CodeIgniter/blob/2.1.4/system/database/drivers/mysql/mysql_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

论坛还是有挺多热心的朋友,感谢朋友的回复,{:1_1:}

马云 发表于 2013-10-26 21:43:00

lamtin 发表于 2013-10-26 21:17 static/image/common/back.gif
看这里
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 static/image/common/back.gif
谢谢版主,我这样写,就是下面的代码,应该不用担心安全问题吧?
$this->db->insert('news', $data); 直 ...

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

lamtin 发表于 2013-10-28 16:32:01

马云 发表于 2013-10-26 21:43 static/image/common/back.gif
谢谢版主,我这样写,就是下面的代码,应该不用担心安全问题吧?
$this->db->insert('news', $data); 直 ...

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

dayrui 发表于 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过来的数据,这样的应该怎么写。
页: [1]
查看完整版本: CI 防注入方面,到底过滤特殊字符没有?