From 9c1391fcb760270d87ad17425ac5887e734ef81e Mon Sep 17 00:00:00 2001 From: Ignacio Nelson Date: Mon, 3 Apr 2023 15:19:56 -0300 Subject: [PATCH] Sanitize svg files uploaded in settings pages --- includes/functions.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 87a550b9..7c55958a 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1635,14 +1635,14 @@ function generate_safe_filename($filename) /** * Simple file upload. Used on normal file fields, eg: logo on branding page */ -function option_file_upload($file, $validate_ext = '', $option = '', $action = '') +function option_file_upload($file, $validate_type = '', $option = '', $action = '') { global $dbh; $continue = true; /** Validate file extensions */ - if (!empty($validate_ext)) { - switch ($validate_ext) { + if (!empty($validate_type)) { + switch ($validate_type) { case 'image': $validate_types = "/^\.(jpg|jpeg|gif|png|svg){1}$/i"; break; @@ -1659,6 +1659,10 @@ function option_file_upload($file, $validate_ext = '', $option = '', $action = ' if (!empty($validate_types) && !preg_match($validate_types, strrchr($safe_filename, '.'))) { $continue = false; } + + if (file_is_svg($file['tmp_name'])) { + file_put_contents($file['tmp_name'], sanitize_svg($file['tmp_name'])); + } if ($continue) { /**