CodeIgniter-Chinese / CodeIgniter

开源 PHP 框架 CodeIgniter 中国社区分支
http://codeigniter.org.cn/
MIT License
65 stars 26 forks source link

关于input类的“不可见字符”被屏蔽的问题 #18

Closed kkksc03 closed 10 years ago

kkksc03 commented 10 years ago

这边在“不可见字符”加上了引号。 在post一个数据时,内容包括"%10",这是3个字符组成的字符串而不是一个不可见字符,是在文本框中输入的。但是ci的input类会把"%10"这3个字符也给屏蔽了。 ci的上下文如下:

        if ($url_encoded)
        {
            $non_displayables[] = '/%0[0-8bcef]/';  // url encoded 00-08, 11, 12, 14, 15
            $non_displayables[] = '/%1[0-9a-f]/';   // url encoded 16-31
        }
        $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S';   // 00-08, 11, 12, 14-31, 127
        do
        {
            $str = preg_replace($non_displayables, '', $str, -1, $count);
        }
        while ($count);

其中,我认为/%0[0-8bcef]/这个正则有点问题,因为%不是正则表达式的元字符,他会把%10这样的给屏蔽掉。

kkksc03 commented 10 years ago

其实问题不是出自这里,应该是这里

        // Clean $_POST Data
        if (is_array($_POST) AND count($_POST) > 0)
        {
            foreach ($_POST as $key => $val)
            {
                $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);//fuck
            }
        }
    function _clean_input_data($str)
    {
                //省略
        // Remove control characters
        $str = remove_invisible_characters($str);

        // Should we filter the input data?
        if ($this->_enable_xss === TRUE)
        {
            $str = $this->security->xss_clean($str);
        }

        // Standardize newlines if needed
        if ($this->_standardize_newlines == TRUE)
        {
            if (strpos($str, "\r") !== FALSE)
            {
                $str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
            }
        }
        return $str;
    }

上面的函数原型是function remove_invisible_characters($str, $url_encoded = TRUE) 由于没有第2项取了默认值TRUE,所以。。。

hex-ci commented 10 years ago

这是已知问题,目前已经修复。