diff --git a/lhc_web/lib/core/lhcore/lhfileupload.php b/lhc_web/lib/core/lhcore/lhfileupload.php index a837454b22..92980d6f5c 100644 --- a/lhc_web/lib/core/lhcore/lhfileupload.php +++ b/lhc_web/lib/core/lhcore/lhfileupload.php @@ -71,10 +71,15 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro $matches = array(); if (strpos($name, '.') === false && preg_match('/^image\/(gif|jpe?g|png)/', $fileUpload->type, $matches)) { - $fileUpload->extension = $matches[1]; + $fileUpload->extension = strtolower($matches[1]); } else { $partsFile = explode('.', $fileUpload->upload_name); - $fileUpload->extension = end($partsFile); + $fileUpload->extension = strtolower(end($partsFile)); + } + + if ($fileUpload->extension == 'svg') { + erLhcoreClassFileUploadAdmin::cleanSVG($fileUpload->file_path_server); + $file->size = $fileUpload->size = filesize($fileUpload->file_path_server); } if (isset($this->options['remove_meta']) && $this->options['remove_meta'] == true && in_array($fileUpload->extension, array('jpg', 'jpeg', 'png', 'gif'))) { diff --git a/lhc_web/lib/core/lhcore/lhfileuploadadmin.php b/lhc_web/lib/core/lhcore/lhfileuploadadmin.php index 528c2d2613..71ca17fb2b 100644 --- a/lhc_web/lib/core/lhcore/lhfileuploadadmin.php +++ b/lhc_web/lib/core/lhcore/lhfileuploadadmin.php @@ -73,11 +73,16 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro $fileUpload->extension = strtolower(end($partsFile)); } + if ($fileUpload->extension == 'svg') { + self::cleanSVG($fileUpload->file_path_server); + $file->size = $fileUpload->size = filesize($fileUpload->file_path_server); + } + if (isset($this->options['remove_meta']) && $this->options['remove_meta'] == true && in_array($fileUpload->extension, array('jpg', 'jpeg', 'png', 'gif'))) { self::removeExif($fileUpload->file_path_server, $fileUpload->file_path_server . '_exif'); unlink($fileUpload->file_path_server); rename($fileUpload->file_path_server . '_exif', $fileUpload->file_path_server); - $fileUpload->size = filesize($fileUpload->file_path_server); + $file->size = $fileUpload->size = filesize($fileUpload->file_path_server); } $fileUpload->saveThis(); @@ -89,6 +94,16 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro return $file; } + + public static function cleanSVG($path) + { + $sanitizer = new \enshrined\svgSanitize\Sanitizer(); + $dirtySVG = file_get_contents($path); + $cleanSVG = $sanitizer->sanitize($dirtySVG); + file_put_contents($path.'_svg', $cleanSVG); + unlink($path); + rename($path.'_svg', $path); + } } ?> \ No newline at end of file