Skip to content

Commit

Permalink
fix: dont check JWT iat is in the past unless maxTokenAge is used
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Apr 19, 2022
1 parent fbb72ab commit 96d85c7
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/lib/jwt_claims_set.ts
Expand Up @@ -87,17 +87,8 @@ export default (
const { currentDate } = options
const now = epoch(currentDate || new Date())

if (payload.iat !== undefined || options.maxTokenAge) {
if (typeof payload.iat !== 'number') {
throw new JWTClaimValidationFailed('"iat" claim must be a number', 'iat', 'invalid')
}
if (payload.exp === undefined && payload.iat > now + tolerance) {
throw new JWTClaimValidationFailed(
'"iat" claim timestamp check failed (it should be in the past)',
'iat',
'check_failed',
)
}
if ((payload.iat !== undefined || options.maxTokenAge) && typeof payload.iat !== 'number') {
throw new JWTClaimValidationFailed('"iat" claim must be a number', 'iat', 'invalid')
}

if (payload.nbf !== undefined) {
Expand Down

0 comments on commit 96d85c7

Please sign in to comment.