From c94dcdd6f895d549cde4730bed9ebc88c2b15987 Mon Sep 17 00:00:00 2001 From: AdrienClairembault Date: Tue, 17 Sep 2024 15:36:28 +0200 Subject: [PATCH] Better HTML encoding for Domain and Dropdown --- src/Domain.php | 7 ++--- src/Dropdown.php | 72 +++++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/Domain.php b/src/Domain.php index 264b7ca92f2..0c61be90584 100644 --- a/src/Domain.php +++ b/src/Domain.php @@ -845,10 +845,9 @@ public static function getAdditionalMenuLinks() { $links = []; if (static::canManageRecords()) { - $rooms = " - - " . DomainRecord::getTypeName(Session::getPluralNumber()) . " - "; + $label = htmlspecialchars(DomainRecord::getTypeName(Session::getPluralNumber())); + $rooms = " + $label"; $links[$rooms] = DomainRecord::getSearchURL(false); } if (count($links)) { diff --git a/src/Dropdown.php b/src/Dropdown.php index c8cf2b64bc0..b75705b1d28 100644 --- a/src/Dropdown.php +++ b/src/Dropdown.php @@ -611,36 +611,36 @@ public static function getDropdownName($table, $id, $withcomment = false, $trans if (!empty($data["phone"])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . Phone::getTypeName(1), - "" . $data['phone'] + "" . htmlspecialchars(Phone::getTypeName(1)), + "" . htmlspecialchars($data['phone']) ); } if (!empty($data["phone2"])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . __('Phone 2'), - "" . $data['phone2'] + "" . __s('Phone 2'), + "" . htmlspecialchars($data['phone2']) ); } if (!empty($data["mobile"])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . __('Mobile phone'), - "" . $data['mobile'] + "" . __s('Mobile phone'), + "" . htmlspecialchars($data['mobile']) ); } if (!empty($data["fax"])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . __('Fax'), - "" . $data['fax'] + "" . __s('Fax'), + "" . htmlspecialchars($data['fax']) ); } if (!empty($data["email"])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), "" . _n('Email', 'Emails', 1), - "" . $data['email'] + "" . htmlspecialchars($data['email']) ); } } @@ -651,22 +651,22 @@ public static function getDropdownName($table, $id, $withcomment = false, $trans if (!empty($data["phonenumber"])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . Phone::getTypeName(1), - "" . $data['phonenumber'] + "" . htmlspecialchars(Phone::getTypeName(1)), + "" . htmlspecialchars($data['phonenumber']) ); } if (!empty($data["fax"])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . __('Fax'), - "" . $data['fax'] + "" . __s('Fax'), + "" . htmlspecialchars($data['fax']) ); } if (!empty($data["email"])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . _n('Email', 'Emails', 1), - "" . $data['email'] + "" . _sn('Email', 'Emails', 1), + "" . htmlspecialchars($data['email']) ); } } @@ -690,7 +690,7 @@ public static function getDropdownName($table, $id, $withcomment = false, $trans if (!empty($data['locations_id'])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . Location::getTypeName(1) . "", + "" . htmlspecialchars(Location::getTypeName(1)) . "", self::getDropdownName( "glpi_locations", $data["locations_id"], @@ -702,7 +702,7 @@ public static function getDropdownName($table, $id, $withcomment = false, $trans if (!empty($data['budgettypes_id'])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . _n('Type', 'Types', 1) . "", + "" . _sn('Type', 'Types', 1) . "", self::getDropdownName( "glpi_budgettypes", $data["budgettypes_id"], @@ -714,14 +714,14 @@ public static function getDropdownName($table, $id, $withcomment = false, $trans if (!empty($data['begin_date'])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . __('Start date') . "", + "" . __s('Start date') . "", Html::convDateTime($data["begin_date"]) ); } if (!empty($data['end_date'])) { $comment .= "
" . sprintf( __('%1$s: %2$s'), - "" . __('End date') . "", + "" . __s('End date') . "", Html::convDateTime($data["end_date"]) ); } @@ -1359,6 +1359,8 @@ public static function showItemTypeMenu(string $title, array $optgroup, string $ echo "
"; echo "
"; + + $title = htmlspecialchars($title); echo ""; $selected = ''; @@ -2272,21 +2274,21 @@ public static function showFromArray($name, array $elements, $options = []) if ($param['readonly']) { $to_display = []; foreach ($param['values'] as $value) { - $output .= ""; + $output .= ""; if (isset($elements[$value])) { - $to_display[] = $elements[$value]; + $to_display[] = htmlspecialchars($elements[$value]); } } - $output .= '' . implode(', ', $to_display) . ''; + $output .= '' . implode(', ', $to_display) . ''; } else { if ($param['multiple']) { // Fix for multiple select not sending any form data when no option is selected - $output .= ""; + $output .= ""; } - $output .= ""; - echo (!$params['management_restrict'] ? __('Unit management') : __('Global management')); + htmlspecialchars($params['management_restrict']) . "'>"; + echo (!$params['management_restrict'] ? __s('Unit management') : __s('Global management')); } else { - echo (!$params['value'] ? __('Unit management') : __('Global management')); + echo (!$params['value'] ? __s('Unit management') : __s('Global management')); } } }