From 9aa017d0f7ce13a11114cbae24b694e935931342 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 25 Nov 2016 22:15:13 +0100 Subject: [ticket/14875] Add method for raw input to request and add to installer A method for retrieving raw input has been added to the request class. This will be used in the installer to retrieve the datatabase password while also allowing utf8 characters. Not escaping the input is ok in this case as it won't be put anywhere in this raw form and only be used to populate the entry for the password field in config.php. PHPBB3-14875 --- phpBB/phpbb/request/request.php | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'phpBB/phpbb/request/request.php') diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php index 4cac6fbaea..318d9f66f9 100644 --- a/phpBB/phpbb/request/request.php +++ b/phpBB/phpbb/request/request.php @@ -224,6 +224,68 @@ class request implements \phpbb\request\request_interface return $this->_variable($var_name, $default, $multibyte, $super_global, false); } + /** + * Get a variable without trimming strings and without escaping. + * This method MUST NOT be used with queries. + * Same functionality as variable(), except does not run trim() on strings + * and does not escape input. + * This method should only be used when the raw input is needed without + * any escaping, i.e. for database password during the installation. + * + * @param string|array $var_name The form variable's name from which data shall be retrieved. + * If the value is an array this may be an array of indizes which will give + * direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") + * then specifying array("var", 1) as the name will return "a". + * @param mixed $default A default value that is returned if the variable was not set. + * This function will always return a value of the same type as the default. + * @param \phpbb\request\request_interface::POST|GET|REQUEST|COOKIE $super_global + * Specifies which super global should be used + * + * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the + * the same as that of $default. If the variable is not set $default is returned. + */ + public function raw_variable($var_name, $default, $super_global = \phpbb\request\request_interface::REQUEST) + { + $path = false; + + // deep direct access to multi dimensional arrays + if (is_array($var_name)) + { + $path = $var_name; + // make sure at least the variable name is specified + if (empty($path)) + { + return (is_array($default)) ? array() : $default; + } + // the variable name is the first element on the path + $var_name = array_shift($path); + } + + if (!isset($this->input[$super_global][$var_name])) + { + return (is_array($default)) ? array() : $default; + } + $var = $this->input[$super_global][$var_name]; + + if ($path) + { + // walk through the array structure and find the element we are looking for + foreach ($path as $key) + { + if (is_array($var) && isset($var[$key])) + { + $var = $var[$key]; + } + else + { + return (is_array($default)) ? array() : $default; + } + } + } + + return $var; + } + /** * Shortcut method to retrieve SERVER variables. * -- cgit v1.2.1 From 08bf8812d3bc7c22671e7e0dc88a0e99fcf403d7 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 25 Nov 2016 22:51:29 +0100 Subject: [ticket/14875] Use raw_variable() method in _variable() to get raw data The raw_variable() method uses the same exact code the _variable method has been using until now. PHPBB3-14875 --- phpBB/phpbb/request/request.php | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) (limited to 'phpBB/phpbb/request/request.php') diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php index 318d9f66f9..0d9ffa1780 100644 --- a/phpBB/phpbb/request/request.php +++ b/phpBB/phpbb/request/request.php @@ -431,41 +431,14 @@ class request implements \phpbb\request\request_interface */ protected function _variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST, $trim = true) { - $path = false; - - // deep direct access to multi dimensional arrays - if (is_array($var_name)) - { - $path = $var_name; - // make sure at least the variable name is specified - if (empty($path)) - { - return (is_array($default)) ? array() : $default; - } - // the variable name is the first element on the path - $var_name = array_shift($path); - } - - if (!isset($this->input[$super_global][$var_name])) - { - return (is_array($default)) ? array() : $default; - } - $var = $this->input[$super_global][$var_name]; + $var = $this->raw_variable($var_name, $default, $super_global); - if ($path) + // Return prematurely if raw variable is empty array or the same as + // the default. Using strict comparison to ensure that one can't + // prevent proper type checking on any input variable + if ($var === array() || $var === $default) { - // walk through the array structure and find the element we are looking for - foreach ($path as $key) - { - if (is_array($var) && isset($var[$key])) - { - $var = $var[$key]; - } - else - { - return (is_array($default)) ? array() : $default; - } - } + return $var; } $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $trim); -- cgit v1.2.1 From 9bdd002f584de78475362067b777749486504172 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 2 Dec 2016 11:36:07 +0100 Subject: [ticket/14875] Move raw_variable() method to request_interface PHPBB3-14875 --- phpBB/phpbb/request/request.php | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'phpBB/phpbb/request/request.php') diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php index 0d9ffa1780..92d4213180 100644 --- a/phpBB/phpbb/request/request.php +++ b/phpBB/phpbb/request/request.php @@ -225,24 +225,7 @@ class request implements \phpbb\request\request_interface } /** - * Get a variable without trimming strings and without escaping. - * This method MUST NOT be used with queries. - * Same functionality as variable(), except does not run trim() on strings - * and does not escape input. - * This method should only be used when the raw input is needed without - * any escaping, i.e. for database password during the installation. - * - * @param string|array $var_name The form variable's name from which data shall be retrieved. - * If the value is an array this may be an array of indizes which will give - * direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") - * then specifying array("var", 1) as the name will return "a". - * @param mixed $default A default value that is returned if the variable was not set. - * This function will always return a value of the same type as the default. - * @param \phpbb\request\request_interface::POST|GET|REQUEST|COOKIE $super_global - * Specifies which super global should be used - * - * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the - * the same as that of $default. If the variable is not set $default is returned. + * {@inheritdoc} */ public function raw_variable($var_name, $default, $super_global = \phpbb\request\request_interface::REQUEST) { -- cgit v1.2.1