A free, self-hostable news aggregator…
Use timing safe comparison for tokens everywhere (#8945)
Inverle931d62ab0855
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.phpindex c575c5831..9cf5b61c3 100644--- a/app/Controllers/userController.php+++ b/app/Controllers/userController.php@@ -605,7 +605,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {}if ($token != '') {- if ($user_config->email_validation_token !== $token) {+ if (!hash_equals($user_config->email_validation_token, $token)) {Minz_Request::bad(_t('user.email.validation.feedback.wrong_token'),['c' => 'user', 'a' => 'validateEmail']diff --git a/app/Models/Auth.php b/app/Models/Auth.phpindex ee806d78b..095f47ae3 100644--- a/app/Models/Auth.php+++ b/app/Models/Auth.php@@ -216,9 +216,9 @@ class FreshRSS_Auth {public static function isCsrfOk(?string $token = null): bool {$csrf = Minz_Session::paramString('csrf');if ($token === null) {- $token = $_POST['_csrf'] ?? '';+ $token = is_string($_POST['_csrf'] ?? null) ? $_POST['_csrf'] : '';}- return $token != '' && $token === $csrf;+ return $token != '' && hash_equals($csrf, $token);}public static function needsReauth(): bool {diff --git a/p/api/fever.php b/p/api/fever.phpindex 16ea7635f..102ac6a07 100644--- a/p/api/fever.php+++ b/p/api/fever.php@@ -176,7 +176,7 @@ final class FeverAPIif ($username != false) {$username = trim($username);FreshRSS_Context::initUser($username);- if ($feverKey === FreshRSS_Context::userConf()->feverKey && FreshRSS_Context::userConf()->enabled) {+ if (hash_equals(FreshRSS_Context::userConf()->feverKey, $feverKey) && FreshRSS_Context::userConf()->enabled) {Minz_Translate::init(FreshRSS_Context::userConf()->language);$this->entryDAO = FreshRSS_Factory::createEntryDao();$this->feedDAO = FreshRSS_Factory::createFeedDao();diff --git a/p/api/greader.php b/p/api/greader.phpindex b2bc53c44..8fb9780f6 100644--- a/p/api/greader.php+++ b/p/api/greader.php@@ -255,7 +255,7 @@ final class GReaderAPI {$token === 'x')) { //Reederreturn true;}- if ($token === str_pad(sha1(FreshRSS_Context::systemConf()->salt . $user . $conf->apiPasswordHash), 57, 'Z')) {+ if (hash_equals(str_pad(sha1(FreshRSS_Context::systemConf()->salt . $user . $conf->apiPasswordHash), 57, 'Z'), $token)) {return true;}Minz_Log::warning('Invalid POST token: ' . $token, API_LOG);diff --git a/p/api/query.php b/p/api/query.phpindex 2d92800b9..2f9a732de 100644--- a/p/api/query.php+++ b/p/api/query.php@@ -66,7 +66,7 @@ Minz_ExtensionManager::enableByList(FreshRSS_Context::userConf()->extensions_ena$query = null;$userSearch = null;foreach (FreshRSS_Context::userConf()->queries as $raw_query) {- if (!empty($raw_query['token']) && $raw_query['token'] === $token) {+ if (!empty($raw_query['token']) && hash_equals($raw_query['token'], $token)) {switch ($format) {case 'atom':case 'greader':