Skip to content

Commit

Permalink
corrected validation of issuedAt and notBefore in token calim (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thottbot committed Oct 23, 2023
1 parent 96f587e commit 225c166
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions v2/auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ func IsTokenValid(token string, tokenExpireDurationDiff time.Duration) bool {

ts := time.Now().Add(tokenExpireDurationDiff)

for _, claim := range []*jwt.NumericDate{
claims.ExpiresAt,
claims.IssuedAt,
claims.NotBefore,
} {
if claim == nil {
continue
}

if claim.Before(ts) {
return false
}
if claims.ExpiresAt != nil && ts.Before(claims.ExpiresAt.Time) {
return false
}

if claims.IssuedAt != nil && ts.After(claims.IssuedAt.Time) {
return false
}

if claims.NotBefore != nil && ts.After(claims.NotBefore.Time) {
return false
}

return true
Expand Down

0 comments on commit 225c166

Please sign in to comment.