diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 70d0c8cf58..8e571de379 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -193,7 +193,7 @@ class acp_board 'allow_post_flash' => array('lang' => 'ALLOW_POST_FLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'allow_smilies' => array('lang' => 'ALLOW_SMILIES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'allow_post_links' => array('lang' => 'ALLOW_POST_LINKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'allowed_schemes_links' => array('lang' => 'ALLOWED_SCHEMES_LINKS', 'validate' => 'string', 'type' => 'text:0:255', 'explain' => true), + 'allowed_schemes_links' => array('lang' => 'ALLOWED_SCHEMES_LINKS', 'validate' => 'csv', 'type' => 'text:0:255', 'explain' => true), 'allow_nocensors' => array('lang' => 'ALLOW_NO_CENSORS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'allow_bookmarks' => array('lang' => 'ALLOW_BOOKMARKS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'enable_post_confirm' => array('lang' => 'VISUAL_CONFIRM_POST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), @@ -497,6 +497,19 @@ class acp_board $cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', array('' => ''), true) : $this->new_config; $error = array(); + // Prevalidate allowed URL schemes + if ($mode == 'post') + { + $schemes = array_filter(explode(',', $cfg_array['allowed_schemes_links'])); + foreach ($schemes as $scheme) + { + if (!preg_match('#^[a-z][a-z0-9+\\-.]*$#Di', $scheme)) + { + $error[] = $language->lang('URL_SCHEME_INVALID', $language->lang('ALLOWED_SCHEMES_LINKS'), $scheme); + } + } + } + // We validate the complete config if wished validate_config_vars($display_vars['vars'], $cfg_array, $error); diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index a013af2c89..7c6eebb5a8 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -453,8 +453,20 @@ function validate_config_vars($config_vars, &$cfg_array, &$error) $error[] = $language->lang('URL_INVALID', $language->lang($config_definition['lang'])); } + goto validate_string; + + case 'csv': + // Validate comma separated values + $unfiltered_array = explode(',', $cfg_array[$config_name]); + $filtered_array = array_filter($unfiltered_array); + if (!empty($filtered_array) && count($unfiltered_array) !== count($filtered_array)) + { + $error[] = $language->lang('CSV_INVALID', $language->lang($config_definition['lang'])); + } + // no break here + validate_string: case 'string': $length = utf8_strlen($cfg_array[$config_name]); diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 3705678112..29d0ec5947 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -235,6 +235,7 @@ $lang = array_merge($lang, array( 'CRON_NO_SUCH_TASK' => 'Could not find cron task “%s”.', 'CRON_NO_TASK' => 'No cron tasks need to be run right now.', 'CRON_NO_TASKS' => 'No cron tasks could be found.', + 'CSV_INVALID' => 'The provided comma-separated setting “%1$s” is invalid. The values should be delimited by comma only, it should not contain any leading or trailing delimiters.', 'CURRENT_VERSION' => 'Current version', 'DEACTIVATE' => 'Deactivate', @@ -316,6 +317,7 @@ $lang = array_merge($lang, array( 'UCP' => 'User Control Panel', 'URL_INVALID' => 'The provided URL for the setting “%1$s” is invalid.', + 'URL_SCHEME_INVALID' => 'The provided scheme “%2$s” in comma-separated setting “%1$s” is invalid. Scheme should start with a latin character followed by alphanumeric characters, hyphens or dots.', 'USERNAMES_EXPLAIN' => 'Place each username on a separate line.', 'USER_CONTROL_PANEL' => 'User Control Panel', diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 7d12abad90..eadd1ba2de 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -218,7 +218,9 @@ class factory implements \phpbb\textformatter\cache_interface { $configurator->urlConfig->disallowScheme($scheme); } - foreach (array_filter(explode(',', $this->config['allowed_schemes_links'])) as $scheme) + + $schemes = array_filter(explode(',', $this->config['allowed_schemes_links'])); + foreach ($schemes as $scheme) { $configurator->urlConfig->allowScheme(trim($scheme)); }