Skip to content

Commit

Permalink
Sanitize svg files uploaded in settings pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacionelson committed Apr 3, 2023
1 parent 2adc95d commit 9c1391f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions includes/functions.php
Expand Up @@ -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;
Expand All @@ -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) {
/**
Expand Down

0 comments on commit 9c1391f

Please sign in to comment.