[Svn] r4503 - in trunk/roundcubemail: . config program/include program/steps/utils

trac at roundcube.net trac at roundcube.net
Tue Feb 8 09:13:06 CET 2011


Author: thomasb
Date: 2011-02-08 02:13:06 -0600 (Tue, 08 Feb 2011)
New Revision: 4503

Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/config/main.inc.php.dist
   trunk/roundcubemail/index.php
   trunk/roundcubemail/program/include/main.inc
   trunk/roundcubemail/program/steps/utils/error.inc
Log:
Add optional referer check to prevent CSRF in GET requests

Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2011-02-08 08:12:31 UTC (rev 4502)
+++ trunk/roundcubemail/CHANGELOG	2011-02-08 08:13:06 UTC (rev 4503)
@@ -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

Modified: trunk/roundcubemail/config/main.inc.php.dist
===================================================================
--- trunk/roundcubemail/config/main.inc.php.dist	2011-02-08 08:12:31 UTC (rev 4502)
+++ trunk/roundcubemail/config/main.inc.php.dist	2011-02-08 08:13:06 UTC (rev 4503)
@@ -212,6 +212,9 @@
 // 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.

Modified: trunk/roundcubemail/index.php
===================================================================
--- trunk/roundcubemail/index.php	2011-02-08 08:12:31 UTC (rev 4502)
+++ trunk/roundcubemail/index.php	2011-02-08 08:13:06 UTC (rev 4503)
@@ -190,6 +190,14 @@
     $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

Modified: trunk/roundcubemail/program/include/main.inc
===================================================================
--- trunk/roundcubemail/program/include/main.inc	2011-02-08 08:12:31 UTC (rev 4502)
+++ trunk/roundcubemail/program/include/main.inc	2011-02-08 08:13:06 UTC (rev 4503)
@@ -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 @@
 
 
 /**
+ * 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
  */

Modified: trunk/roundcubemail/program/steps/utils/error.inc
===================================================================
--- trunk/roundcubemail/program/steps/utils/error.inc	2011-02-08 08:12:31 UTC (rev 4502)
+++ trunk/roundcubemail/program/steps/utils/error.inc	2011-02-08 08:13:06 UTC (rev 4503)
@@ -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 @@
                    "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";

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list