Skip to content

Commit

Permalink
Fixed bug where session autologin_key could be set to nothing
Browse files Browse the repository at this point in the history
For #995
  • Loading branch information
eSilverStrike committed Nov 27, 2019
1 parent 94df006 commit 540c26c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion system/lib-sessions.php
Expand Up @@ -485,9 +485,19 @@ function SESS_issueAutoLoginCookie($userId, $onlyExtendLifeSpan = true)
}

if ($onlyExtendLifeSpan) {
// Need to make sure cookie is the same as what is in the database though
$autoLoginKey = Input::cookie($_CONF['cookie_name'], '');
$autoLoginKey = preg_replace('/[^0-9a-f]/', '', $autoLoginKey);
} else {

// Make sure autologin key cookie still is the same as what is stored in the sessions table and both are not empty
$sessionId = DB_escapeString(Session::getSessionId());
if (empty(trim($autoLoginKey)) || $autoLoginKey != DB_getItem($_TABLES['sessions'], 'autologin_key', "sess_id = '$sessionId'")) {
// Something is not right since cookie does not match key stored in db so generate a new one since the user is already logged in by this point
$onlyExtendLifeSpan = false;
}
}

if (!$onlyExtendLifeSpan) {
$autoLoginKey = SEC_randomBytes(80);
$autoLoginKey = sha1($autoLoginKey);
}
Expand Down

0 comments on commit 540c26c

Please sign in to comment.