Skip to content

Commit 6ce3783

Browse files
authored
fix: fix base64 padding (#381)
1 parent bf6c54a commit 6ce3783

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/Auth/EloquentWebAuthnProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public function retrieveByCredentials(array $credentials)
5454
{
5555
if ($this->isSignedChallenge($credentials)) {
5656
try {
57-
$webauthnKey = (Webauthn::model())::where([
58-
'credentialId' => Base64UrlSafe::encode(Base64::decode($credentials['id'])),
59-
])->firstOrFail();
57+
$webauthnKey = (Webauthn::model())::where('credentialId', Base64UrlSafe::encode(Base64::decode($credentials['id'])))
58+
->orWhere('credentialId', Base64UrlSafe::encodeUnpadded(Base64::decode($credentials['id'])))
59+
->firstOrFail();
6060

6161
return $this->retrieveById($webauthnKey->user_id);
6262
} catch (ModelNotFoundException $e) {

src/Services/Webauthn/CredentialRepository.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,16 @@ public function getRegisteredKeys(User $user): array
111111
*/
112112
private function model(string $credentialId): WebauthnKey
113113
{
114-
return (Webauthn::model())::where(array_filter(
115-
[
116-
'user_id' => $this->guard()->guest() ? null : $this->guard()->id(),
117-
'credentialId' => Base64UrlSafe::encode($credentialId),
118-
]
119-
))->firstOrFail();
114+
return (Webauthn::model())::where(function ($query) {
115+
if ($this->guard()->check()) {
116+
$query->where('user_id', $this->guard()->id());
117+
}
118+
})
119+
->where(function ($query) use ($credentialId) {
120+
$query->where('credentialId', Base64UrlSafe::encode($credentialId))
121+
->orWhere('credentialId', Base64UrlSafe::encodeUnpadded($credentialId));
122+
})
123+
->firstOrFail();
120124
}
121125

122126
/**

0 commit comments

Comments
 (0)