Skip to content

Commit

Permalink
Run media library files through Svg sanitizer when renaming to SVG ex…
Browse files Browse the repository at this point in the history
…tension
  • Loading branch information
LukeTowers committed Nov 29, 2023
1 parent b4041b5 commit 8445b84
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions modules/system/classes/MediaLibrary.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?php namespace System\Classes;
<?php

use Str;
use Lang;
namespace System\Classes;

use ApplicationException;
use Cache;
use Config;
use Illuminate\Filesystem\FilesystemAdapter;
use Lang;
use Storage;
use Request;
use SystemException;
use Url;
use Winter\Storm\Filesystem\Definitions as FileDefinitions;
use Illuminate\Filesystem\FilesystemAdapter;
use ApplicationException;
use SystemException;
use Winter\Storm\Support\Str;
use Winter\Storm\Support\Svg;

/**
* Provides abstraction level for the Media Library operations.
Expand Down Expand Up @@ -346,6 +348,15 @@ public function moveFile($oldPath, $newPath, $isRename = false)
$newPath = self::validatePath($newPath);
$fullNewPath = $this->getMediaPath($newPath);

// If the file extension is changed to SVG, ensure that it has been sanitized
$oldExt = pathinfo($oldPath, PATHINFO_EXTENSION);
$newExt = pathinfo($newPath, PATHINFO_EXTENSION);
if ($oldExt !== $newExt && $newExt === 'svg') {
$contents = $this->getStorageDisk()->get($fullOldPath);
$contents = Svg::sanitize($contents);
$this->getStorageDisk()->put($fullOldPath, $contents);
}

return $this->getStorageDisk()->move($fullOldPath, $fullNewPath);
}

Expand Down

0 comments on commit 8445b84

Please sign in to comment.