From 59584283c52f06a478e61e93b1d0f69a750a1768 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 17 May 2017 11:13:58 +0200 Subject: [FIX] web: properly escape field values when necessary This rev. removes some html injections issues: - in char and text field widgets - in phone field widget in mobile - in list views (when no widget is instantiated) --- addons/web/static/src/js/fields/field_utils.js | 41 ++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src/js/fields/field_utils.js') diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index ed3014d9bb6..98fafcef7f1 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -52,10 +52,18 @@ function formatBoolean(value) { * an empty string. * * @param {string|false} value + * @param {Object} [field] + * a description of the field (note: this parameter is ignored) + * @param {Object} [options] additional options + * @param {boolean} [options.escape=false] if true, escapes the formatted value * @returns {string} */ -function formatChar(value) { - return typeof value === 'string' ? value : ''; +function formatChar(value, field, options) { + value = typeof value === 'string' ? value : ''; + if (options && options.escape) { + value = _.escape(value); + } + return value; } /** @@ -189,10 +197,18 @@ function formatInteger(value) { * case, we assume that it is a record from a BasicModel. * * @param {Array|Object|false} value + * @param {Object} [field] + * a description of the field (note: this parameter is ignored) + * @param {Object} [options] additional options + * @param {boolean} [options.escape=false] if true, escapes the formatted value * @returns {string} */ -function formatMany2one(value) { - return value && (_.isArray(value) ? value[1] : value.data.display_name) || ''; +function formatMany2one(value, field, options) { + value = value && (_.isArray(value) ? value[1] : value.data.display_name) || ''; + if (options && options.escape) { + value = _.escape(value); + } + return value; } /** @@ -270,14 +286,27 @@ function formatMonetary(value, field, options) { } } -function formatSelection(value, field) { +/** + * Returns a string representing the value of the selection. + * + * @param {string|false} value + * @param {Object} [field] + * a description of the field (note: this parameter is ignored) + * @param {Object} [options] additional options + * @param {boolean} [options.escape=false] if true, escapes the formatted value + */ +function formatSelection(value, field, options) { if (!value) { return ''; } var val = _.find(field.selection, function (option) { return option[0] === value; }); - return val[1]; + value = val[1]; + if (options && options.escape) { + value = _.escape(value); + } + return value; } //////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3