EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Use hash equals
Yurii3570160c949b
diff --git a/application/Espo/Core/Authentication/Authentication.php b/application/Espo/Core/Authentication/Authentication.phpindex fa6c8fdbf0..978a714ccb 100644--- a/application/Espo/Core/Authentication/Authentication.php+++ b/application/Espo/Core/Authentication/Authentication.php@@ -829,10 +829,10 @@ class Authentication$authToken = $this->authTokenManager->get($password);}- if ($authToken && $authToken->getSecret()) {+ if ($authToken?->getSecret()) {$sentSecret = $request->getCookieParam(self::COOKIE_AUTH_TOKEN_SECRET);- if ($sentSecret !== $authToken->getSecret()) {+ if (!$sentSecret || !hash_equals($authToken->getSecret(), $sentSecret)) {$authToken = null;}}diff --git a/application/Espo/Core/Authentication/Logins/Hmac.php b/application/Espo/Core/Authentication/Logins/Hmac.phpindex 4afcebda96..84bb28fd25 100644--- a/application/Espo/Core/Authentication/Logins/Hmac.php+++ b/application/Espo/Core/Authentication/Logins/Hmac.php@@ -76,11 +76,12 @@ class Hmac implements Login$string = $request->getMethod() . ' ' . $request->getResourcePath();// As of v8.4.1.- if ($hash === ApiKey::hash($secretKey, $string)) {+ if (hash_equals(ApiKey::hash($secretKey, $string), $hash)) {return Result::success($user);}- if ($hash === ApiKey::hashLegacy($secretKey, $string)) {+ // @todo Remove in v11.0.+ if (hash_equals(ApiKey::hashLegacy($secretKey, $string), $hash)) {return Result::success($user);}diff --git a/application/Espo/Core/Utils/ApiKey.php b/application/Espo/Core/Utils/ApiKey.phpindex f1b0afc2c7..ad76cc0be0 100644--- a/application/Espo/Core/Utils/ApiKey.php+++ b/application/Espo/Core/Utils/ApiKey.php@@ -46,6 +46,7 @@ class ApiKey/*** @deprecated+ * @todo Remove in v11.0.* @internal*/public static function hashLegacy(string $secretKey, string $string = ''): stringdiff --git a/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php b/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.phpindex 1edc0c1639..a584887ee9 100644--- a/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php+++ b/application/Espo/Modules/Crm/EntryPoints/CampaignUrl.php@@ -153,7 +153,7 @@ class CampaignUrl implements EntryPoint{$hashActual = $this->hasher->hash($emailAddress);- if ($hashActual !== $hash) {+ if (!hash_equals($hashActual, $hash)) {throw new NotFoundSilent();}@@ -182,7 +182,7 @@ class CampaignUrl implements EntryPoint{$hashActual = $this->hasher->hash($uid);- if ($hashActual !== $hash) {+ if (!hash_equals($hashActual, $hash)) {throw new NotFoundSilent();}diff --git a/application/Espo/Modules/Crm/Tools/MassEmail/UnsubscribeService.php b/application/Espo/Modules/Crm/Tools/MassEmail/UnsubscribeService.phpindex 811390f2ee..b5b7375f2c 100644--- a/application/Espo/Modules/Crm/Tools/MassEmail/UnsubscribeService.php+++ b/application/Espo/Modules/Crm/Tools/MassEmail/UnsubscribeService.php@@ -30,6 +30,7 @@namespace Espo\Modules\Crm\Tools\MassEmail;use Espo\Core\Exceptions\NotFound;+use Espo\Core\Exceptions\NotFoundSilent;use Espo\Core\HookManager;use Espo\Core\Name\Field;use Espo\Core\ORM\EntityManager;@@ -315,10 +316,10 @@ class UnsubscribeService*/private function getEmailAddressWithHash(string $emailAddress, string $hash): EmailAddress{- $hash2 = $this->hasher->hash($emailAddress);+ $hashActual = $this->hasher->hash($emailAddress);- if ($hash2 !== $hash) {- throw new NotFound();+ if (!hash_equals($hashActual, $hash)) {+ throw new NotFoundSilent();}$address = $this->getEmailAddressRepository()->getByAddress($emailAddress);