-
Notifications
You must be signed in to change notification settings - Fork 392
Open
Description
Both the gin-jwt library and the underlying jwt-go support a TimeFunc. By default, they are both initialized to time.Now.
https://github.com/appleboy/gin-jwt/blob/v2.6.4/auth_jwt.go#L272:
if mw.TimeFunc == nil {
mw.TimeFunc = time.Now
}https://github.com/dgrijalva/jwt-go/blob/v3.2.0/token.go#L13:
// TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time).
// You can override it to use another time value. This is useful for testing or if your
// server uses a different time zone than your tokens.
var TimeFunc = time.Nowgin-jwt should ensure that TimeFunc of each library are the same. If the two functions are not the same, it's possible for gin-jwt to create a token with an expiration date that is then falsely invalidated by jwt-go when the user of gin-jwt provides a custom TimeFunc.
Proposed Solution
The proposed solution is to simply add a line in the first snipped shown above to the following:
if mw.TimeFunc == nil {
mw.TimeFunc = time.Now
}
jwt.TimeFunc = mw.TimeFunc // proposed lineMetadata
Metadata
Assignees
Labels
No labels