Skip to content

Commit c379897

Browse files
authored
Merge pull request wwWallet#88 from wwWallet/fix/verify-registration-response-catch
Handle exception in verifyRegistrationResponse
2 parents 8f39641 + c218e23 commit c379897

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/routers/user.router.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)