From 00c806e9c29ff74668a0fcc66bbe413309cc1da1 Mon Sep 17 00:00:00 2001 From: Takafumi Umemoto Date: Sat, 11 Mar 2023 01:34:46 +0900 Subject: [PATCH] Fixed the condition to judge as valid iat --- src/jwt-decoder.ts | 2 +- tests/jwt-decoder.test.ts | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/jwt-decoder.ts b/src/jwt-decoder.ts index fed3720..41d8eb9 100644 --- a/src/jwt-decoder.ts +++ b/src/jwt-decoder.ts @@ -96,7 +96,7 @@ const decodePayload = (payloadPart: string, currentTimestamp: number): DecodedPa throw new JwtError(JwtErrorCode.INVALID_ARGUMENT, `"iat" claim must be a number but got "${payload.iat}"`); } - if (currentTimestamp <= payload.iat) { + if (currentTimestamp < payload.iat) { throw new JwtError( JwtErrorCode.INVALID_ARGUMENT, `Incorrect "iat" claim must be a older than "${currentTimestamp}" (iat: "${payload.iat}")` diff --git a/tests/jwt-decoder.test.ts b/tests/jwt-decoder.test.ts index 2b06d44..c7b17e7 100644 --- a/tests/jwt-decoder.test.ts +++ b/tests/jwt-decoder.test.ts @@ -87,17 +87,6 @@ describe('TokenDecoder', () => { `Incorrect "iat" claim must be a older than "${currentTimestamp}" (iat: "${currentTimestamp + 10000}")` ), ], - [ - 'iat is now', - { - ...payload, - iat: currentTimestamp, - }, - new JwtError( - JwtErrorCode.INVALID_ARGUMENT, - `Incorrect "iat" claim must be a older than "${currentTimestamp}" (iat: "${currentTimestamp}")` - ), - ], [ 'exp is in past', {