-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PM-6631] Handle Fido2VerificationException during passkey attestation and assertion #59
base: main
Are you sure you want to change the base?
Changes from all commits
ef46733
1d7b3f6
06ef83d
b97a4d3
bd46adc
bad8e6b
6c2f818
dd73045
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,38 +26,52 @@ public AssertWebAuthnLoginCredentialCommand(IFido2 fido2, IWebAuthnCredentialRep | |
{ | ||
if (!GuidUtilities.TryParseBytes(assertionResponse.Response.UserHandle, out var userId)) | ||
{ | ||
throw new BadRequestException("Invalid credential."); | ||
ThrowInvalidCredentialException(); | ||
} | ||
|
||
var user = await _userRepository.GetByIdAsync(userId); | ||
if (user == null) | ||
{ | ||
throw new BadRequestException("Invalid credential."); | ||
ThrowInvalidCredentialException(); | ||
} | ||
|
||
var userCredentials = await _webAuthnCredentialRepository.GetManyByUserIdAsync(user.Id); | ||
var assertedCredentialId = CoreHelpers.Base64UrlEncode(assertionResponse.Id); | ||
var credential = userCredentials.FirstOrDefault(c => c.CredentialId == assertedCredentialId); | ||
if (credential == null) | ||
{ | ||
throw new BadRequestException("Invalid credential."); | ||
ThrowInvalidCredentialException(); | ||
} | ||
|
||
// Always return true, since we've already filtered the credentials after user id | ||
IsUserHandleOwnerOfCredentialIdAsync callback = (args, cancellationToken) => Task.FromResult(true); | ||
var credentialPublicKey = CoreHelpers.Base64UrlDecode(credential.PublicKey); | ||
var assertionVerificationResult = await _fido2.MakeAssertionAsync( | ||
assertionResponse, options, credentialPublicKey, (uint)credential.Counter, callback); | ||
|
||
Fido2NetLib.Objects.AssertionVerificationResult assertionVerificationResult = null; | ||
try | ||
{ | ||
assertionVerificationResult = await _fido2.MakeAssertionAsync( | ||
assertionResponse, options, credentialPublicKey, (uint)credential.Counter, callback); | ||
} | ||
catch (Fido2VerificationException) | ||
{ | ||
ThrowInvalidCredentialException(); | ||
} | ||
|
||
// Update SignatureCounter | ||
credential.Counter = (int)assertionVerificationResult.Counter; | ||
await _webAuthnCredentialRepository.ReplaceAsync(credential); | ||
Comment on lines
62
to
63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Ensure that |
||
|
||
if (assertionVerificationResult.Status != "ok") | ||
{ | ||
throw new BadRequestException("Invalid credential."); | ||
ThrowInvalidCredentialException(); | ||
} | ||
|
||
return (user, credential); | ||
} | ||
|
||
private void ThrowInvalidCredentialException() | ||
{ | ||
throw new BadRequestException("Invalid credential."); | ||
} | ||
Comment on lines
+73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider making this method more flexible by allowing custom error messages or including more context in the exception. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The catch block swallows the specific exception details. Consider logging the exception message or type for better diagnostics.