Details
Recommended Fix
Three coordinated changes, matching the three failure modes:
- Replace "never expire" with a very long expiry (for example 10 years) so every token has a finite
expclaim. This removes the conditional atjwt.go:103entirely:
if expiry == model.NEVER_EXPIRY {
expiry = int64((10 * 365 * 24 * time.Hour).Seconds())
}
claims.ExpiresAt = jwt.NewNumericDate(time.Now().UTC().Add(time.Duration(expiry) * time.Second))
- If the "never expire" semantics must be preserved, make logout handle nil
ExpiresAtexplicitly:
if claims, err := jwtUtil.ParseToken(authHeader[7:]); err == nil && claims.ID != "" {
var remaining time.Duration
if claims.ExpiresAt != nil {
remaining = time.Until(claims.ExpiresAt.Time)
} else {
remaining = 365 * 24 * time.Hour
}
h.authService.RevokeToken(claims.ID, remaining)
}
And accept non-positive TTLs in RevokeToken by substituting a long default.
- Blacklist the JTI when admin deletes an access token:
tok, err := settingService.settingRepository.GetAccessTokenByID(ctx, id)
if err != nil {
return err
}
if tok.JTI != "" {
settingService.authRepo.RevokeToken(tok.JTI, 365*24*time.Hour)
}
return settingService.transactor.Run(ctx, func(txCtx context.Context) error {
return settingService.settingRepository.DeleteAccessTokenByID(txCtx, id)
})
Any two of the three changes close the gap; all three together make the revocation semantics match the admin's mental model.
---
*Found by aisafe.io*