Authenticator Counter
The authenticators may have an internal counter. This feature is very helpful to detect cloned devices.
The default behaviour is to reject the assertions. This behaviour might cause some troubles as it could reject the real device whilst the fake one can continue to be used.
It is therefore required to go deeper in the protection of your application by logging the error and locking the associated account.
To do so , you have to create a custom Counter Checker and inject it to your Authenticator Assertion Response Validator. The checker must implement the interface Webauthn\Counter\CounterChecker.
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace App\Service;
7
8
use App\SecuritySystem;
9
use Assert\Assertion;
10
use Throwable;
11
use Webauthn\PublicKeyCredentialSource;
12
13
final class CustomCounterChecker implements CounterChecker
14
{
15
private $securitySystem;
16
17
public function __construct(SecuritySystem $securitySystem)
18
{
19
$this->securitySystem = $securitySystem ;
20
}
21
22
public function check(PublicKeyCredentialSource $publicKeyCredentialSource, int $currentCounter): void
23
{
24
try {
25
Assertion::greaterThan($currentCounter, $publicKeyCredentialSource->getCounter(), 'Invalid counter.');
26
} catch (Throwable $throwable) {
27
$this->securitySystem->fakeDeviceDetected($publicKeyCredentialSource);
28
throw $throwable;
29
}
30
}
31
}
Copied!

The Hard Way

1
$authenticatorAssertionResponseValidator =
2
AuthenticatorAssertionResponseValidator::create(
3
$publicKeyCredentialSourceRepository,
4
$tokenBindingHandler,
5
$extensionOutputCheckerHandler,
6
$coseAlgorithmManager
7
)
8
->setCounterChecker(new CustomCounterChecker())
9
;
Copied!
Export as PDF
Copy link
Edit on GitHub
Contents
The Hard Way