CVE-2022-39296 (published 2022-10-11T18:15Z)

MelisAssetManager provides deliveries of Melis Platform's assets located in every module's public folder. Attackers can read arbitrary files on affected versions of `melisplatform/melis-asset-manager`, leading to the disclosure of sensitive information. Conducting this attack does not require authentication. Users should immediately upgrade to `melisplatform/melis-asset-manager` >= 5.0.1. This issue was addressed by restricting access to files to intended directories only.

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

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/melisplatform/melis-asset-manager
commit_details: repo_url: https://github.com/melisplatform/melis-asset-manager
author: Maria Teresa Pomar
author_date: 2022-09-26 16:49:23+08:00
msg: added checking if the requested file is inside the intended directory
repository: repo_url: https://github.com/melisplatform/melis-asset-manager
repo_name: melisplatform/melis-asset-manager
description: MelisAssetManager provides deliveries of Melis Platform's assets located in every module's public folder.
repo_language: PHP
owner: melisplatform
file_changes: filename: Module.php
change_type: ModificationType.MODIFY
diff: @@ -148,7 +148,7 @@ class Module
         
         // First check if asset in main public folder
         $pathFile = $_SERVER['DOCUMENT_ROOT'] . $UriWithoutParams;
-        if (is_file($pathFile))
+        if (is_file($pathFile) && $this->checkFileInFolder($pathFile, $_SERVER['DOCUMENT_ROOT']))
             $this->sendDocument($pathFile, $UriParams);
         else
         {
@@ -181,7 +181,7 @@ class Module
     
                         if ($pathFile != '')
                         {
-                            if (is_file($pathFile))
+                            if (is_file($pathFile) && $this->checkFileInFolder($pathFile, $path . '/public/'))
                                 $this->sendDocument($pathFile, $UriParams);
                         }
                     }
@@ -263,4 +263,18 @@ class Module
         ];
     }
 
+     /*checks if the file is inside the given folder*/
+    protected function checkFileInFolder($file, $folder)
+    {       
+        $path = realpath($file);        
+        if ($path !== false) {
+            if (strpos($path, realpath($folder)) !== 0) {                   
+                throw new \Exception('Requested resource is outside of ' . $folder);
+            } else {              
+                return true;
+            }
+        } else {                   
+            return false;
+        }
+    }
 }

programming_language: PHP