From 7150af6b9e21ed7802202702b1dac3a3df1998c0 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 21 Jun 2024 19:18:21 +0100 Subject: [PATCH] [core] use sha3 instead of md5 for csrf tokens --- core/user.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/user.php b/core/user.php index 0b7b556d..225f0b38 100644 --- a/core/user.php +++ b/core/user.php @@ -238,20 +238,16 @@ class User /** * Get an auth token to be used in POST forms * - * password = secret, avoid storing directly - * passhash = bcrypt(password), so someone who gets to the database can't get passwords - * sesskey = md5(passhash . IP), so if it gets sniffed it can't be used from another IP, - * and it can't be used to get the passhash to generate new sesskeys - * authtok = md5(sesskey, salt), presented to the user in web forms, to make sure that - * the form was generated within the session. Salted and re-hashed so that - * reading a web page from the user's cache doesn't give access to the session key + * the token is based on + * - the user's password, so that only this user can use the token + * - the session IP, to reduce the blast radius of guessed passwords + * - a salt known only to the server, so that clients or attackers + * can't generate their own tokens even if they know the first two */ public function get_auth_token(): string { global $config; - $salt = SECRET; - $addr = get_session_ip($config); - return md5(md5($this->passhash . $addr) . "salty-csrf-" . $salt); + return hash("sha3-256", $this->passhash . get_session_ip($config) . SECRET); }