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

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

2023.03.16

608

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啦!


相关新闻

PHP+WebUploader简单实现分块上传

2020.12.29

1512

随着互联网的迅猛发展和广泛应用,越来越多的用户在操作图片上传、文件上传时会选择大文件。按以前将一个文件整体FORM上传到服务端,已不在适用。

Go time.Parse() 和time.Format()

2020.12.09

1233

在windows下,time.Parse()的时区和time.Format()的时区是一致的。