Skip to content

Commit fb61132

Browse files
authored
Merge pull request #282 from matthiasthomas/jwt-v5
chore: update to JWT v5 to fix vulnerability GO-2025-3553
2 parents 00133fa + a0d555d commit fb61132

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

generates/jwt_access.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import (
88

99
"github.com/go-oauth2/oauth2/v4"
1010
"github.com/go-oauth2/oauth2/v4/errors"
11-
"github.com/golang-jwt/jwt"
11+
"github.com/golang-jwt/jwt/v5"
1212
"github.com/google/uuid"
1313
)
1414

1515
// JWTAccessClaims jwt claims
1616
type JWTAccessClaims struct {
17-
jwt.StandardClaims
17+
jwt.RegisteredClaims
1818
}
1919

2020
// Valid claims verification
2121
func (a *JWTAccessClaims) Valid() error {
22-
if time.Unix(a.ExpiresAt, 0).Before(time.Now()) {
22+
if a.ExpiresAt != nil && time.Unix(a.ExpiresAt.Unix(), 0).Before(time.Now()) {
2323
return errors.ErrInvalidAccessToken
2424
}
2525
return nil
@@ -44,10 +44,10 @@ type JWTAccessGenerate struct {
4444
// Token based on the UUID generated token
4545
func (a *JWTAccessGenerate) Token(ctx context.Context, data *oauth2.GenerateBasic, isGenRefresh bool) (string, string, error) {
4646
claims := &JWTAccessClaims{
47-
StandardClaims: jwt.StandardClaims{
48-
Audience: data.Client.GetID(),
47+
RegisteredClaims: jwt.RegisteredClaims{
48+
Audience: jwt.ClaimStrings{data.Client.GetID()},
4949
Subject: data.UserID,
50-
ExpiresAt: data.TokenInfo.GetAccessCreateAt().Add(data.TokenInfo.GetAccessExpiresIn()).Unix(),
50+
ExpiresAt: jwt.NewNumericDate(data.TokenInfo.GetAccessCreateAt().Add(data.TokenInfo.GetAccessExpiresIn())),
5151
},
5252
}
5353

generates/jwt_access_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/go-oauth2/oauth2/v4"
1010
"github.com/go-oauth2/oauth2/v4/generates"
1111
"github.com/go-oauth2/oauth2/v4/models"
12-
"github.com/golang-jwt/jwt"
12+
"github.com/golang-jwt/jwt/v5"
1313

1414
. "github.com/smartystreets/goconvey/convey"
1515
)
@@ -45,7 +45,10 @@ func TestJWTAccess(t *testing.T) {
4545
claims, ok := token.Claims.(*generates.JWTAccessClaims)
4646
So(ok, ShouldBeTrue)
4747
So(token.Valid, ShouldBeTrue)
48-
So(claims.Audience, ShouldEqual, "123456")
48+
aud, err := claims.GetAudience()
49+
So(err, ShouldBeNil)
50+
So(len(aud), ShouldEqual, 1)
51+
So(aud[0], ShouldEqual, "123456")
4952
So(claims.Subject, ShouldEqual, "000000")
5053
})
5154
}

0 commit comments

Comments
 (0)