From 87e60e529939c60ef5b07d70c37426d359b2e8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Mon, 18 Jan 2016 14:26:31 +0100 Subject: [PATCH] MDL-52727 mod_data: Improve output of the form fields values This issue mostly affects the search form fields. Submitted values for these fields are typically obtained via optional_param() with PARAM_NOTAGS specified as the parameter type - see parse_search_field() methods. Such values themselves are not safe enough to be printed back directly into the HTML as they might contain malicious code. While working on the patch, some other places with weak protection were detected and fixed. In case of the itemid parameters, the s() seems to be unnecessary but it was added anyway as an extra protection (just in case the code flow changes or the parts of the code are re-used elsewhere). --- mod/data/field/file/field.class.php | 4 ++-- mod/data/field/number/field.class.php | 2 +- mod/data/field/picture/field.class.php | 4 ++-- mod/data/field/text/field.class.php | 2 +- mod/data/field/textarea/field.class.php | 4 ++-- mod/data/field/url/field.class.php | 4 ++-- mod/data/lib.php | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mod/data/field/file/field.class.php b/mod/data/field/file/field.class.php index 5fd2d215d2d..93dee4739dc 100644 --- a/mod/data/field/file/field.class.php +++ b/mod/data/field/file/field.class.php @@ -68,7 +68,7 @@ class data_field_file extends data_field_base { $html .= '
'.$this->field->name.''; // itemid element - $html .= ''; + $html .= ''; $options = new stdClass(); $options->maxbytes = $this->field->param3; @@ -92,7 +92,7 @@ class data_field_file extends data_field_base { function display_search_field($value = '') { return '' . - ''; + ''; } function generate_sql($tablealias, $value) { diff --git a/mod/data/field/number/field.class.php b/mod/data/field/number/field.class.php index d04be455d48..4035f501c98 100644 --- a/mod/data/field/number/field.class.php +++ b/mod/data/field/number/field.class.php @@ -71,7 +71,7 @@ class data_field_number extends data_field_base { function display_search_field($value = '') { return '' . - ''; + ''; } function parse_search_field() { diff --git a/mod/data/field/picture/field.class.php b/mod/data/field/picture/field.class.php index a459791f790..439c9382584 100644 --- a/mod/data/field/picture/field.class.php +++ b/mod/data/field/picture/field.class.php @@ -93,7 +93,7 @@ class data_field_picture extends data_field_base { $str .= $output->render($fm); $str .= '
'; - $str .= ''; + $str .= ''; $str .= ' '; $str .= '
'; @@ -123,7 +123,7 @@ class data_field_picture extends data_field_base { function display_search_field($value = '') { return '' . - ''; + ''; } function parse_search_field() { diff --git a/mod/data/field/text/field.class.php b/mod/data/field/text/field.class.php index 54cd497e4d9..90aee4c8d1d 100644 --- a/mod/data/field/text/field.class.php +++ b/mod/data/field/text/field.class.php @@ -27,7 +27,7 @@ class data_field_text extends data_field_base { var $type = 'text'; function display_search_field($value = '') { - return '' . ''; + return '' . ''; } function parse_search_field() { diff --git a/mod/data/field/textarea/field.class.php b/mod/data/field/textarea/field.class.php index 51ad6fc8dd5..8be1d198d5d 100644 --- a/mod/data/field/textarea/field.class.php +++ b/mod/data/field/textarea/field.class.php @@ -120,7 +120,7 @@ class data_field_textarea extends data_field_base { $formats[$fid] = $strformats[$fid]; } $editor->use_editor($field, $options, $fpoptions); - $str .= ''; + $str .= ''; $str .= '
'; $str .= '
'; $str .= ''; + ''; } function parse_search_field() { diff --git a/mod/data/field/url/field.class.php b/mod/data/field/url/field.class.php index eb0c4c57d66..b2e549f87f5 100644 --- a/mod/data/field/url/field.class.php +++ b/mod/data/field/url/field.class.php @@ -54,7 +54,7 @@ class data_field_url extends data_field_base { $str .= ''; $str .= ''; $str .= '
'; $str .= get_string('url','data').':'; $str .= ''; - $str .= ''; + $str .= ''; $str .= '
'.get_string('text','data').':
'; @@ -79,7 +79,7 @@ class data_field_url extends data_field_base { function display_search_field($value = '') { return '' . - ''; + ''; } function parse_search_field() { diff --git a/mod/data/lib.php b/mod/data/lib.php index cf7b745f56b..12956c89e4a 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -1741,9 +1741,9 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order=' $fn = !empty($search_array[DATA_FIRSTNAME]->data) ? $search_array[DATA_FIRSTNAME]->data : ''; $ln = !empty($search_array[DATA_LASTNAME]->data) ? $search_array[DATA_LASTNAME]->data : ''; $patterns[] = '/##firstname##/'; - $replacement[] = ''; + $replacement[] = ''; $patterns[] = '/##lastname##/'; - $replacement[] = ''; + $replacement[] = ''; // actual replacement of the tags $newtext = preg_replace($patterns, $replacement, $data->asearchtemplate);