Skip to content

Commit ec6a6a5

Browse files
committed
test: add a check that signatures are verified before claims set
1 parent f64cadd commit ec6a6a5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/jwt/verify.test.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,14 @@ test('Signed JWTs cannot use unencoded payload', async (t) => {
380380
{ code: 'ERR_JWT_INVALID', message: 'JWTs MUST NOT use unencoded payload' },
381381
)
382382
})
383+
384+
test('signatures are compared before claim set', async (t) => {
385+
// https://github.com/panva/jose/discussions/447
386+
const jwt = await new SignJWT({ exp: 0 }).setProtectedHeader({ alg: 'HS256' }).sign(t.context.secret);
387+
388+
// with valid secret should throw exp failing to verify
389+
await t.throwsAsync(jwtVerify(jwt, t.context.secret), { code: 'ERR_JWT_EXPIRED' })
390+
391+
// with invalid secret should throw signature failing to verify
392+
await t.throwsAsync(jwtVerify(jwt, new Uint8Array([0x00, 0x01])), { code: 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED' })
393+
})

0 commit comments

Comments
 (0)