CVE-2022-47945 (published 2022-12-23T21:15Z)

ThinkPHP Framework before 6.0.14 allows local file inclusion via the lang parameter when the language pack feature is enabled (lang_switch_on=true). An unauthenticated and remote attacker can exploit this to execute arbitrary operating system commands, as demonstrated by including pearcmd.php.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-22
cwe_name: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
description: The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
extended_description: 
            Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin" to access unexpected files. This is referred to as absolute path traversal.
         
         

Fix information:
repo_url: https://github.com/top-think/framework
commit_details: repo_url: https://github.com/top-think/framework
author: thinkphp
author_date: 2022-09-14 13:33:59+08:00
msg: 删除废弃方法 优化多语言检测
repository: repo_url: https://github.com/top-think/framework
repo_name: top-think/framework
description: ThinkPHP Framework
repo_language: PHP
owner: top-think
file_changes: filename: Lang.php
change_type: ModificationType.MODIFY
diff: @@ -287,58 +287,4 @@ class Lang
         return $value;
     }
 
-    /**
-     * 自动侦测设置获取语言选择
-     * @deprecated
-     * @access public
-     * @param Request $request
-     * @return string
-     */
-    public function detect(Request $request): string
-    {
-        // 自动侦测设置获取语言选择
-        $langSet = '';
-
-        if ($request->get($this->config['detect_var'])) {
-            // url中设置了语言变量
-            $langSet = strtolower($request->get($this->config['detect_var']));
-        } elseif ($request->header($this->config['header_var'])) {
-            // Header中设置了语言变量
-            $langSet = strtolower($request->header($this->config['header_var']));
-        } elseif ($request->cookie($this->config['cookie_var'])) {
-            // Cookie中设置了语言变量
-            $langSet = strtolower($request->cookie($this->config['cookie_var']));
-        } elseif ($request->server('HTTP_ACCEPT_LANGUAGE')) {
-            // 自动侦测浏览器语言
-            $match = preg_match('/^([a-z\d\-]+)/i', $request->server('HTTP_ACCEPT_LANGUAGE'), $matches);
-            if ($match) {
-                $langSet = strtolower($matches[1]);
-                if (isset($this->config['accept_language'][$langSet])) {
-                    $langSet = $this->config['accept_language'][$langSet];
-                }
-            }
-        }
-
-        if (empty($this->config['allow_lang_list']) || in_array($langSet, $this->config['allow_lang_list'])) {
-            // 合法的语言
-            $this->range = $langSet;
-        }
-
-        return $this->range;
-    }
-
-    /**
-     * 保存当前语言到Cookie
-     * @deprecated
-     * @access public
-     * @param Cookie $cookie Cookie对象
-     * @return void
-     */
-    public function saveToCookie(Cookie $cookie)
-    {
-        if ($this->config['use_cookie']) {
-            $cookie->set($this->config['cookie_var'], $this->range);
-        }
-    }
-
 }

programming_language: PHP
filename: LoadLangPack.php
change_type: ModificationType.MODIFY
diff: @@ -70,33 +70,33 @@ class LoadLangPack
 
         if ($request->get($this->config['detect_var'])) {
             // url中设置了语言变量
-            $langSet = strtolower($request->get($this->config['detect_var']));
+            $langSet = $request->get($this->config['detect_var']);
         } elseif ($request->header($this->config['header_var'])) {
             // Header中设置了语言变量
-            $langSet = strtolower($request->header($this->config['header_var']));
+            $langSet = $request->header($this->config['header_var']);
         } elseif ($request->cookie($this->config['cookie_var'])) {
             // Cookie中设置了语言变量
-            $langSet = strtolower($request->cookie($this->config['cookie_var']));
+            $langSet = $request->cookie($this->config['cookie_var']);
         } elseif ($request->server('HTTP_ACCEPT_LANGUAGE')) {
             // 自动侦测浏览器语言
-            $match = preg_match('/^([a-z\d\-]+)/i', $request->server('HTTP_ACCEPT_LANGUAGE'), $matches);
-            if ($match) {
-                $langSet = strtolower($matches[1]);
-                if (isset($this->config['accept_language'][$langSet])) {
-                    $langSet = $this->config['accept_language'][$langSet];
-                }
+            $langSet = $request->server('HTTP_ACCEPT_LANGUAGE');
+        }
+
+        if (preg_match('/^([a-z\d\-]+)/i', $langSet, $matches)) {
+            $langSet = strtolower($matches[1]);
+            if (isset($this->config['accept_language'][$langSet])) {
+                $langSet = $this->config['accept_language'][$langSet];
             }
         }
 
         if (empty($this->config['allow_lang_list']) || in_array($langSet, $this->config['allow_lang_list'])) {
             // 合法的语言
-            $range = $langSet;
-            $this->lang->setLangSet($range);
+            $this->lang->setLangSet($langSet);
         } else {
-            $range = $this->lang->getLangSet();
+            $langSet = $this->lang->getLangSet();
         }
 
-        return $range;
+        return $langSet;
     }
 
     /**

programming_language: PHP