diff --git a/web/includes/auth.php b/web/includes/auth.php index a1d45c74b..768ec578e 100644 --- a/web/includes/auth.php +++ b/web/includes/auth.php @@ -635,8 +635,8 @@ if (ZM_OPT_USE_AUTH) { } // end if success==false } // end if using reCaptcha - zm_session_clear(); # Closes session - zm_session_regenerate_id(); # starts session + # Drop the pre-auth session and issue a fresh id in a single Set-Cookie + zm_session_regenerate_id_login(); $username = $_REQUEST['username']; $password = $_REQUEST['password']; diff --git a/web/includes/session.php b/web/includes/session.php index 3139336af..37e0dd761 100644 --- a/web/includes/session.php +++ b/web/includes/session.php @@ -92,6 +92,24 @@ function zm_session_regenerate_id() { : $_SERVER['REMOTE_ADDR']; } // function zm_session_regenerate_id() +// Regenerate the session id at a privilege boundary (login). +// When called with an already-started session (the normal login flow), this +// should emit a single Set-Cookie via session_regenerate_id(true) while +// discarding any pre-auth session data and deleting the old session server-side. +// Assumes zm_session_start() has been called previously. +function zm_session_regenerate_id_login() { + if (!is_session_started()) zm_session_start(); + // Discard any pre-auth session contents so nothing carries across the + // authentication boundary. + $_SESSION = array(); + // New id + delete the old session file server-side. Emits a single Set-Cookie. + session_regenerate_id(true); + $_SESSION['generated_at'] = time(); + $_SESSION['remoteAddr'] = !empty($_SERVER['HTTP_X_FORWARDED_FOR']) + ? trim(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0]) + : $_SERVER['REMOTE_ADDR']; +} // function zm_session_regenerate_id_login() + function is_session_started() { if ( php_sapi_name() !== 'cli' ) { if ( version_compare(phpversion(), '5.4.0', '>=') ) {