Merge pull request #4902 from SteveGilvarry/fix/login-single-session-cookie

fix: emit a single session cookie on login
This commit is contained in:
Isaac Connor
2026-06-13 11:15:27 -04:00
committed by GitHub
2 changed files with 20 additions and 2 deletions

View File

@@ -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'];

View File

@@ -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', '>=') ) {