您所在的位置:首页 / 知识分享

修复Thinkphp版本低于5.0.24的高危漏洞解决方法

2023.03.16

23

ytj

打开:thinkphp\library\think\Request.php文件,搜索 method 方法,原来的函数方法是这样的如下:

public function method($method = false)
{
    if (true === $method) {
        // 获取原始请求类型
        return $this->server('REQUEST_METHOD') ?: 'GET';
    } elseif (!$this->method) {
        if (isset($_POST[Config::get('var_method')])) {
            $this->method = strtoupper($_POST[Config::get('var_method')]);
            $this->{$this->method}($_POST);
        } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
            $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
        } else {
            $this->method = $this->server('REQUEST_METHOD') ?: 'GET';
        }
    }
    return $this->method;
}
改成下面:

public function method($method = false)
{
    if (true === $method) {
        // 获取原始请求类型
        return $this->server('REQUEST_METHOD') ?: 'GET';
    } elseif (!$this->method) {
        if (isset($_POST[Config::get('var_method')])) {
            $method = strtoupper($_POST[Config::get('var_method')]);
            if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) {
                $this->method = $method;
                $this->{$this->method}($_POST);
            } else {
                $this->method = 'POST';
            }
            unset($_POST[Config::get('var_method')]);
        } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
            $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
        } else {
            $this->method = $this->server('REQUEST_METHOD') ?: 'GET';
        }
    }
    return $this->method;
}
然后,打开:thinkphp\library\think\App.php文件,搜索 model方法,原来的函数方法是这样的如下: 
        // 获取控制器名
 374      $controller = strip_tags($result[1] ?: $config['default_controller']);
 375       $controller = $convert ? strtolower($controller) : $controller;

加上:
 //修复漏洞
        if ($controller && !preg_match('/^[A-Za-z][\w|\.]*$/', $controller)) {
            throw new HttpException(404, 'controller not exists:' . $controller);
        }


就OK啦!


相关新闻

为什么甲方不喜欢极简主义?

2019.12.28

1114

关于极简主义的思考

用3个章节,聊聊SaaS用户体验设计实践与价值

2023.03.07

23

今天和大家聊聊我对「SaaS」和「SaaS 用户体验」价值思考及设计实践总结分享,本文从如下三个方面展开: 如何理解 SaaS 和传统软件的差别 重新认识 B 端用户体验的价值 SaaS 用户体验设计体系实践思考。

商户+共享停车

2016.07.12

5841

随着城市发展,停车难已成为广大车主无法避免的痛点,这也进一步影响到车位资源紧缺商户的生意--因难停车而导致顾客流失或到访频次减少。