Skip to content

Commit b74a164

Browse files
authored
fix: Invalid app authentication setup with recovery codes (#19644)
1 parent 5c5c439 commit b74a164

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/panels/src/Auth/MultiFactor/App/AppAuthentication.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,17 @@ public function generateRecoveryCodes(): array
164164
return Collection::times($this->getRecoveryCodeCount(), fn (): string => Str::random(10) . '-' . Str::random(10))->all();
165165
}
166166

167-
public function verifyCode(string $code, ?string $secret = null): bool
167+
public function verifyCode(string $code, ?string $secret = null, bool $shouldPreventCodeReuse = false): bool
168168
{
169169
/** @var HasAppAuthentication $user */
170170
$user = Filament::auth()->user();
171171

172172
$secret = $secret ?? $this->getSecret($user);
173+
174+
if (! $shouldPreventCodeReuse) {
175+
return $this->google2FA->verifyKey($secret, $code, $this->getCodeWindow());
176+
}
177+
173178
$cacheKey = 'filament.app_authentication_codes.' . md5($secret . $code);
174179

175180
$timestamp = $this->google2FA->verifyKeyNewer($secret, $code, cache()->get($cacheKey), $this->getCodeWindow());
@@ -327,7 +332,7 @@ public function getChallengeFormComponents(Authenticatable $user): array
327332
->required(fn (Get $get): bool => (! $isRecoverable) || blank($get('recoveryCode')))
328333
->rule(function () use ($user): Closure {
329334
return function (string $attribute, $value, Closure $fail) use ($user): void {
330-
if ($this->verifyCode($value, $this->getSecret($user))) {
335+
if ($this->verifyCode($value, $this->getSecret($user), shouldPreventCodeReuse: true)) {
331336
return;
332337
}
333338

0 commit comments

Comments
 (0)