From: Patrick Canterino Date: Mon, 16 Jun 2025 10:13:44 +0000 (+0200) Subject: Compare stored hashes for admin and download password using hash_equals() X-Git-Tag: 4.6.3~2^2 X-Git-Url: https://git.p6c8.net/jirafeau/pcanterino.git/commitdiff_plain/8c8f88ec2104ab0a12ceec4f5a8e2ebeb72758cc Compare stored hashes for admin and download password using hash_equals() This prevents timing attacks and attacks using Type Juggling Originally proposed by onosh --- diff --git a/admin.php b/admin.php index f8270a2..75cc38d 100644 --- a/admin.php +++ b/admin.php @@ -73,7 +73,7 @@ elseif (true === jirafeau_challenge_admin_ip($cfg, get_ip_address($cfg))) { } /* Test web password authentication. */ elseif (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) { - if ($cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) { + if (hash_equals($cfg['admin_password'], hash('sha256', $_POST['admin_password']))) { jirafeau_admin_session_start(); } else { require(JIRAFEAU_ROOT . 'lib/template/header.php'); diff --git a/f.php b/f.php index f523f72..a93ec98 100644 --- a/f.php +++ b/f.php @@ -171,7 +171,7 @@ if (!empty($link['key'])) { require(JIRAFEAU_ROOT.'lib/template/footer.php'); exit; } else { - if ($link['key'] == md5($_POST['key'])) { + if (hash_equals($link['key'], md5($_POST['key']))) { $password_challenged = true; } else { sleep(2);