openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 463007e91d8f953e16f40ffb538d9b699c0e3764
parent 6b9a67b60cc1c0103271c8aeb3dd0360615370d2
Author: dankert <devnull@localhost>
Date:   Tue, 23 Feb 2010 22:39:25 +0100

Bei Login/Logout die Session neu erzeugen, um Session-Fixation-Angriffe zu vermeiden.

Diffstat:
actionClasses/IndexAction.class.php | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 55 insertions(+), 5 deletions(-)

diff --git a/actionClasses/IndexAction.class.php b/actionClasses/IndexAction.class.php @@ -647,6 +647,7 @@ class IndexAction extends Action if ( !$loginOk ) { + // Anmeldung nicht erfolgreich sleep(3); if ( $this->mustChangePassword ) @@ -668,7 +669,10 @@ class IndexAction extends Action return; } else - { + { + // Anmeldung erfolgreich. + $this->recreateSession(); + $user = Session::getUser(); $this->addNotice('user',$user->name,'LOGIN_OK',OR_NOTICE_OK,array('name'=>$user->fullname)); @@ -730,8 +734,22 @@ class IndexAction extends Action if ( is_object($db) ) $this->setTemplateVar('dbid',$db->id); - // Aus Sicherheitsgruenden die komplette Session deaktvieren. - session_unset(); + /* + // Alle Variablen aus der Sitzung entfernen. + session_unset(); + + // Damit wird die Session gelöscht, nicht nur die Session-Daten! + if ( ini_get("session.use_cookies") ) + { + $params = session_get_cookie_params(); + setcookie( session_name(),'', time() - 3600, + $params["path"],$params["domain"],$params["secure"],$params["httponly"] ); + } + + // Loeschen der Session. + session_destroy(); + */ + $this->recreateSession(); if ( @$conf['theme']['compiler']['compile_at_logout']) { @@ -1551,8 +1569,40 @@ class IndexAction extends Action } } - - + + /** + * Erzeugt eine neue Sitzung. + */ + function recreateSession() + { + session_unset(); + + // PHP < 4.3.2 kennt die Funktion session_regenerate_id() nicht. + if ( version_compare(phpversion(),"4.3.2","<") ) + { + $randlen = 32; + $randval = "0123456789abcdefghijklmnopqrstuvwxyz"; + $newid = ""; + for ($i = 1; $i <= $randlen; $i++) + { + $newid .= substr($randval, rand(0,(strlen($randval) - 1)), 1); + } + session_id( $newid ); + } + elseif( version_compare(phpversion(),"4.3.2","==") ) + { + session_regenerate_id(); + + // Bug in PHP 4.3.2: Session-Cookie wird nicht neu gesetzt. + if ( ini_get("session.use_cookies") ) + setcookie( session_name(),session_id(),ini_get("session.cookie_lifetime"),"/" ); + } + else + { + // PHP >= 4.3.3 + session_regenerate_id(); + } + } }