Changeset 4991 in subversion


Ignore:
Timestamp:
Jul 30, 2011 11:32:13 AM (23 months ago)
Author:
thomasb
Message:

Log session validation errors; keep error message when redirecting to login after session error

Location:
trunk/roundcubemail
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/config/main.inc.php.dist

    r4963 r4991  
    4141// Log successful logins to <log_dir>/userlogins or to syslog 
    4242$rcmail_config['log_logins'] = false; 
     43 
     44// Log session authentication errors to <log_dir>/session or to syslog 
     45$rcmail_config['log_session'] = false; 
    4346 
    4447// Log SQL queries to <log_dir>/sql or to syslog 
  • trunk/roundcubemail/index.php

    r4807 r4991  
    121121    // allow plugins to control the redirect url after login success 
    122122    $redir = $RCMAIL->plugins->exec_hook('login_after', $query + array('_task' => 'mail')); 
    123     unset($redir['abort']); 
     123    unset($redir['abort'], $redir['_err']); 
    124124 
    125125    // send redirect 
     
    148148else if ($RCMAIL->task != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') { 
    149149  if (!$RCMAIL->session->check_auth()) { 
    150     $OUTPUT->show_message('sessionerror', 'error'); 
    151150    $RCMAIL->kill_session(); 
     151    $session_error = true; 
    152152  } 
    153153} 
     
    155155// not logged in -> show login page 
    156156if (empty($RCMAIL->user->ID)) { 
     157  // log session failures 
     158  if ($RCMAIL->task != 'login' && !$session_error && ($sess_id = $_COOKIE[ini_get('session.name')])) { 
     159    $RCMAIL->session->log("Aborted session " . $sess_id . "; no valid session data found"); 
     160    $session_error = true; 
     161  } 
     162 
    157163  if ($OUTPUT->ajax_call) 
    158     $OUTPUT->redirect(array(), 2000); 
     164    $OUTPUT->redirect(array('_err' => 'session'), 2000); 
    159165 
    160166  if (!empty($_REQUEST['_framed'])) 
    161     $OUTPUT->command('redirect', '?'); 
     167    $OUTPUT->command('redirect', $RCMAIL->url(array('_err' => 'session'))); 
    162168 
    163169  // check if installer is still active 
     
    172178    ); 
    173179  } 
     180   
     181  if ($session_error || $_REQUEST['_err'] == 'session') 
     182    $OUTPUT->show_message('sessionerror', 'error', null, true, -1); 
    174183 
    175184  $RCMAIL->set_task('login'); 
  • trunk/roundcubemail/program/include/rcube_session.php

    r4782 r4991  
    4343  private $secret = ''; 
    4444  private $ip_check = false; 
     45  private $logging = false; 
    4546  private $keep_alive = 0; 
    4647  private $memcache; 
     
    5455    $this->start = microtime(true); 
    5556    $this->ip = $_SERVER['REMOTE_ADDR']; 
     57    $this->logging = $config->get('log_session', false); 
    5658 
    5759    $lifetime = $config->get('session_lifetime', 1) * 60; 
     
    566568    $result = $this->ip_check ? $_SERVER['REMOTE_ADDR'] == $this->ip : true; 
    567569 
     570    if (!$result) 
     571      $this->log("IP check failed for " . $this->key . "; expected " . $this->ip . "; got " . $_SERVER['REMOTE_ADDR']); 
     572 
    568573    if ($result && $this->_mkcookie($this->now) != $this->cookie) { 
    569574      // Check if using id from previous time slot 
    570       if ($this->_mkcookie($this->prev) == $this->cookie) 
     575      if ($this->_mkcookie($this->prev) == $this->cookie) { 
    571576        $this->set_auth_cookie(); 
    572       else 
     577      } 
     578      else { 
    573579        $result = false; 
     580        $this->log("Session authentication failed for " . $this->key . "; invalid auth cookie sent"); 
     581      } 
    574582    } 
    575583 
     
    599607    return "S" . (function_exists('sha1') ? sha1($auth_string) : md5($auth_string)); 
    600608  } 
     609   
     610  /** 
     611   *  
     612   */ 
     613  function log($line) 
     614  { 
     615    if ($this->logging) 
     616      write_log('session', $line); 
     617  } 
    601618 
    602619} 
  • trunk/roundcubemail/program/js/app.js

    r4990 r4991  
    51545154    } 
    51555155 
    5156     window.setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout); 
     5156    if (timeout > 0) 
     5157      window.setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout); 
    51575158    return id; 
    51585159  }; 
Note: See TracChangeset for help on using the changeset viewer.