From 9bb1f14f3e73e3ae71891e1530bfb3749cfa819a Mon Sep 17 00:00:00 2001 From: harryzcy Date: Wed, 19 Jul 2023 00:59:44 -0500 Subject: [PATCH 1/3] Bump github.com/golang-jwt/jwt to v5 --- cmd/serv.go | 2 +- go.mod | 3 ++- go.sum | 2 ++ modules/generate/generate.go | 2 +- routers/web/auth/oauth.go | 22 +++++++++----------- routers/web/auth/oauth_test.go | 2 +- services/auth/source/oauth2/jwtsigningkey.go | 2 +- services/auth/source/oauth2/token.go | 5 ++++- services/lfs/server.go | 2 +- services/packages/auth.go | 2 +- 10 files changed, 24 insertions(+), 20 deletions(-) diff --git a/cmd/serv.go b/cmd/serv.go index 484e3bf4048a8..6b5cb78667e09 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -30,7 +30,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/services/lfs" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" "github.com/kballard/go-shellquote" "github.com/urfave/cli" ) diff --git a/go.mod b/go.mod index 885bb34220469..45138d39d1d0d 100644 --- a/go.mod +++ b/go.mod @@ -54,7 +54,7 @@ require ( github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 - github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/golang-jwt/jwt/v5 v5.0.0 github.com/google/go-github/v53 v53.0.0 github.com/google/pprof v0.0.0-20230502171905-255e3b9b56de github.com/google/uuid v1.3.0 @@ -196,6 +196,7 @@ require ( github.com/go-openapi/validate v0.22.0 // indirect github.com/go-webauthn/revoke v0.1.9 // indirect github.com/goccy/go-json v0.10.2 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/golang/geo v0.0.0-20230421003525-6adc56603217 // indirect diff --git a/go.sum b/go.sum index 9b4538bc65bc5..fef2ce2b90afc 100644 --- a/go.sum +++ b/go.sum @@ -507,6 +507,8 @@ github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85/go.mod h1:fR6z github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= diff --git a/modules/generate/generate.go b/modules/generate/generate.go index f29634e05e663..8b82976e85f3c 100644 --- a/modules/generate/generate.go +++ b/modules/generate/generate.go @@ -12,7 +12,7 @@ import ( "code.gitea.io/gitea/modules/util" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" ) // NewInternalToken generate a new value intended to be used by INTERNAL_TOKEN. diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index db15bf2e3d1a5..3c367b3d27ff6 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -37,7 +37,7 @@ import ( user_service "code.gitea.io/gitea/services/user" "gitea.com/go-chi/binding" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" "github.com/markbates/goth" "github.com/markbates/goth/gothic" go_oauth2 "golang.org/x/oauth2" @@ -342,17 +342,15 @@ func IntrospectOAuth(ctx *context.Context) { form := web.GetForm(ctx).(*forms.IntrospectTokenForm) token, err := oauth2.ParseToken(form.Token, oauth2.DefaultSigningKey) if err == nil { - if token.Valid() == nil { - grant, err := auth.GetOAuth2GrantByID(ctx, token.GrantID) - if err == nil && grant != nil { - app, err := auth.GetOAuth2ApplicationByID(ctx, grant.ApplicationID) - if err == nil && app != nil { - response.Active = true - response.Scope = grant.Scope - response.Issuer = setting.AppURL - response.Audience = []string{app.ClientID} - response.Subject = fmt.Sprint(grant.UserID) - } + grant, err := auth.GetOAuth2GrantByID(ctx, token.GrantID) + if err == nil && grant != nil { + app, err := auth.GetOAuth2ApplicationByID(ctx, grant.ApplicationID) + if err == nil && app != nil { + response.Active = true + response.Scope = grant.Scope + response.Issuer = setting.AppURL + response.Audience = []string{app.ClientID} + response.Subject = fmt.Sprint(grant.UserID) } } } diff --git a/routers/web/auth/oauth_test.go b/routers/web/auth/oauth_test.go index adf933fd239bf..4339d9d1ebae8 100644 --- a/routers/web/auth/oauth_test.go +++ b/routers/web/auth/oauth_test.go @@ -13,7 +13,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/services/auth/source/oauth2" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" "github.com/stretchr/testify/assert" ) diff --git a/services/auth/source/oauth2/jwtsigningkey.go b/services/auth/source/oauth2/jwtsigningkey.go index 33bd3648e717f..ff0d426e2239c 100644 --- a/services/auth/source/oauth2/jwtsigningkey.go +++ b/services/auth/source/oauth2/jwtsigningkey.go @@ -22,7 +22,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" ) // ErrInvalidAlgorithmType represents an invalid algorithm error. diff --git a/services/auth/source/oauth2/token.go b/services/auth/source/oauth2/token.go index 612c9db8cf5f0..3405619d3fa59 100644 --- a/services/auth/source/oauth2/token.go +++ b/services/auth/source/oauth2/token.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/modules/timeutil" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" ) // ___________ __ @@ -50,6 +50,9 @@ func ParseToken(jwtToken string, signingKey JWTSigningKey) (*Token, error) { if err != nil { return nil, err } + if !parsedToken.Valid { + return nil, fmt.Errorf("invalid token") + } var token *Token var ok bool if token, ok = parsedToken.Claims.(*Token); !ok || !parsedToken.Valid { diff --git a/services/lfs/server.go b/services/lfs/server.go index cc0ec73105bd7..58b4663345ca6 100644 --- a/services/lfs/server.go +++ b/services/lfs/server.go @@ -32,7 +32,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/storage" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" "github.com/minio/sha256-simd" ) diff --git a/services/packages/auth.go b/services/packages/auth.go index 41d3a0a82511e..2f78b26f506e2 100644 --- a/services/packages/auth.go +++ b/services/packages/auth.go @@ -13,7 +13,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "github.com/golang-jwt/jwt/v4" + "github.com/golang-jwt/jwt/v5" ) type packageClaims struct { From 374c7c16518723f85fe2da790f4a8e12b38fe19a Mon Sep 17 00:00:00 2001 From: harryzcy Date: Wed, 19 Jul 2023 01:09:54 -0500 Subject: [PATCH 2/3] Bump github.com/go-webauthn/webauthn since it uses jwt v5 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 44a99a5244b68..2b784674d08c3 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/go-sql-driver/mysql v1.7.1 github.com/go-swagger/go-swagger v0.30.5 github.com/go-testfixtures/testfixtures/v3 v3.9.0 - github.com/go-webauthn/webauthn v0.8.4 + github.com/go-webauthn/webauthn v0.8.6 github.com/gobwas/glob v0.2.3 github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 diff --git a/go.sum b/go.sum index b01fb2df87993..8018ceb027ab0 100644 --- a/go.sum +++ b/go.sum @@ -455,8 +455,8 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78 github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= github.com/go-testfixtures/testfixtures/v3 v3.9.0 h1:938g5V+GWLVejm3Hc+nWCuEXRlcglZDDlN/t1gWzcSY= github.com/go-testfixtures/testfixtures/v3 v3.9.0/go.mod h1:cdsKD2ApFBjdog9jRsz6EJqF+LClq/hrwE9K/1Dzo4s= -github.com/go-webauthn/webauthn v0.8.4 h1:/emQ9b9Rj4flWO94Fo8KJeYvZ6VzPywXsmqyDA/WicY= -github.com/go-webauthn/webauthn v0.8.4/go.mod h1:ZqEa9OnSCdQf6CJvTWTDCsUcPRi8F3h7XCIDINwbBgI= +github.com/go-webauthn/webauthn v0.8.6 h1:bKMtL1qzd2WTFkf1mFTVbreYrwn7dsYmEPjTq6QN90E= +github.com/go-webauthn/webauthn v0.8.6/go.mod h1:emwVLMCI5yx9evTTvr0r+aOZCdWJqMfbRhF0MufyUog= github.com/go-webauthn/x v0.1.4 h1:sGmIFhcY70l6k7JIDfnjVBiAAFEssga5lXIUXe0GtAs= github.com/go-webauthn/x v0.1.4/go.mod h1:75Ug0oK6KYpANh5hDOanfDI+dvPWHk788naJVG/37H8= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= From 5eec5640b48b3acac9ae2a63342885192f9a3463 Mon Sep 17 00:00:00 2001 From: harryzcy Date: Wed, 19 Jul 2023 01:17:35 -0500 Subject: [PATCH 3/3] Run `make tidy` --- assets/go-licenses.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/assets/go-licenses.json b/assets/go-licenses.json index bd541e7e904b8..87f13ad9d58f0 100644 --- a/assets/go-licenses.json +++ b/assets/go-licenses.json @@ -499,6 +499,11 @@ "path": "github.com/golang-jwt/jwt/v4/LICENSE", "licenseText": "Copyright (c) 2012 Dave Grijalva\nCopyright (c) 2021 golang-jwt maintainers\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n" }, + { + "name": "github.com/golang-jwt/jwt/v5", + "path": "github.com/golang-jwt/jwt/v5/LICENSE", + "licenseText": "Copyright (c) 2012 Dave Grijalva\nCopyright (c) 2021 golang-jwt maintainers\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n" + }, { "name": "github.com/golang-sql/civil", "path": "github.com/golang-sql/civil/LICENSE",