From a77cf2292b1b5e010172b572f618aef78795456b Mon Sep 17 00:00:00 2001 From: thomascube Date: Tue, 8 Feb 2011 08:13:06 +0000 Subject: Add optional referer check to prevent CSRF in GET requests --- program/include/main.inc | 15 ++++++++++++++- program/steps/utils/error.inc | 9 ++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'program') diff --git a/program/include/main.inc b/program/include/main.inc index 155f4afee..35f9ddc98 100644 --- a/program/include/main.inc +++ b/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: | @@ -1264,6 +1264,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/program/steps/utils/error.inc b/program/steps/utils/error.inc index 422827a23..8b0496911 100644 --- a/program/steps/utils/error.inc +++ b/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!
\n". + "Please contact your server-administrator."; +} + // failed request (wrong step in URL) else if ($ERROR_CODE==404) { $__error_title = "REQUEST FAILED/FILE NOT FOUND"; -- cgit v1.2.3