Use hash_equals for checking username
This makes the comparison happen in constant time and makes it impossible to use it to guess stored usernames. Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
parent
58245cb1cc
commit
6117ad5cef
@ -413,14 +413,14 @@ class AuthenticationCookie extends AuthenticationPlugin
|
||||
|
||||
// Ensures valid authentication mode, 'only_db', bookmark database and
|
||||
// table names and relation table name are used
|
||||
if ($cfg['Server']['user'] != $GLOBALS['PHP_AUTH_USER']) {
|
||||
if (! hash_equals($cfg['Server']['user'], $GLOBALS['PHP_AUTH_USER'])) {
|
||||
foreach ($cfg['Servers'] as $idx => $current) {
|
||||
if ($current['host'] == $cfg['Server']['host']
|
||||
&& $current['port'] == $cfg['Server']['port']
|
||||
&& $current['socket'] == $cfg['Server']['socket']
|
||||
&& $current['ssl'] == $cfg['Server']['ssl']
|
||||
&& $current['connect_type'] == $cfg['Server']['connect_type']
|
||||
&& $current['user'] == $GLOBALS['PHP_AUTH_USER']
|
||||
&& hash_equals($current['user'], $GLOBALS['PHP_AUTH_USER'])
|
||||
) {
|
||||
$GLOBALS['server'] = $idx;
|
||||
$cfg['Server'] = $current;
|
||||
|
||||
@ -164,7 +164,7 @@ class AuthenticationHttp extends AuthenticationPlugin
|
||||
// User logged out -> ensure the new username is not the same
|
||||
$old_usr = isset($_REQUEST['old_usr']) ? $_REQUEST['old_usr'] : '';
|
||||
if (! empty($old_usr)
|
||||
&& (isset($PHP_AUTH_USER) && $old_usr == $PHP_AUTH_USER)
|
||||
&& (isset($PHP_AUTH_USER) && hash_equals($old_usr, $PHP_AUTH_USER))
|
||||
) {
|
||||
$PHP_AUTH_USER = '';
|
||||
// -> delete user's choices that were stored in session
|
||||
@ -197,12 +197,12 @@ class AuthenticationHttp extends AuthenticationPlugin
|
||||
|
||||
// Ensures valid authentication mode, 'only_db', bookmark database and
|
||||
// table names and relation table name are used
|
||||
if ($cfg['Server']['user'] != $PHP_AUTH_USER) {
|
||||
if (! hash_equals($cfg['Server']['user'], $PHP_AUTH_USER)) {
|
||||
$servers_cnt = count($cfg['Servers']);
|
||||
for ($i = 1; $i <= $servers_cnt; $i++) {
|
||||
if (isset($cfg['Servers'][$i])
|
||||
&& ($cfg['Servers'][$i]['host'] == $cfg['Server']['host']
|
||||
&& $cfg['Servers'][$i]['user'] == $PHP_AUTH_USER)
|
||||
&& hash_equals($cfg['Servers'][$i]['user'], $PHP_AUTH_USER))
|
||||
) {
|
||||
$server = $i;
|
||||
$cfg['Server'] = $cfg['Servers'][$i];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user