Skip to content

chore: update to JWT v5 to fix vulnerability GO-2025-3553 #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions generates/jwt_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (

"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/errors"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
)

// JWTAccessClaims jwt claims
type JWTAccessClaims struct {
jwt.StandardClaims
jwt.RegisteredClaims
}

// Valid claims verification
func (a *JWTAccessClaims) Valid() error {
if time.Unix(a.ExpiresAt, 0).Before(time.Now()) {
if a.ExpiresAt != nil && time.Unix(a.ExpiresAt.Unix(), 0).Before(time.Now()) {
return errors.ErrInvalidAccessToken
}
return nil
Expand All @@ -44,10 +44,10 @@ type JWTAccessGenerate struct {
// Token based on the UUID generated token
func (a *JWTAccessGenerate) Token(ctx context.Context, data *oauth2.GenerateBasic, isGenRefresh bool) (string, string, error) {
claims := &JWTAccessClaims{
StandardClaims: jwt.StandardClaims{
Audience: data.Client.GetID(),
RegisteredClaims: jwt.RegisteredClaims{
Audience: jwt.ClaimStrings{data.Client.GetID()},
Subject: data.UserID,
ExpiresAt: data.TokenInfo.GetAccessCreateAt().Add(data.TokenInfo.GetAccessExpiresIn()).Unix(),
ExpiresAt: jwt.NewNumericDate(data.TokenInfo.GetAccessCreateAt().Add(data.TokenInfo.GetAccessExpiresIn())),
},
}

Expand Down
7 changes: 5 additions & 2 deletions generates/jwt_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/generates"
"github.com/go-oauth2/oauth2/v4/models"
"github.com/golang-jwt/jwt"
"github.com/golang-jwt/jwt/v5"

. "github.com/smartystreets/goconvey/convey"
)
Expand Down Expand Up @@ -45,7 +45,10 @@ func TestJWTAccess(t *testing.T) {
claims, ok := token.Claims.(*generates.JWTAccessClaims)
So(ok, ShouldBeTrue)
So(token.Valid, ShouldBeTrue)
So(claims.Audience, ShouldEqual, "123456")
aud, err := claims.GetAudience()
So(err, ShouldBeNil)
So(len(aud), ShouldEqual, 1)
So(aud[0], ShouldEqual, "123456")
So(claims.Subject, ShouldEqual, "000000")
})
}