diff --git a/server/.golangci.yml b/server/.golangci.yml index 7d3fa2f05a..811a765aef 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -190,7 +190,6 @@ issues: channels/utils/license_test.go|\ channels/web/oauth_test.go|\ channels/web/saml.go|\ - channels/web/static.go|\ channels/web/web_test.go|\ channels/web/webhook.go|\ cmd/mattermost/commands/cmdtestlib.go|\ diff --git a/server/channels/web/static.go b/server/channels/web/static.go index 91cbae42af..b1fbde369a 100644 --- a/server/channels/web/static.go +++ b/server/channels/web/static.go @@ -64,7 +64,12 @@ func root(c *Context, w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "no-store") data := renderUnsupportedBrowser(c.AppContext, r) - c.App.Srv().TemplatesContainer().Render(w, "unsupported_browser", data) + err := c.App.Srv().TemplatesContainer().Render(w, "unsupported_browser", data) + if err != nil { + c.Logger.Error("Failed to render template", mlog.Err(err)) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } return } @@ -78,7 +83,10 @@ func root(c *Context, w http.ResponseWriter, r *http.Request) { staticDir, _ := fileutils.FindDir(model.ClientDir) contents, err := os.ReadFile(filepath.Join(staticDir, "root.html")) if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) + c.Logger.Warn("Failed to read content from file", + mlog.String("file_path", filepath.Join(staticDir, "root.html")), + mlog.Err(err)) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -90,7 +98,11 @@ func root(c *Context, w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "text/html") - w.Write(contents) + if _, err = w.Write(contents); err != nil { + c.Logger.Warn("Failed to write content to HTTP reply", mlog.Err(err)) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } func staticFilesHandler(handler http.Handler) http.Handler { @@ -135,7 +147,11 @@ func robotsHandler(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - w.Write(robotsTxt) + if _, err := w.Write(robotsTxt); err != nil { + mlog.Warn("Failed to write robots.txt", mlog.Err(err)) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } func unsupportedBrowserScriptHandler(w http.ResponseWriter, r *http.Request) {