@@ -401,21 +401,27 @@ userController.post('/webauthn/register-finish', async (req: Request, res: Respo
401401 console . log ( "webauthn register-finish challenge" , challenge ) ;
402402
403403 const credential = req . body . credential ;
404- const verification = await SimpleWebauthn . verifyRegistrationResponse ( {
405- response : {
406- type : credential . type ,
407- id : credential . id ,
408- rawId : credential . id , // SimpleWebauthn requires this base64url encoded
404+ let verification ;
405+ try {
406+ verification = await SimpleWebauthn . verifyRegistrationResponse ( {
409407 response : {
410- attestationObject : base64url . encode ( credential . response . attestationObject ) ,
411- clientDataJSON : base64url . encode ( credential . response . clientDataJSON ) ,
408+ type : credential . type ,
409+ id : credential . id ,
410+ rawId : credential . id , // SimpleWebauthn requires this base64url encoded
411+ response : {
412+ attestationObject : base64url . encode ( credential . response . attestationObject ) ,
413+ clientDataJSON : base64url . encode ( credential . response . clientDataJSON ) ,
414+ } ,
415+ clientExtensionResults : credential . clientExtensionResults ,
412416 } ,
413- clientExtensionResults : credential . clientExtensionResults ,
414- } ,
415- expectedChallenge : base64url . encode ( challenge . challenge ) ,
416- expectedOrigin : config . webauthn . origin ,
417- expectedRPID : config . webauthn . rp . id ,
418- } ) ;
417+ expectedChallenge : base64url . encode ( challenge . challenge ) ,
418+ expectedOrigin : config . webauthn . origin ,
419+ expectedRPID : config . webauthn . rp . id ,
420+ } ) ;
421+ } catch ( e ) {
422+ console . log ( e ) ;
423+ return res . status ( 400 ) . send ( { error : "Registration response could not be verified" } )
424+ }
419425
420426 if ( verification . verified ) {
421427 const updateUserRes = await updateUser ( user . uuid , ( userEntity , manager ) => {
0 commit comments