Skip to content

Commit 52a01fb

Browse files
committed
incorrect signed challenge causes a query exception, return null when no webauthn key can be found
1 parent 3368d17 commit 52a01fb

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Auth/EloquentWebAuthnProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function retrieveByCredentials(array $credentials): ?User
5050
return $this->retrieveById($webauthnKey->user_id);
5151
} catch (ModelNotFoundException $e) {
5252
// No result
53+
return null;
5354
}
5455
}
5556

tests/Unit/Auth/EloquentWebAuthnProviderTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,29 @@ public function it_retrieve_user_new_format()
142142
$this->assertNotNull($result);
143143
$this->assertEquals($user->id, $result->id);
144144
}
145+
146+
/**
147+
* @test
148+
*/
149+
public function it_does_not_fail_when_retrieving_user()
150+
{
151+
Webauthn::shouldReceive('validateAssertion')->andReturn(true);
152+
Webauthn::shouldReceive('model')->andReturn(WebauthnKey::class);
153+
154+
$provider = new EloquentWebAuthnProvider(
155+
app('config'),
156+
app(CredentialAssertionValidator::class),
157+
app(Hasher::class),
158+
User::class,
159+
);
160+
161+
$result = $provider->retrieveByCredentials([
162+
'id' => Base64UrlSafe::encode('id'),
163+
'rawId' => 'rawId',
164+
'type' => 'public-key',
165+
'response' => 'response',
166+
]);
167+
168+
$this->assertNull($result);
169+
}
145170
}

0 commit comments

Comments
 (0)