-
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?
Conversation
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.
3 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
Fido2NetLib.Objects.AssertionVerificationResult assertionVerificationResult = null; | ||
try | ||
{ | ||
assertionVerificationResult = await _fido2.MakeAssertionAsync( | ||
assertionResponse, options, credentialPublicKey, (uint)credential.Counter, callback); | ||
} | ||
catch (Fido2VerificationException) | ||
{ | ||
ThrowInvalidCredentialException(); | ||
} |
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.
credential.Counter = (int)assertionVerificationResult.Counter; | ||
await _webAuthnCredentialRepository.ReplaceAsync(credential); |
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.
logic: Ensure that assertionVerificationResult
is not null before accessing its properties.
private void ThrowInvalidCredentialException() | ||
{ | ||
throw new BadRequestException("Invalid credential."); | ||
} |
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: Consider making this method more flexible by allowing custom error messages or including more context in the exception.
Type of change
Objective
In bitwarden#3615 we handled the
Fido2VerificationException
when asserting a WebAuthn credential for 2FA.In this PR, we address the
MakeNewCredentialAsync
methods similarly, as well as theMakeAssertionAsync
when asserting a WebAuthn credential for login, which was missed in bitwarden#3615 .📓 We have https://bitwarden.atlassian.net/browse/PM-4172 in the backlog to consolidate the implementations, at which point we should consider an abstraction.
Code changes
BadRequestException
instead of the unhandled exception returned previously. This will be handled on the client, as it is the pattern already established in the class for communicating assertion errors.false
along with a log message. I did this instead of throwing aBadRequestException
as this is the pattern already established in this command for handling invalid data. I added a log here as returningfalse
gives no indication of the root cause.false
along with a log message. I did this instead of throwing aBadRequestException
as this is the pattern already established in this command for handling invalid data. I added a log here as returningfalse
gives no indication of the root cause.Before you submit
dotnet format --verify-no-changes
) (required)Greptile Summary
This pull request addresses exception handling for WebAuthn credential creation and assertion, focusing on improving error management in three key files:
AssertWebAuthnLoginCredentialCommand.cs
to handleFido2VerificationException
during login credential assertionCreateWebAuthnLoginCredentialCommand.cs
for WebAuthn credential creation, returning false and logging errors on exceptionUserService.cs
to catchFido2VerificationException
during WebAuthn registration, logging the error and returning false on failureBadRequestException
throwing inAssertWebAuthnLoginCredentialCommand.cs
for consistent error handling