Skip to content

Commit 968d956

Browse files
authored
[management] Bump github.com/golang-jwt/jwt from 3.2.2+incompatible to 5.3.0 (#4375)
1 parent 28bef26 commit 968d956

File tree

17 files changed

+41
-55
lines changed

17 files changed

+41
-55
lines changed

client/internal/auth/device_flow_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ package auth
33
import (
44
"context"
55
"fmt"
6-
"github.com/golang-jwt/jwt"
7-
"github.com/netbirdio/netbird/client/internal"
8-
"github.com/stretchr/testify/require"
96
"io"
107
"net/http"
118
"net/url"
129
"strings"
1310
"testing"
1411
"time"
12+
13+
"github.com/golang-jwt/jwt/v5"
14+
"github.com/stretchr/testify/require"
15+
16+
"github.com/netbirdio/netbird/client/internal"
1517
)
1618

1719
type mockHTTPClient struct {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
cunicu.li/go-rosenpass v0.4.0
77
github.com/cenkalti/backoff/v4 v4.3.0
88
github.com/cloudflare/circl v1.3.3 // indirect
9-
github.com/golang-jwt/jwt v3.2.2+incompatible
109
github.com/golang/protobuf v1.5.4
1110
github.com/google/uuid v1.6.0
1211
github.com/gorilla/mux v1.8.0
@@ -48,6 +47,7 @@ require (
4847
github.com/fsnotify/fsnotify v1.7.0
4948
github.com/gliderlabs/ssh v0.3.8
5049
github.com/godbus/dbus/v5 v5.1.0
50+
github.com/golang-jwt/jwt/v5 v5.3.0
5151
github.com/golang/mock v1.6.0
5252
github.com/google/go-cmp v0.7.0
5353
github.com/google/gopacket v1.1.19

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
246246
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
247247
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
248248
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
249-
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
250-
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
249+
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
250+
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
251251
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
252252
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
253253
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=

management/server/auth/jwt/extractor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"net/url"
66
"time"
77

8-
"github.com/golang-jwt/jwt"
8+
"github.com/golang-jwt/jwt/v5"
99
log "github.com/sirupsen/logrus"
1010

1111
nbcontext "github.com/netbirdio/netbird/management/server/context"

management/server/auth/jwt/validator.go

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"sync"
1818
"time"
1919

20-
"github.com/golang-jwt/jwt"
20+
"github.com/golang-jwt/jwt/v5"
2121

2222
log "github.com/sirupsen/logrus"
2323
)
@@ -63,12 +63,10 @@ type Validator struct {
6363
}
6464

6565
var (
66-
errKeyNotFound = errors.New("unable to find appropriate key")
67-
errInvalidAudience = errors.New("invalid audience")
68-
errInvalidIssuer = errors.New("invalid issuer")
69-
errTokenEmpty = errors.New("required authorization token not found")
70-
errTokenInvalid = errors.New("token is invalid")
71-
errTokenParsing = errors.New("token could not be parsed")
66+
errKeyNotFound = errors.New("unable to find appropriate key")
67+
errTokenEmpty = errors.New("required authorization token not found")
68+
errTokenInvalid = errors.New("token is invalid")
69+
errTokenParsing = errors.New("token could not be parsed")
7270
)
7371

7472
func NewValidator(issuer string, audienceList []string, keysLocation string, idpSignkeyRefreshEnabled bool) *Validator {
@@ -88,24 +86,6 @@ func NewValidator(issuer string, audienceList []string, keysLocation string, idp
8886

8987
func (v *Validator) getKeyFunc(ctx context.Context) jwt.Keyfunc {
9088
return func(token *jwt.Token) (interface{}, error) {
91-
// Verify 'aud' claim
92-
var checkAud bool
93-
for _, audience := range v.audienceList {
94-
checkAud = token.Claims.(jwt.MapClaims).VerifyAudience(audience, false)
95-
if checkAud {
96-
break
97-
}
98-
}
99-
if !checkAud {
100-
return token, errInvalidAudience
101-
}
102-
103-
// Verify 'issuer' claim
104-
checkIss := token.Claims.(jwt.MapClaims).VerifyIssuer(v.issuer, false)
105-
if !checkIss {
106-
return token, errInvalidIssuer
107-
}
108-
10989
// If keys are rotated, verify the keys prior to token validation
11090
if v.idpSignkeyRefreshEnabled {
11191
// If the keys are invalid, retrieve new ones
@@ -144,7 +124,7 @@ func (v *Validator) getKeyFunc(ctx context.Context) jwt.Keyfunc {
144124
}
145125

146126
// ValidateAndParse validates the token and returns the parsed token
147-
func (m *Validator) ValidateAndParse(ctx context.Context, token string) (*jwt.Token, error) {
127+
func (v *Validator) ValidateAndParse(ctx context.Context, token string) (*jwt.Token, error) {
148128
// If the token is empty...
149129
if token == "" {
150130
// If we get here, the required token is missing
@@ -153,7 +133,13 @@ func (m *Validator) ValidateAndParse(ctx context.Context, token string) (*jwt.To
153133
}
154134

155135
// Now parse the token
156-
parsedToken, err := jwt.Parse(token, m.getKeyFunc(ctx))
136+
parsedToken, err := jwt.Parse(
137+
token,
138+
v.getKeyFunc(ctx),
139+
jwt.WithAudience(v.audienceList...),
140+
jwt.WithIssuer(v.issuer),
141+
jwt.WithIssuedAt(),
142+
)
157143

158144
// Check if there was an error in parsing...
159145
if err != nil {

management/server/auth/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"hash/crc32"
99

10-
"github.com/golang-jwt/jwt"
10+
"github.com/golang-jwt/jwt/v5"
1111

1212
"github.com/netbirdio/netbird/base62"
1313
nbjwt "github.com/netbirdio/netbird/management/server/auth/jwt"

management/server/auth/manager_mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package auth
33
import (
44
"context"
55

6-
"github.com/golang-jwt/jwt"
6+
"github.com/golang-jwt/jwt/v5"
77

88
nbcontext "github.com/netbirdio/netbird/management/server/context"
99
"github.com/netbirdio/netbird/management/server/types"

management/server/auth/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/golang-jwt/jwt"
15+
"github.com/golang-jwt/jwt/v5"
1616
"github.com/stretchr/testify/assert"
1717
"github.com/stretchr/testify/require"
1818

management/server/http/middleware/auth_middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"github.com/netbirdio/netbird/management/server/auth"
1414
nbcontext "github.com/netbirdio/netbird/management/server/context"
1515
"github.com/netbirdio/netbird/management/server/http/middleware/bypass"
16+
"github.com/netbirdio/netbird/management/server/types"
1617
"github.com/netbirdio/netbird/shared/management/http/util"
1718
"github.com/netbirdio/netbird/shared/management/status"
18-
"github.com/netbirdio/netbird/management/server/types"
1919
)
2020

2121
type EnsureAccountFunc func(ctx context.Context, userAuth nbcontext.UserAuth) (string, string, error)

management/server/http/middleware/auth_middleware_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/golang-jwt/jwt"
11+
"github.com/golang-jwt/jwt/v5"
1212
"github.com/stretchr/testify/assert"
1313

1414
"github.com/netbirdio/netbird/management/server/auth"
1515
nbjwt "github.com/netbirdio/netbird/management/server/auth/jwt"
1616
nbcontext "github.com/netbirdio/netbird/management/server/context"
17-
"github.com/netbirdio/netbird/management/server/util"
18-
1917
"github.com/netbirdio/netbird/management/server/http/middleware/bypass"
2018
"github.com/netbirdio/netbird/management/server/types"
19+
"github.com/netbirdio/netbird/management/server/util"
2120
)
2221

2322
const (

0 commit comments

Comments
 (0)