Skip to content

Commit

Permalink
refactor: catch type error when decoding base64url signature (#569)
Browse files Browse the repository at this point in the history
Co-authored-by: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
lboynton and panva authored Sep 1, 2023
1 parent f57c197 commit 935e920
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/jws/flattened/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ export async function flattenedVerify(
encoder.encode('.'),
typeof jws.payload === 'string' ? encoder.encode(jws.payload) : jws.payload,
)
const signature = base64url(jws.signature)
let signature: Uint8Array
try {
signature = base64url(jws.signature)
} catch {
throw new JWSInvalid('Failed to parse the base64url encoded signature')
}
const verified = await verify(alg, key, signature, data)

if (!verified) {
Expand Down

0 comments on commit 935e920

Please sign in to comment.