diff options
| author | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-02-08 08:13:06 +0000 |
|---|---|---|
| committer | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-02-08 08:13:06 +0000 |
| commit | 7c95446d869d392f330f93cda8de91941c99d75b (patch) | |
| tree | cbf75f0f720600e5a51269f8fed3f56635ee6e3c | |
| parent | 3b73335cc73cda7f827e49a44950f886ba38a16b (diff) | |
Add optional referer check to prevent CSRF in GET requests
git-svn-id: https://svn.roundcube.net/trunk@4503 208e9e7b-5314-0410-a742-e7e81cd9613c
| -rw-r--r-- | roundcubemail/CHANGELOG | 1 | ||||
| -rw-r--r-- | roundcubemail/config/main.inc.php.dist | 3 | ||||
| -rw-r--r-- | roundcubemail/index.php | 8 | ||||
| -rw-r--r-- | roundcubemail/program/include/main.inc | 15 | ||||
| -rw-r--r-- | roundcubemail/program/steps/utils/error.inc | 9 |
5 files changed, 34 insertions, 2 deletions
diff --git a/roundcubemail/CHANGELOG b/roundcubemail/CHANGELOG index 2a7cdfbf6..9a008e9ee 100644 --- a/roundcubemail/CHANGELOG +++ b/roundcubemail/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Security: add optional referer check to prevent CSRF in GET requests - Fix email_dns_check setting not used for identities/contacts (#1487740) - Fix ICANN example addresses doesn't validate (#1487742) - Security: protect login form submission from CSRF diff --git a/roundcubemail/config/main.inc.php.dist b/roundcubemail/config/main.inc.php.dist index 7dfca7afb..36c52775a 100644 --- a/roundcubemail/config/main.inc.php.dist +++ b/roundcubemail/config/main.inc.php.dist @@ -212,6 +212,9 @@ $rcmail_config['session_domain'] = ''; // check client IP in session athorization $rcmail_config['ip_check'] = false; +// check referer of incoming requests +$rcmail_config['referer_check'] = false; + // this key is used to encrypt the users imap password which is stored // in the session record (and the client cookie if remember password is enabled). // please provide a string of exactly 24 chars. diff --git a/roundcubemail/index.php b/roundcubemail/index.php index bf38874d0..f50cf2bb3 100644 --- a/roundcubemail/index.php +++ b/roundcubemail/index.php @@ -190,6 +190,14 @@ else { $OUTPUT->show_message('invalidrequest', 'error'); $OUTPUT->send($RCMAIL->task); } + + // check referer if configured + if (!$request_check_whitelist[$RCMAIL->action] && $RCMAIL->config->get('referer_check') && !rcube_check_referer()) { + raise_error(array( + 'code' => 403, + 'type' => 'php', + 'message' => "Referer check failed"), true, true); + } } // handle special actions diff --git a/roundcubemail/program/include/main.inc b/roundcubemail/program/include/main.inc index 155f4afee..35f9ddc98 100644 --- a/roundcubemail/program/include/main.inc +++ b/roundcubemail/program/include/main.inc @@ -5,7 +5,7 @@ | program/include/main.inc | | | | This file is part of the Roundcube Webmail client | - | Copyright (C) 2005-2009, The Roundcube Dev Team | + | Copyright (C) 2005-2011, The Roundcube Dev Team | | Licensed under the GNU GPL | | | | PURPOSE: | @@ -1265,6 +1265,19 @@ function rcmail_remote_ip() /** + * Check whether the HTTP referer matches the current request + * + * @return boolean True if referer is the same host+path, false if not + */ +function rcube_check_referer() +{ + $uri = parse_url($_SERVER['REQUEST_URI']); + $referer = parse_url(rc_request_header('Referer')); + return $referer['host'] == rc_request_header('Host') && $referer['path'] == $uri['path']; +} + + +/** * @access private * @return mixed */ diff --git a/roundcubemail/program/steps/utils/error.inc b/roundcubemail/program/steps/utils/error.inc index 422827a23..8b0496911 100644 --- a/roundcubemail/program/steps/utils/error.inc +++ b/roundcubemail/program/steps/utils/error.inc @@ -5,7 +5,7 @@ | program/steps/utils/error.inc | | | | This file is part of the Roundcube Webmail client | - | Copyright (C) 2005-2010, The Roundcube Dev Team | + | Copyright (C) 2005-2011, The Roundcube Dev Team | | Licensed under the GNU GPL | | | | PURPOSE: | @@ -47,6 +47,13 @@ else if ($ERROR_CODE==401) { "Please contact your server-administrator."; } +// forbidden due to request check +else if ($ERROR_CODE==403) { + $__error_title = "REQUEST CHECK FAILED"; + $__error_text = "Access to this service was denied due to failing security checks!<br />\n". + "Please contact your server-administrator."; +} + // failed request (wrong step in URL) else if ($ERROR_CODE==404) { $__error_title = "REQUEST FAILED/FILE NOT FOUND"; |
