diff options
author | Fabian Cook <hello@fabiancook.dev> | 2023-09-12 21:48:00 +1200 |
---|---|---|
committer | Fabian Cook <hello@fabiancook.dev> | 2023-09-12 21:48:00 +1200 |
commit | b446d501d5ed6d93672db36ee1a1ae739404a360 (patch) | |
tree | 2dea3d5df68a1181c9889c90139ad475b58f8649 /packages/server/src | |
parent | 2e4a2d62ce72af50f725202b8292f9244213e066 (diff) |
expectedType for verifyAuthenticationResponse
Related to https://github.com/MasterKale/SimpleWebAuthn/discussions/402
Diffstat (limited to 'packages/server/src')
-rw-r--r-- | packages/server/src/authentication/verifyAuthenticationResponse.ts | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/packages/server/src/authentication/verifyAuthenticationResponse.ts b/packages/server/src/authentication/verifyAuthenticationResponse.ts index 41370a0..efc56ee 100644 --- a/packages/server/src/authentication/verifyAuthenticationResponse.ts +++ b/packages/server/src/authentication/verifyAuthenticationResponse.ts @@ -18,6 +18,7 @@ export type VerifyAuthenticationResponseOpts = { expectedChallenge: string | ((challenge: string) => boolean | Promise<boolean>); expectedOrigin: string | string[]; expectedRPID: string | string[]; + expectedType?: string | string[]; authenticator: AuthenticatorDevice; requireUserVerification?: boolean; advancedFIDOConfig?: { @@ -52,6 +53,7 @@ export async function verifyAuthenticationResponse( expectedChallenge, expectedOrigin, expectedRPID, + expectedType, authenticator, requireUserVerification = true, advancedFIDOConfig, @@ -88,7 +90,16 @@ export async function verifyAuthenticationResponse( const { type, origin, challenge, tokenBinding } = clientDataJSON; // Make sure we're handling an authentication - if (type !== 'webauthn.get') { + if (Array.isArray(expectedType)) { + if (!expectedType.includes(type)) { + const joinedExpectedType = expectedType.join(', '); + throw new Error(`Unexpected authentication response type "${type}", expected one of: ${joinedExpectedType}`); + } + } else if (expectedType) { + if (type !== expectedType) { + throw new Error(`Unexpected authentication response type "${type}", expected "${expectedType}"`); + } + } else if (type !== 'webauthn.get') { throw new Error(`Unexpected authentication response type: ${type}`); } |