Changeset 521 in subversion


Ignore:
Timestamp:
Mar 27, 2007 5:34:30 AM (6 years ago)
Author:
thomasb
Message:

New session authentication, should fix bugs #1483951 and #1484299; testing required

Location:
trunk/roundcubemail
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r519 r521  
    11CHANGELOG RoundCube Webmail 
    22--------------------------- 
     3 
     42007/03/27 (thomasb) 
     5---------- 
     6- New session authentication: Change sessid cookie when login, authentication with sessauth cookie is now configurable. 
     7  Should close bugs #1483951 and #1484299 
     8 
    39 
    4102007/03/23 (thomasb) 
  • trunk/roundcubemail/UPGRADING

    r434 r521  
    1717  $rcmail_config['preview_pane'] = TRUE; 
    1818  $rcmail_config['date_today'] = 'H:i'; 
     19  $rcmail_config['double_auth'] = TRUE; 
    1920 
    2021 
  • trunk/roundcubemail/config/main.inc.php.dist

    r423 r521  
    9898 
    9999// check client IP in session athorization 
    100 $rcmail_config['ip_check'] = TRUE; 
     100$rcmail_config['ip_check'] = false; 
     101 
     102// Use an additional frequently changing cookie to athenticate user sessions. 
     103// There have been problems reported with this feature. 
     104$rcmail_config['double_auth'] = false; 
    101105 
    102106// this key is used to encrypt the users imap password which is stored 
  • trunk/roundcubemail/index.php

    r510 r521  
    33 +-----------------------------------------------------------------------+ 
    44 | RoundCube Webmail IMAP Client                                         | 
    5  | Version 0.1-20070301                                                  | 
     5 | Version 0.1-20070327                                                  | 
    66 |                                                                       | 
    77 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 | 
     
    4141*/ 
    4242 
    43 define('RCMAIL_VERSION', '0.1-20070301'); 
     43define('RCMAIL_VERSION', '0.1-20070327'); 
    4444 
    4545// define global vars 
     
    173173    show_message("cookiesdisabled", 'warning'); 
    174174    } 
    175   else if (isset($_POST['_user']) && isset($_POST['_pass']) && 
     175  else if ($_SESSION['temp'] && isset($_POST['_user']) && isset($_POST['_pass']) && 
    176176           rcmail_login(get_input_value('_user', RCUBE_INPUT_POST), 
    177177              get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host)) 
    178178    { 
     179    // create new session ID 
     180    unset($_SESSION['temp']); 
     181    sess_regenerate_id(); 
     182 
     183    // send auth cookie if necessary 
     184    rcmail_authenticate_session(); 
     185 
    179186    // send redirect 
    180187    header("Location: $COMM_PATH"); 
     
    198205else if ($_action != 'login' && $_SESSION['user_id'] && $_action != 'send') 
    199206  { 
    200   if (!rcmail_authenticate_session() || 
    201       (!empty($CONFIG['session_lifetime']) && isset($SESS_CHANGED) && $SESS_CHANGED + $CONFIG['session_lifetime']*60 < mktime())) 
     207  if (!rcmail_authenticate_session()) 
    202208    { 
    203209    $message = show_message('sessionerror', 'error'); 
  • trunk/roundcubemail/program/include/main.inc

    r515 r521  
    3434function rcmail_startup($task='mail') 
    3535  { 
    36   global $sess_id, $sess_auth, $sess_user_lang; 
     36  global $sess_id, $sess_user_lang; 
    3737  global $CONFIG, $INSTALL_PATH, $BROWSER, $OUTPUT, $_SESSION, $IMAP, $DB, $JS_OBJECT_NAME; 
    3838 
     
    5454  $DB->db_connect('w'); 
    5555 
    56   // we can use the database for storing session data 
    57   if (!$DB->is_error()) 
    58     include_once('include/session.inc'); 
     56  // use database for storing session data 
     57  include_once('include/session.inc'); 
    5958 
    6059  // init session 
     
    6665    { 
    6766    $_SESSION['user_lang'] = rcube_language_prop($CONFIG['locale_string']); 
    68     $_SESSION['auth_time'] = mktime(); 
    69     setcookie('sessauth', rcmail_auth_hash($sess_id, $_SESSION['auth_time'])); 
     67    $_SESSION['auth_time'] = time(); 
     68    $_SESSION['temp'] = true; 
    7069    } 
    7170 
     
    179178function rcmail_authenticate_session() 
    180179  { 
    181   $now = mktime(); 
    182   $valid = ($_COOKIE['sessauth'] == rcmail_auth_hash(session_id(), $_SESSION['auth_time']) || 
    183                                                 $_COOKIE['sessauth'] == rcmail_auth_hash(session_id(), $_SESSION['last_auth'])); 
    184  
    185   // renew auth cookie every 5 minutes (only for GET requests) 
    186   if (!$valid || ($_SERVER['REQUEST_METHOD']!='POST' && $now-$_SESSION['auth_time'] > 300)) 
    187     { 
    188     $_SESSION['last_auth'] = $_SESSION['auth_time']; 
    189     $_SESSION['auth_time'] = $now; 
    190     setcookie('sessauth', rcmail_auth_hash(session_id(), $now)); 
    191     } 
     180  global $CONFIG, $SESS_CLIENT_IP, $SESS_CHANGED; 
     181   
     182  // advanced session authentication 
     183  if ($CONFIG['double_auth']) 
     184  { 
     185    $now = time(); 
     186    $valid = ($_COOKIE['sessauth'] == rcmail_auth_hash(session_id(), $_SESSION['auth_time']) || 
     187              $_COOKIE['sessauth'] == rcmail_auth_hash(session_id(), $_SESSION['last_auth'])); 
     188 
     189    // renew auth cookie every 5 minutes (only for GET requests) 
     190    if (!$valid || ($_SERVER['REQUEST_METHOD']!='POST' && $now-$_SESSION['auth_time'] > 300)) 
     191    { 
     192      $_SESSION['last_auth'] = $_SESSION['auth_time']; 
     193      $_SESSION['auth_time'] = $now; 
     194      setcookie('sessauth', rcmail_auth_hash(session_id(), $now)); 
     195    } 
     196  } 
     197  else 
     198    $valid = $CONFIG['ip_check'] ? $_SERVER['REMOTE_ADDR'] == $SESS_CLIENT_IP : true; 
     199   
     200  // check session filetime 
     201  if (!empty($CONFIG['session_lifetime']) && isset($SESS_CHANGED) && $SESS_CHANGED + $CONFIG['session_lifetime']*60 < time()) 
     202    $valid = false; 
    192203 
    193204  return $valid; 
     
    276287    } 
    277288 
    278   $_SESSION = array(); 
    279   session_destroy(); 
     289  $_SESSION = array('user_lang' => $GLOBALS['sess_user_lang'], 'auth_time' => time(), 'temp' => true); 
     290  setcookie('sessauth', '-del-', time()-60); 
    280291  } 
    281292 
  • trunk/roundcubemail/program/include/session.inc

    r339 r521  
    3737function sess_read($key) 
    3838  { 
    39   global $DB, $SESS_CHANGED; 
     39  global $DB, $SESS_CHANGED, $SESS_CLIENT_IP; 
     40   
     41  if ($DB->is_error()) 
     42    return FALSE; 
    4043   
    4144  $sql_result = $DB->query("SELECT vars, ip, ".$DB->unixtimestamp('changed')." AS changed 
     
    4750    { 
    4851    $SESS_CHANGED = $sql_arr['changed']; 
     52    $SESS_CLIENT_IP = $sql_arr['ip']; 
    4953 
    5054    if (strlen($sql_arr['vars'])) 
     
    6064  { 
    6165  global $DB; 
     66   
     67  if ($DB->is_error()) 
     68    return FALSE; 
    6269 
    6370  $sql_result = $DB->query("SELECT 1 
     
    97104  global $DB; 
    98105   
     106  if ($DB->is_error()) 
     107    return FALSE; 
     108   
    99109  // delete session entries in cache table 
    100110  $DB->query("DELETE FROM ".get_table_name('cache')." 
     
    114124  { 
    115125  global $DB; 
     126 
     127  if ($DB->is_error()) 
     128    return FALSE; 
    116129 
    117130  // get all expired sessions   
     
    145158 
    146159 
     160function sess_regenerate_id() 
     161  { 
     162  $randlen = 32; 
     163  $randval = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
     164  $random = ""; 
     165  for ($i=1; $i <= $randlen; $i++) 
     166    $random .= substr($randval, rand(0,(strlen($randval) - 1)), 1); 
     167 
     168  // use md5 value for id or remove capitals from string $randval 
     169  $random = md5($random); 
     170 
     171  // delete old session record 
     172  sess_destroy(session_id()); 
     173 
     174  session_id($random); 
     175  $cookie = session_get_cookie_params(); 
     176  setcookie(session_name(), $random, $cookie['lifetime'], $cookie['path']); 
     177 
     178  return true; 
     179  } 
     180 
     181 
    147182// set custom functions for PHP session management 
    148183session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy', 'sess_gc'); 
Note: See TracChangeset for help on using the changeset viewer.