[MM-61079] Fix error checking in webhook.go (#30611)
* MM-28751 Fix error checking in webhook.go - Implement proper error checking for r.ParseForm() - Implement proper error checking for r.ParseMultipartForm() - Implement proper error checking for w.Write() - Remove webhook.go exception from .golangci.yml 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix translation --------- Co-authored-by: Claude <noreply@anthropic.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2e2782e4bf
Коммит
545de88486
@@ -165,7 +165,6 @@ issues:
|
||||
channels/web/oauth_test.go|\
|
||||
channels/web/saml.go|\
|
||||
channels/web/web_test.go|\
|
||||
channels/web/webhook.go|\
|
||||
cmd/mattermost/commands/cmdtestlib.go|\
|
||||
cmd/mattermost/commands/db.go|\
|
||||
cmd/mattermost/commands/export.go|\
|
||||
|
||||
@@ -27,7 +27,11 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
id := params["id"]
|
||||
errCtx := map[string]any{"hook_id": id}
|
||||
|
||||
r.ParseForm()
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("incomingWebhook", "web.incoming_webhook.parse_form.app_error", errCtx, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
var appErr *model.AppError
|
||||
var mediaType string
|
||||
@@ -69,7 +73,10 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
} else if mediaType == "multipart/form-data" {
|
||||
r.ParseMultipartForm(0)
|
||||
if err := r.ParseMultipartForm(0); err != nil {
|
||||
c.Err = model.NewAppError("incomingWebhook", "web.incoming_webhook.parse_multipart.app_error", errCtx, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
decoder := schema.NewDecoder()
|
||||
err := decoder.Decode(incomingWebhookPayload, r.PostForm)
|
||||
@@ -93,7 +100,10 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write([]byte("ok"))
|
||||
if _, err := w.Write([]byte("ok")); err != nil {
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func commandWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -114,7 +124,10 @@ func commandWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write([]byte("ok"))
|
||||
if _, err := w.Write([]byte("ok")); err != nil {
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func decodePayload(payload io.Reader) (*model.IncomingWebhookRequest, *model.AppError) {
|
||||
|
||||
@@ -10544,6 +10544,14 @@
|
||||
"id": "web.incoming_webhook.parse.app_error",
|
||||
"translation": "Unable to parse incoming data."
|
||||
},
|
||||
{
|
||||
"id": "web.incoming_webhook.parse_form.app_error",
|
||||
"translation": "Failed to parse form for webhook {{.hook_id}}."
|
||||
},
|
||||
{
|
||||
"id": "web.incoming_webhook.parse_multipart.app_error",
|
||||
"translation": "Failed to parse multipart form for webhook {{.hook_id}}."
|
||||
},
|
||||
{
|
||||
"id": "web.incoming_webhook.permissions.app_error",
|
||||
"translation": "User {{.user}} does not have appropriate permissions to channel {{.channel}}"
|
||||
|
||||
Ссылка в новой задаче
Block a user