From b405227d51583e29fe305f0cd19d2802a3885e07 Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Tue, 10 Mar 2026 15:14:21 -0300 Subject: [PATCH] fix(jwt): consolidate the dependencies BE-12695 (#2020) --- .golangci.yaml | 2 ++ api/jwt/jwt.go | 2 +- api/jwt/jwt_kubeconfig_test.go | 2 +- api/jwt/jwt_test.go | 2 +- api/oauth/oauth.go | 4 ++-- go.mod | 3 +-- go.sum | 2 -- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 1eeb32be9..2fedf1ead 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -58,6 +58,8 @@ linters: desc: use go.yaml.in/yaml/v3 instead - pkg: gopkg.in/yaml.v3 desc: use go.yaml.in/yaml/v3 instead + - pkg: github.com/golang-jwt/jwt/v4 + desc: use github.com/golang-jwt/jwt/v5 instead - pkg: github.com/mitchellh/mapstructure desc: use github.com/go-viper/mapstructure/v2 instead - pkg: gopkg.in/alecthomas/kingpin.v2 diff --git a/api/jwt/jwt.go b/api/jwt/jwt.go index 3fec37ee3..f461f4807 100644 --- a/api/jwt/jwt.go +++ b/api/jwt/jwt.go @@ -9,7 +9,7 @@ import ( "github.com/portainer/portainer/api/apikey" "github.com/portainer/portainer/api/dataservices" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" "github.com/google/uuid" "github.com/rs/zerolog/log" ) diff --git a/api/jwt/jwt_kubeconfig_test.go b/api/jwt/jwt_kubeconfig_test.go index 648bfea3d..696531ef6 100644 --- a/api/jwt/jwt_kubeconfig_test.go +++ b/api/jwt/jwt_kubeconfig_test.go @@ -7,7 +7,7 @@ import ( "github.com/portainer/portainer/api/dataservices" "github.com/portainer/portainer/api/datastore" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/api/jwt/jwt_test.go b/api/jwt/jwt_test.go index d48458e41..b9470d967 100644 --- a/api/jwt/jwt_test.go +++ b/api/jwt/jwt_test.go @@ -8,7 +8,7 @@ import ( "github.com/portainer/portainer/api/datastore" "github.com/portainer/portainer/api/internal/testhelpers" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/api/oauth/oauth.go b/api/oauth/oauth.go index 0d9dfa33f..7221189d8 100644 --- a/api/oauth/oauth.go +++ b/api/oauth/oauth.go @@ -12,7 +12,7 @@ import ( portainer "github.com/portainer/portainer/api" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" "github.com/pkg/errors" "github.com/rs/zerolog/log" "github.com/segmentio/encoding/json" @@ -87,7 +87,7 @@ func GetIdToken(token *oauth2.Token) (map[string]any, error) { return tokenData, nil } - jwtParser := jwt.Parser{SkipClaimsValidation: true} + jwtParser := jwt.NewParser(jwt.WithoutClaimsValidation()) t, _, err := jwtParser.ParseUnverified(idToken.(string), jwt.MapClaims{}) if err != nil { diff --git a/go.mod b/go.mod index 4515c1fc7..c1118d0ad 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/g07cha/defender v0.0.0-20180505193036-5665c627c814 github.com/go-git/go-git/v5 v5.17.0 github.com/go-ldap/ldap/v3 v3.4.1 - github.com/golang-jwt/jwt/v4 v4.5.2 + github.com/golang-jwt/jwt/v5 v5.2.2 github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 github.com/gorilla/csrf v1.7.3 @@ -156,7 +156,6 @@ require ( github.com/gobwas/glob v0.2.3 // indirect github.com/gofrs/flock v0.12.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang-jwt/jwt/v5 v5.2.2 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect diff --git a/go.sum b/go.sum index 90a900b7b..544ed7792 100644 --- a/go.sum +++ b/go.sum @@ -315,8 +315,6 @@ github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= -github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=