Skip to content

Commit 5902e62

Browse files
author
Marius Burkard
committed
- Added internal htmlentities function with array support and ENT_QUOTES.
- Fixed #4893 Stored XSS issue in email name field
1 parent b0f89e5 commit 5902e62

File tree

5 files changed

+43
-17
lines changed

5 files changed

+43
-17
lines changed

interface/lib/classes/functions.inc.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,25 @@ public function generate_ssh_key($client_id, $username = ''){
454454
$app->log("Failed to create SSH keypair for ".$username, LOGLEVEL_WARN);
455455
}
456456
}
457+
458+
public function htmlentities($value) {
459+
global $conf;
460+
461+
if(is_array($value)) {
462+
$out = array();
463+
foreach($values as $key => $val) {
464+
if(is_array($val)) {
465+
$out[$key] = $this->htmlentities($val);
466+
} else {
467+
$out[$key] = htmlentities($val, ENT_QUOTES, $conf["html_content_encoding"]);
468+
}
469+
}
470+
} else {
471+
$out = htmlentities($value, ENT_QUOTES, $conf["html_content_encoding"]);
472+
}
473+
474+
return $out;
475+
}
457476
}
458477

459478
?>

interface/lib/classes/listform.inc.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public function getSearchSQL($sql_where = '')
179179
&& $k == $_SESSION['search'][$list_name][$search_prefix.$field]
180180
&& $_SESSION['search'][$list_name][$search_prefix.$field] != '')
181181
? ' SELECTED' : '';
182+
$v = $app->functions->htmlentities($v);
182183
$out .= "<option value='$k'$selected>$v</option>\r\n";
183184
}
184185
}
@@ -610,17 +611,8 @@ function lng($msg) {
610611
}
611612

612613
function escapeArrayValues($search_values) {
613-
global $conf;
614-
615-
$out = array();
616-
if(is_array($search_values)) {
617-
foreach($search_values as $key => $val) {
618-
$out[$key] = htmlentities($val, ENT_QUOTES, $conf["html_content_encoding"]);
619-
}
620-
}
621-
622-
return $out;
623-
614+
global $app;
615+
return $app->functions->htmlentities($search_values);
624616
}
625617

626618
}

interface/lib/classes/quota_lib.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ public function get_mailquota_data($clientid = null, $readable = true) {
243243
if(is_array($emails) && !empty($emails)){
244244
for($i=0;$i<sizeof($emails);$i++){
245245
$email = $emails[$i]['email'];
246-
246+
247+
$emails[$i]['name'] = $app->functions->htmlentities($emails[$i]['name']);
247248
$emails[$i]['used'] = isset($monitor_data[$email]['used']) ? $monitor_data[$email]['used'] : array(1 => 0);
248249

249250
if (!is_numeric($emails[$i]['used'])) $emails[$i]['used']=$emails[$i]['used'][1];

interface/lib/classes/tform_base.inc.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ function getHTML($record, $tab, $action = 'NEW') {
475475
$selected = ($k == $val)?' SELECTED':'';
476476
if(isset($this->wordbook[$v]))
477477
$v = $this->wordbook[$v];
478+
$v = $app->functions->htmlentities($v);
478479
$out .= "<option value='$k'$selected>".$this->lng($v)."</option>\r\n";
479480
}
480481
}
@@ -494,7 +495,7 @@ function getHTML($record, $tab, $action = 'NEW') {
494495
foreach($vals as $tvl) {
495496
if(trim($tvl) == trim($k)) $selected = ' SELECTED';
496497
}
497-
498+
$v = $app->functions->htmlentities($v);
498499
$out .= "<option value='$k'$selected>$v</option>\r\n";
499500
}
500501
}
@@ -577,7 +578,7 @@ function getHTML($record, $tab, $action = 'NEW') {
577578

578579
default:
579580
if(isset($record[$key])) {
580-
$new_record[$key] = htmlspecialchars($record[$key]);
581+
$new_record[$key] = $app->functions->htmlentities($record[$key]);
581582
} else {
582583
$new_record[$key] = '';
583584
}
@@ -608,7 +609,8 @@ function getHTML($record, $tab, $action = 'NEW') {
608609
$out = '';
609610
foreach($field['value'] as $k => $v) {
610611
$selected = ($k == $field["default"])?' SELECTED':'';
611-
$out .= "<option value='$k'$selected>".$this->lng($v)."</option>\r\n";
612+
$v = $app->functions->htmlentities($this->lng($v));
613+
$out .= "<option value='$k'$selected>".$v."</option>\r\n";
612614
}
613615
}
614616
if(isset($out)) $new_record[$key] = $out;
@@ -622,7 +624,7 @@ function getHTML($record, $tab, $action = 'NEW') {
622624
// HTML schreiben
623625
$out = '';
624626
foreach($field['value'] as $k => $v) {
625-
627+
$v = $app->functions->htmlentities($v);
626628
$out .= "<option value='$k'>$v</option>\r\n";
627629
}
628630
}
@@ -693,7 +695,7 @@ function getHTML($record, $tab, $action = 'NEW') {
693695
break;
694696

695697
default:
696-
$new_record[$key] = htmlspecialchars($field['default']);
698+
$new_record[$key] = $app->functions->htmlentities($field['default']);
697699
}
698700
}
699701

@@ -911,6 +913,12 @@ function filterField($field_name, $field_value, $filters, $filter_event) {
911913
case 'NOWHITESPACE':
912914
$returnval = preg_replace('/\s+/', '', $returnval);
913915
break;
916+
case 'STRIPTAGS':
917+
$returnval = strip_tags(preg_replace('/<script[^>]*>/is', '', $returnval));
918+
break;
919+
case 'STRIPNL':
920+
$returnval = str_replace(array("\n","\r"),'', $returnval);
921+
break;
914922
default:
915923
$this->errorMessage .= "Unknown Filter: ".$filter['type'];
916924
break;

interface/web/mail/form/mail_user.tform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@
144144
'name' => array (
145145
'datatype' => 'VARCHAR',
146146
'formtype' => 'TEXT',
147+
'filters' => array(
148+
0 => array( 'event' => 'SAVE',
149+
'type' => 'STRIPTAGS'),
150+
1 => array( 'event' => 'SAVE',
151+
'type' => 'STRIPNL')
152+
),
147153
'default' => '',
148154
'value' => '',
149155
'width' => '30',

0 commit comments

Comments
 (0)