Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Improved "remember me" cookie handling
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Apr 29, 2024
1 parent e9f2b71 commit cc36083
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,14 @@ private static function GetSignMeToken(): ?array
\SnappyMail\Log::notice(self::AUTH_SIGN_ME_TOKEN_KEY, 'decrypt');
$aResult = \SnappyMail\Crypt::DecryptUrlSafe($sSignMeToken, 'signme');
if (isset($aResult['e'], $aResult['u']) && \SnappyMail\UUID::isValid($aResult['u'])) {
if (!isset($aResult['c'])) {
$aTokenData['c'] = \array_key_last($aTokenData);
$aTokenData['d'] = \end($aTokenData);
}
return $aResult;
}
\SnappyMail\Log::notice(self::AUTH_SIGN_ME_TOKEN_KEY, 'invalid');
// Don't clear due to login checkbox
// Cookies::clear(self::AUTH_SIGN_ME_TOKEN_KEY);
Cookies::clear(self::AUTH_SIGN_ME_TOKEN_KEY);
}
return null;
}
Expand All @@ -360,7 +363,8 @@ public function SetSignMeToken(MainAccount $oAccount): void
\SnappyMail\Crypt::EncryptUrlSafe([
'e' => $oAccount->Email(),
'u' => $uuid,
$data[0] => \base64_encode($data[1])
'c' => $data[0],
'd' => \base64_encode($data[1])
], 'signme'),
\time() + 3600 * 24 * 30 // 30 days
);
Expand All @@ -382,8 +386,8 @@ public function GetAccountFromSignMeToken(): ?MainAccount
throw new \RuntimeException("server token not found for {$aTokenData['e']}/.sign_me/{$aTokenData['u']}");
}
$aAccountHash = \SnappyMail\Crypt::Decrypt([
\array_key_last($aTokenData),
\base64_decode(\end($aTokenData)),
$aTokenData['c'],
\base64_decode($aTokenData['d']),
$sAuthToken
], 'signme');
if (!\is_array($aAccountHash)) {
Expand All @@ -401,8 +405,7 @@ public function GetAccountFromSignMeToken(): ?MainAccount
catch (\Throwable $oException)
{
\SnappyMail\Log::warning(self::AUTH_SIGN_ME_TOKEN_KEY, $oException->getMessage());
// Don't clear due to smctoken cookie missing at initialization and login checkbox
// $this->ClearSignMeData();
$this->ClearSignMeData();
}
}
return null;
Expand Down

0 comments on commit cc36083

Please sign in to comment.