Bugfix: Call to a member function Email() on null #1706

This commit is contained in:
the-djmaze 2024-08-27 23:39:27 +02:00
parent 1ad946d013
commit 082dd3af41

View file

@ -98,13 +98,15 @@ class ServiceActions
$token = Utils::GetCsrfToken();
if (isset($_SERVER['HTTP_X_SM_TOKEN'])) {
if ($_SERVER['HTTP_X_SM_TOKEN'] !== $token) {
$sEmail = $this->oActions->getAccountFromToken(false)->Email();
$oAccount = $this->oActions->getAccountFromToken(false);
$sEmail = $oAccount ? $oAccount->Email() : 'guest';
$this->oActions->logWrite("{$_SERVER['HTTP_X_SM_TOKEN']} !== {$token} for {$sEmail}", \LOG_ERROR, 'Token');
throw new Exceptions\ClientException(Notifications::InvalidToken, null, 'HTTP Token mismatch');
}
} else if ($this->oHttp->IsPost()) {
if (empty($_POST['XToken']) || $_POST['XToken'] !== $token) {
$sEmail = $this->oActions->getAccountFromToken(false)->Email();
$oAccount = $this->oActions->getAccountFromToken(false);
$sEmail = $oAccount ? $oAccount->Email() : 'guest';
$this->oActions->logWrite("{$_POST['XToken']} !== {$token} for {$sEmail}", \LOG_ERROR, 'XToken');
throw new Exceptions\ClientException(Notifications::InvalidToken, null, 'XToken mismatch');
}