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/winter
Language: PHP
Files changed: modules/backend/traits/UploadableWidget.php
Commit date: 2023-07-07 11:54:38 -0600
Commit message: Add support for uploading SVGs

Diff: diff --git a/modules/backend/traits/UploadableWidget.php b/modules/backend/traits/UploadableWidget.php
index dd1e12a58..1f6c28eda 100644
--- a/modules/backend/traits/UploadableWidget.php
+++ b/modules/backend/traits/UploadableWidget.php
@@ -1,19 +1,18 @@
 <?php namespace Backend\Traits;
 
-use Str;
+use ApplicationException;
+use Event;
 use File;
+use Illuminate\Filesystem\FilesystemAdapter;
 use Lang;
-use Event;
-use Config;
-use Storage;
 use Request;
 use Response;
-use ApplicationException;
+use Str;
 use System\Classes\MediaLibrary;
-use Illuminate\Filesystem\FilesystemAdapter;
 use Winter\Storm\Filesystem\Definitions as FileDefinitions;
+use Winter\Storm\Support\Svg;
 
 /**
  * Uploadable Widget Trait
  * Adds media library upload features to back-end widgets
  *
@@ -122,10 +121,15 @@ protected function onUploadDirect(): \Illuminate\Http\Response
                 ? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName()
                 : $uploadedFile->getRealPath();
 
             $filePath = $this->uploadableGetUploadPath($fileName);
 
+            // Filter SVG files
+            if (pathinfo($filePath, PATHINFO_EXTENSION) === 'svg') {
+                file_put_contents($sourcePath, Svg::extract($sourcePath));
+            }
+
             $this->uploadableGetDisk()->put($filePath, File::get($sourcePath));
 
             /**
              * @event media.file.upload
              * Called after a file is uploaded

Vulnerable code: use Str;
use Event;
use Config;
use Storage;
use ApplicationException;
use Illuminate\Filesystem\FilesystemAdapter;
Fixed code: use ApplicationException;
use Event;
use Illuminate\Filesystem\FilesystemAdapter;
use Str;
use Winter\Storm\Support\Svg;
            // Filter SVG files
            if (pathinfo($filePath, PATHINFO_EXTENSION) === 'svg') {
                file_put_contents($sourcePath, Svg::extract($sourcePath));
            }