Skip to content

Commit 6dc5cb6

Browse files
orthaghtrasher
authored andcommitted
remove xss on dbutil::formatUserName
1 parent d45ae18 commit 6dc5cb6

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

inc/dbutils.class.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ public function getPreviousItem($table, $ID, $condition = "", $nextprev_item = "
15421542
*
15431543
* @return string formatted username
15441544
*/
1545-
public function formatUserName($ID, $login, $realname, $firstname, $link = 0, $cut = 0, $force_config = false) {
1545+
public function formatUserName($ID, $login, $realname, $firstname, $link = 1, $cut = 0, $force_config = false) {
15461546
global $CFG_GLPI;
15471547

15481548
$before = "";
@@ -1559,37 +1559,38 @@ public function formatUserName($ID, $login, $realname, $firstname, $link = 0, $c
15591559
}
15601560

15611561
if (strlen($realname) > 0) {
1562-
$temp = $realname;
1562+
$formatted = $realname;
15631563

15641564
if (strlen($firstname) > 0) {
15651565
if ($order == User::FIRSTNAME_BEFORE) {
1566-
$temp = $firstname." ".$temp;
1566+
$formatted = $firstname." ".$formatted;
15671567
} else {
1568-
$temp .= " ".$firstname;
1568+
$formatted .= " ".$firstname;
15691569
}
15701570
}
15711571

15721572
if (($cut > 0)
1573-
&& (Toolbox::strlen($temp) > $cut)) {
1574-
$temp = Toolbox::substr($temp, 0, $cut)." ...";
1573+
&& (Toolbox::strlen($formatted) > $cut)) {
1574+
$formatted = Toolbox::substr($formatted, 0, $cut)." ...";
15751575
}
15761576

15771577
} else {
1578-
$temp = $login;
1578+
$formatted = $login;
15791579
}
15801580

15811581
if ($ID > 0
1582-
&& ((strlen($temp) == 0) || $id_visible)) {
1583-
$temp = sprintf(__('%1$s (%2$s)'), $temp, $ID);
1582+
&& ((strlen($formatted) == 0) || $id_visible)) {
1583+
$formatted = sprintf(__('%1$s (%2$s)'), $formatted, $ID);
15841584
}
15851585

15861586
if (($link == 1)
15871587
&& ($ID > 0)) {
1588-
$before = "<a title=\"".$temp."\" href='".User::getFormURLWithID($ID)."'>";
1588+
$before = "<a title=\"".Toolbox::addslashes_deep($formatted)."\"
1589+
href='".User::getFormURLWithID($ID)."'>";
15891590
$after = "</a>";
15901591
}
15911592

1592-
$username = $before.$temp.$after;
1593+
$username = $before.$formatted.$after;
15931594
return $username;
15941595
}
15951596

0 commit comments

Comments
 (0)