Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CI将CodeIgniter不允许的关键字符留空的风险有多大?_Php_Codeigniter - Fatal编程技术网

Php CI将CodeIgniter不允许的关键字符留空的风险有多大?

Php CI将CodeIgniter不允许的关键字符留空的风险有多大?,php,codeigniter,Php,Codeigniter,已经有一些关于不允许的关键字符的帖子,但这篇有不同的问题。我想知道如果我将$config['allowed\u uri\u chars']留空,风险有多大。会发生什么? 原因是什么?我需要启用\u查询\u字符串FALSE,并且我在 网址: 我从不依赖URL的值,我以前总是做一些清理。但我不确定Codeigniter如何处理路由以及它如何包含文件。他们是否依赖于此单一允许的字符规则?如果您只想包含阿拉伯字符,可以在预输入的字符regexp中包含unicode范围。使用我们可以尝试构造regexp:

已经有一些关于不允许的关键字符的帖子,但这篇有不同的问题。我想知道如果我将
$config['allowed\u uri\u chars']
留空,风险有多大。会发生什么? 原因是什么?我需要
启用\u查询\u字符串FALSE
,并且我在

网址:

我从不依赖URL的值,我以前总是做一些清理。但我不确定Codeigniter如何处理路由以及它如何包含文件。他们是否依赖于此单一允许的字符规则?

如果您只想包含阿拉伯字符,可以在预输入的字符regexp中包含unicode范围。使用我们可以尝试构造regexp:

a-z 0-9~%.:_\- \x0600-\x06FF
不幸的是,CodeIgniter没有在
preg\u match
中使用
u
修饰符(用于unicode)。因此,为了使其正常工作,您需要修改源代码文件行,并将其更改为:

if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|iu", $str))
在上面的代码中,我只将
u
修饰符添加到
preg\u match
。或者,您可以扩展中描述的
URI
类,这是一个更好的选择

(我没有测试这个)

为了回答为什么允许所有字符都是不好的问题:我只能想到SQL注入问题或错误

编辑:例如,如果您使用url
index.php/main/get_pdf?filename=awesome.pdf
/pdf/awesome.pdf
下载pdf文件,如果您不正确处理(即验证)您的输入,恶意用户可以执行以下操作:
index.php/main/get_pdf?filename=../secure_files/nuclear_launch_code.pdf

Edit2:好吧,上面的例子并不是坏用
allowed\u uri\u chars
的例子,因为AFAIK CodeIgniter允许这种url变量,所以你需要自己验证这些东西。我回家后会检查所有这些东西

Edit3:我修正了regexp,但似乎这不是启用阿拉伯语字符的方法,所以我划掉了答案的这一部分

我和CodeIgniter玩了一会儿。我不知道这些东西是否能在其他系统上工作。它适用于我的WindowsXP,PHP5.3。这就是我发现的:

  • 在PHP中,可以使用UTF-8字符作为函数和类标识符,但官方不支持(有关更多信息,请参阅)
  • 在CodeIgniter中,URL的
    控制器/方法
    部分是URL编码的(例如
    ‎‎转换为
    %D9%80%D8%AC%E2%80%8E
    )。如果您想在
    控制器
    方法
    名称中使用阿拉伯语,您有两个选项:

  • application/config/routes.php
    中添加url编码的路由,指向可能包含阿拉伯语字符的真实路由(如上所述,您可以在php标识符中使用UTF-8字符)。例如:
    $route['welcome/%D8%A3']='welcome/أ'
    将允许用户进入
    example.com/index.php/welcome/أ
    ,它将在
    欢迎
    控制器中调用
    أ
    方法(定义为
    函数{…}
    )。当然,您可以将阿拉伯语url编码的url映射到普通ASCII名称
  • system/core/Router.php
    类,以便
    fetch\u方法
    fetch\u类
    返回url解码名称。我不知道你这样做的时候会有什么安全隐患。可能最好验证输入字符是否确实是阿拉伯语(即,您可以检查提供的字符范围)。修改的
    获取类的示例:

    function fetch_class()
    {
        return urldecode($this->class);
    }
    
  • 如果您需要在控制器方法的参数中使用阿拉伯语字符,您只需要
    urldecode
    这些参数。例如:

    class Welcome extends CI_Controller
    {
        public function index($param)
        {
            $this->output->set_content_type("text/plain; charset=utf-8");
            echo urldecode($param);
        }
    }
    
  • 如果您需要在查询字符串中使用这些字符,它就可以正常工作。例如

    class Welcome extends CI_Controller
    {
        public function index()
        {
            $this->output->set_content_type("text/plain; charset=utf-8");
            echo $this->input->get('arabic');
        }
    }
    
    前往<代码>示例com.com/index.com/index.php/com/index.php/欢迎/欢迎/index.com.com/index.php/欢迎/index.com/index.php/欢迎/欢迎/www.com.com.com/index.php/欢迎/index.com.php/欢迎/index.com.php/前往前往前往前往<代码>例准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准准طعغكلمنهوي

Edit4:如果您有
$config['uri\u protocol']='PATH\u INFO'
,那么:

  • 在配置集
    $config['allowed_uri_chars']='a-z 0-9~%:\-\x{0600}-\x{06FF}
  • system/core/URI.php
    中扩展
    URI
    类,以便在方法
    \u filter\u URI
    中使用
    preg\u match
    行:

    if ( ! preg_match("|^[".str_replace(array('\\-', '\-', '\{', '\}', '\\\\x'), array('-', '-', '{', '}', '\x'), preg_quote($this->config->item('permitted_uri_chars')))."]+$|ui", $str))
    

  • 谢谢,但还是不行。我收到php警告:“Message:preg_match()[function.preg match]:编译失败:偏移量为32的字符类中的范围无序”。@user1324762我将在evening@user1324762我重读了你的问题,我很困惑。您想使用阿拉伯文字符作为控制器名还是方法名?我已经设法通过
    $\u GET
    (例如
    www.example.com/index.php/welcome/index?arabic=阿拉伯文/阿拉伯文/阿拉伯文/阿拉伯文/阿拉伯文/阿拉伯文/阿拉伯文。你在通过
    $\u GET
    发送时有问题吗?或者你想在控制器/方法名称中使用阿拉伯语?PS我已经成功地在控制器/方法名称中使用阿拉伯语字符,而没有更改
    允许的uri\u字符
    ,几乎没有黑客攻击。让我知道这是否是你想要的,我会编辑我的答案。编辑:您使用的是哪个PHP版本?@user1324762。我设法让它在路径信息上运行。看起来regexp是有效的。1.Set
    $config['allowed_uri_chars']='a-z 0-9~%:\-\x{0600}-\x{06FF}。2.同样,我们需要在
    \u filter\u URI
    方法中使用
    system/core/URI.php
    中的
    preg\u match
    更改行。尝试将此代码放在那里:
    如果(!preg\u match(“^[”.str\u replace(数组(“\-”、“\-”、“\{”、“\\}”、“x”)、数组(“-”、“-”、“{”、“}、“\x”)、pregconfig->item('allowed\u uri chars')))。“]+$\ui”、$str。
    
    if ( ! preg_match("|^[".str_replace(array('\\-', '\-', '\{', '\}', '\\\\x'), array('-', '-', '{', '}', '\x'), preg_quote($this->config->item('permitted_uri_chars')))."]+$|ui", $str))