CVE-2023-37269: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
value: Winter is a free, open-source content management system (CMS) based on the Laravel PHP framework. Users with the `backend.manage_branding` permission can upload SVGs as the application logo. Prior to version 1.2.3, SVG uploads were not sanitized, which could have allowed a stored cross-site scripting (XSS) attack. To exploit the vulnerability, an attacker would already need to have developer or super user level permissions in Winter CMS. This means they would already have extensive access and control within the system. Additionally, to execute the XSS, the attacker would need to convince the victim to directly visit the URL of the maliciously uploaded SVG, and the application would have to be using local storage where uploaded files are served under the same domain as the application itself instead of a CDN. This is because all SVGs in Winter CMS are rendered through an `img` tag, which prevents any payloads from being executed directly. These two factors significantly limit the potential harm of this vulnerability. This issue has been patched in v1.2.3 through the inclusion of full support for SVG uploads and automatic sanitization of uploaded SVG files. As a workaround, one may apply the patches manually.
CWE description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
CVSS v3 base score: 4.8
Published: 2023-07-07T22:15Z
Repository: https://github.com/wintercms/storm
Language: PHP
Files changed: src/Database/Attach/File.php, src/Filesystem/Definitions.php
Commit date: 2023-07-07 11:52:24 -0600
Commit message: Add support for uploading SVGs

Diff: diff --git a/src/Database/Attach/File.php b/src/Database/Attach/File.php
index 67c4f39c..d47b949a 100644
--- a/src/Database/Attach/File.php
+++ b/src/Database/Attach/File.php
@@ -9,10 +9,11 @@
 use Symfony\Component\HttpFoundation\File\UploadedFile;
 use Winter\Storm\Database\Model;
 use Winter\Storm\Exception\ApplicationException;
 use Winter\Storm\Network\Http;
 use Winter\Storm\Support\Facades\File as FileHelper;
+use Winter\Storm\Support\Svg;
 
 /**
  * File attachment model
  *
  * @author Alexey Bobkov, Samuel Georges
@@ -832,35 +833,44 @@ protected function putFile($sourcePath, $destinationFileName = null)
     {
         if (!$destinationFileName) {
             $destinationFileName = $this->disk_name;
         }
 
-        $destinationPath = $this->getStorageDirectory() . $this->getPartitionDirectory();
+        $destinationFolder = $this->getStorageDirectory() . $this->getPartitionDirectory();
+        $destinationPath = $destinationFolder . $destinationFileName;
+
+        // Filter SVG files
+        if (pathinfo($destinationPath, PATHINFO_EXTENSION) === 'svg') {
+            file_put_contents($sourcePath, Svg::extract($sourcePath));
+        }
+
+        pathinfo($destinationPath, PATHINFO_EXTENSION);
 
         if (!$this->isLocalStorage()) {
-            return $this->copyLocalToStorage($sourcePath, $destinationPath . $destinationFileName);
+            return $this->copyLocalToStorage($sourcePath, $destinationPath);
         }
 
         /*
          * Using local storage, tack on the root path and work locally
          * this will ensure the correct permissions are used.
          */
-        $destinationPath = $this->getLocalRootPath() . '/' . $destinationPath;
+        $destinationFolder = $this->getLocalRootPath() . '/' . $destinationFolder;
+        $destinationPath = $destinationFolder . $destinationFileName;
 
         /*
          * Verify the directory exists, if not try to create it. If creation fails
          * because the directory was created by a concurrent process then proceed,
          * otherwise trigger the error.
          */
         if (
-            !FileHelper::isDirectory($destinationPath) &&
-            !FileHelper::makeDirectory($destinationPath, 0777, true, true)
+            !FileHelper::isDirectory($destinationFolder) &&
+            !FileHelper::makeDirectory($destinationFolder, 0777, true, true)
         ) {
             trigger_error(error_get_last()['message'], E_USER_WARNING);
         }
 
-        return FileHelper::copy($sourcePath, $destinationPath . $destinationFileName);
+        return FileHelper::copy($sourcePath, $destinationPath);
     }
 
     /**
      * Delete file contents from storage device.
      *
diff --git a/src/Filesystem/Definitions.php b/src/Filesystem/Definitions.php
index 934bb7f7..6cc39add 100644
--- a/src/Filesystem/Definitions.php
+++ b/src/Filesystem/Definitions.php
@@ -111,10 +111,11 @@ protected function defaultExtensions(): array
             'jpeg',
             'bmp',
             'png',
             'webp',
             'gif',
+            'svg',
             'js',
             'map',
             'ico',
             'css',
             'less',
@@ -145,11 +146,11 @@ protected function defaultExtensions(): array
             'mp4',
             'mpeg',
             'webm',
             'mkv',
             'rar',
-            'zip'
+            'zip',
         ];
     }
 
     /**
      * Extensions seen as public assets.
@@ -165,10 +166,11 @@ protected function assetExtensions(): array
             'jpeg',
             'bmp',
             'png',
             'webp',
             'gif',
+            'svg',
             'ico',
             'css',
             'js',
             'woff',
             'woff2',
@@ -176,11 +178,11 @@ protected function assetExtensions(): array
             'eot',
             'json',
             'md',
             'less',
             'sass',
-            'scss'
+            'scss',
         ];
     }
 
     /**
      * Extensions typically used as images.
@@ -195,11 +197,12 @@ protected function imageExtensions(): array
             'jpg',
             'jpeg',
             'bmp',
             'png',
             'webp',
-            'gif'
+            'gif',
+            'svg',
         ];
     }
 
     /**
      * Extensions typically used as video files.
@@ -215,11 +218,11 @@ protected function videoExtensions(): array
             'avi',
             'mov',
             'mpg',
             'mpeg',
             'mkv',
-            'webm'
+            'webm',
         ];
     }
 
     /**
      * Extensions typically used as audio files.
@@ -233,9 +236,9 @@ protected function audioExtensions(): array
         return [
             'mp3',
             'wav',
             'wma',
             'm4a',
-            'ogg'
+            'ogg',
         ];
     }
 }

Vulnerable code:         $destinationPath = $this->getStorageDirectory() . $this->getPartitionDirectory();
            return $this->copyLocalToStorage($sourcePath, $destinationPath . $destinationFileName);
        $destinationPath = $this->getLocalRootPath() . '/' . $destinationPath;
            !FileHelper::isDirectory($destinationPath) &&
            !FileHelper::makeDirectory($destinationPath, 0777, true, true)
        return FileHelper::copy($sourcePath, $destinationPath . $destinationFileName);
            'zip'
            'scss'
            'gif'
            'webm'
            'ogg'
Fixed code: use Winter\Storm\Support\Svg;
        $destinationFolder = $this->getStorageDirectory() . $this->getPartitionDirectory();
        $destinationPath = $destinationFolder . $destinationFileName;

        // Filter SVG files
        if (pathinfo($destinationPath, PATHINFO_EXTENSION) === 'svg') {
            file_put_contents($sourcePath, Svg::extract($sourcePath));
        }

        pathinfo($destinationPath, PATHINFO_EXTENSION);
            return $this->copyLocalToStorage($sourcePath, $destinationPath);
        $destinationFolder = $this->getLocalRootPath() . '/' . $destinationFolder;
        $destinationPath = $destinationFolder . $destinationFileName;
            !FileHelper::isDirectory($destinationFolder) &&
            !FileHelper::makeDirectory($destinationFolder, 0777, true, true)
        return FileHelper::copy($sourcePath, $destinationPath);
            'svg',
            'zip',
            'svg',
            'scss',
            'gif',
            'svg',
            'webm',
            'ogg',