From be7a8a17c0a4096e9c4ecd48c5faddc3b4b2cabb Mon Sep 17 00:00:00 2001 From: TheInvincible <139259364+TheInvincibleRalph@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:07:04 +0100 Subject: [PATCH] Fix errcheck issue in oauth.go (#28795) --- server/.golangci.yml | 1 - server/channels/web/oauth.go | 10 ++++++++-- server/i18n/en.json | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/server/.golangci.yml b/server/.golangci.yml index 290bcfbcbbf..2f4283c8038 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -246,7 +246,6 @@ issues: channels/store/storetest/user_store.go|\ channels/testlib/helper.go|\ channels/utils/license_test.go|\ - channels/web/oauth.go|\ channels/web/oauth_test.go|\ channels/web/saml.go|\ channels/web/static.go|\ diff --git a/server/channels/web/oauth.go b/server/channels/web/oauth.go index 100011f5207..e5f173eacd7 100644 --- a/server/channels/web/oauth.go +++ b/server/channels/web/oauth.go @@ -78,7 +78,10 @@ func authorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) { auditRec.Success() c.LogAudit("success") - w.Write([]byte(model.MapToJSON(map[string]string{"redirect": redirectURL}))) + _, err = w.Write([]byte(model.MapToJSON(map[string]string{"redirect": redirectURL}))) + if err != nil { + c.Logger.Error("Error writing response", mlog.Err(err)) + } } func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) { @@ -201,7 +204,10 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) { } func getAccessToken(c *Context, w http.ResponseWriter, r *http.Request) { - r.ParseForm() + if err := r.ParseForm(); err != nil { + c.Err = model.NewAppError("getAccessToken", "api.oauth.get_access_token.bad_request.app_error", nil, "", http.StatusBadRequest) + return + } code := r.FormValue("code") refreshToken := r.FormValue("refresh_token") diff --git a/server/i18n/en.json b/server/i18n/en.json index 3f0096496b8..d38819c53fa 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -2360,6 +2360,10 @@ "id": "api.oauth.get_access_token.bad_grant.app_error", "translation": "invalid_request: Bad grant_type." }, + { + "id": "api.oauth.get_access_token.bad_request.app_error", + "translation": "invalid_request: Bad request." + }, { "id": "api.oauth.get_access_token.credentials.app_error", "translation": "invalid_client: Invalid client credentials."