Authenticator Counter
webauthn:
counter_checker: App\Service\CustomCounterChecker<?php
declare(strict_types=1);
namespace Acme\Service;
use Assert\Assertion;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Throwable;
use Webauthn\PublicKeyCredentialSource;
final class CustomCounterChecker implements CounterChecker
{
public function __construct(private UserRepository $userRepository)
{
}
public function check(PublicKeyCredentialSource $publicKeyCredentialSource, int $currentCounter): void
{
if ($currentCounter > $publicKeyCredentialSource->getCounter()) {
return;
}
$userId = $publicKeyCredentialSource->getUserHandle();
$user = $this->userRepository->lockUserWithId($userId);
$this->logger->error('The counter is invalid', [
'current' => $currentCounter,
'new' => $publicKeyCredentialSource->getCounter(),
]);
throw new CustomSecurityException('Invalid counter. User is now locked.');
}
}Was this helpful?