From 7c8fd8031038e7958ef4dbb059e86decd6fefa28 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Sat, 30 Jun 2012 12:41:18 -0400 Subject: [PATCH] Show explicit error message when provided hostname is invalid (#1488550) --- index.php | 58 +++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 35 insertions(+), 23 deletions(-) diff --git a/index.php b/index.php index 8a7a79f..54b87ce 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,7 @@ /* +-------------------------------------------------------------------------+ | Roundcube Webmail IMAP Client | - | Version 0.9-svn | + | Version 0.9-git | | | | Copyright (C) 2005-2012, The Roundcube Dev Team | | | @@ -33,9 +33,6 @@ +-------------------------------------------------------------------------+ | Author: Thomas Bruederli <roundcube@gmail.com> | +-------------------------------------------------------------------------+ - - $Id$ - */ // include environment @@ -52,7 +49,7 @@ // check if config files had errors if ($err_str = $RCMAIL->config->get_error()) { - raise_error(array( + rcmail::raise_error(array( 'code' => 601, 'type' => 'php', 'message' => $err_str), false, true); @@ -60,7 +57,7 @@ // check DB connections and exit on failure if ($err_str = $RCMAIL->db->is_error()) { - raise_error(array( + rcmail::raise_error(array( 'code' => 603, 'type' => 'db', 'message' => $err_str), FALSE, TRUE); @@ -68,13 +65,13 @@ // error steps if ($RCMAIL->action == 'error' && !empty($_GET['_code'])) { - raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); + rcmail::raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); } // check if https is required (for login) and redirect if necessary if (empty($_SESSION['user_id']) && ($force_https = $RCMAIL->config->get('force_https', false))) { $https_port = is_bool($force_https) ? 443 : $force_https; - if (!rcube_ui::https_check($https_port)) { + if (!rcube_utils::https_check($https_port)) { $host = preg_replace('/:[0-9]+$/', '', $_SERVER['HTTP_HOST']); $host .= ($https_port != 443 ? ':' . $https_port : ''); header('Location: https://' . $host . $_SERVER['REQUEST_URI']); @@ -89,26 +86,23 @@ // try to log in if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') { - $request_valid = $_SESSION['temp'] && $RCMAIL->check_request(rcube_ui::INPUT_POST, 'login'); + $request_valid = $_SESSION['temp'] && $RCMAIL->check_request(rcube_utils::INPUT_POST, 'login'); // purge the session in case of new login when a session already exists $RCMAIL->kill_session(); $auth = $RCMAIL->plugins->exec_hook('authenticate', array( 'host' => $RCMAIL->autoselect_host(), - 'user' => trim(rcube_ui::get_input_value('_user', rcube_ui::INPUT_POST)), - 'pass' => rcube_ui::get_input_value('_pass', rcube_ui::INPUT_POST, true, + 'user' => trim(rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST)), + 'pass' => rcube_utils::get_input_value('_pass', rcube_utils::INPUT_POST, true, $RCMAIL->config->get('password_charset', 'ISO-8859-1')), 'cookiecheck' => true, 'valid' => $request_valid, )); - // check if client supports cookies - if ($auth['cookiecheck'] && empty($_COOKIE)) { - $OUTPUT->show_message("cookiesdisabled", 'warning'); - } - else if ($auth['valid'] && !$auth['abort'] && - $RCMAIL->login($auth['user'], $auth['pass'], $auth['host']) + // Login + if ($auth['valid'] && !$auth['abort'] && + $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'], $auth['cookiecheck']) ) { // create new session ID, don't destroy the current session // it was destroyed already by $RCMAIL->kill_session() above @@ -123,12 +117,16 @@ // restore original request parameters $query = array(); - if ($url = rcube_ui::get_input_value('_url', rcube_ui::INPUT_POST)) { + if ($url = rcube_utils::get_input_value('_url', rcube_utils::INPUT_POST)) { parse_str($url, $query); // prevent endless looping on login page if ($query['_task'] == 'login') unset($query['_task']); + + // prevent redirect to compose with specified ID (#1488226) + if ($query['_action'] == 'compose' && !empty($query['_id'])) + $query = array(); } // allow plugins to control the redirect url after login success @@ -139,9 +137,23 @@ $OUTPUT->redirect($redir); } else { - $error_code = is_object($RCMAIL->storage) ? $RCMAIL->storage->get_error_code() : 1; + if (!$auth['valid']) { + $error_code = RCMAIL::ERROR_INVALID_REQUEST; + } + else { + $error_code = $auth['error'] ? $auth['error'] : $RCMAIL->login_error(); + } - $OUTPUT->show_message($error_code < -1 ? 'storageerror' : (!$auth['valid'] ? 'invalidrequest' : 'loginfailed'), 'warning'); + $error_labels = array( + RCMAIL::ERROR_STORAGE => 'storageerror', + RCMAIL::ERROR_COOKIES_DISABLED => 'cookiesdisabled', + RCMAIL::ERROR_INVALID_REQUEST => 'invalidrequest', + RCMAIL::ERROR_INVALID_HOST => 'invalidhost', + ); + + $error_message = $error_labels[$error_code] ? $error_labels[$error_code] : 'loginfailed'; + + $OUTPUT->show_message($error_message, 'warning'); $RCMAIL->plugins->exec_hook('login_failed', array( 'code' => $error_code, 'host' => $auth['host'], 'user' => $auth['user'])); $RCMAIL->kill_session(); @@ -172,7 +184,7 @@ // not logged in -> show login page if (empty($RCMAIL->user->ID)) { // log session failures - $task = rcube_ui::get_input_value('_task', rcube_ui::INPUT_GPC); + $task = rcube_utils::get_input_value('_task', rcube_utils::INPUT_GPC); if ($task && !in_array($task, array('login','logout')) && !$session_error && ($sess_id = $_COOKIE[ini_get('session.name')])) { $RCMAIL->session->log("Aborted session " . $sess_id . "; no valid session data found"); $session_error = true; @@ -209,7 +221,7 @@ // check client X-header to verify request origin if ($OUTPUT->ajax_call) { - if (rcube_request_header('X-Roundcube-Request') != $RCMAIL->get_request_token() && !$RCMAIL->config->get('devel_mode')) { + if (rcube_utils::request_header('X-Roundcube-Request') != $RCMAIL->get_request_token() && !$RCMAIL->config->get('devel_mode')) { header('HTTP/1.1 403 Forbidden'); die("Invalid Request"); } @@ -281,7 +293,7 @@ // if we arrive here, something went wrong -raise_error(array( +rcmail::raise_error(array( 'code' => 404, 'type' => 'php', 'line' => __LINE__, -- Gitblit v1.9.1