Skip to content

Commit

Permalink
Merge pull request #8 from nmemoto/fix-iat-verification
Browse files Browse the repository at this point in the history
Fixed the condition to judge as valid iat
  • Loading branch information
Code-Hex authored Mar 19, 2023
2 parents a2d752f + 00c806e commit 1883637
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
2 changes: 1 addition & 1 deletion src/jwt-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}")`
Expand Down
11 changes: 0 additions & 11 deletions tests/jwt-decoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down

0 comments on commit 1883637

Please sign in to comment.