From 730dc6b98569c072aaee9324e58e790973690d2d Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Mon, 19 Apr 2021 14:02:00 +0200 Subject: [PATCH] [MM-34919] Use Mattermost-Plugin-ID header to pass ID in inter-plugin requests (#17418) --- app/plugin_api_test.go | 4 ++++ app/plugin_requests.go | 5 +++++ plugin/context.go | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/plugin_api_test.go b/app/plugin_api_test.go index 5dfdb68002..70bf95b230 100644 --- a/app/plugin_api_test.go +++ b/app/plugin_api_test.go @@ -1404,6 +1404,10 @@ func TestInterpluginPluginHTTP(t *testing.T) { return } + if r.Header.Get("Mattermost-Plugin-ID") != "testplugininterclient" { + return + } + buf := bytes.Buffer{} buf.ReadFrom(r.Body) resp := "we got:" + buf.String() diff --git a/app/plugin_requests.go b/app/plugin_requests.go index 67775c5309..d0132fcb72 100644 --- a/app/plugin_requests.go +++ b/app/plugin_requests.go @@ -74,6 +74,8 @@ func (a *App) ServeInterPluginRequest(w http.ResponseWriter, r *http.Request, so SourcePluginId: sourcePluginId, } + r.Header.Set("Mattermost-Plugin-ID", sourcePluginId) + hooks.ServeHTTP(context, w, r) } @@ -135,6 +137,9 @@ func (a *App) servePluginRequest(w http.ResponseWriter, r *http.Request, handler token = r.URL.Query().Get("access_token") } + // Mattermost-Plugin-ID can only be set by inter-plugin requests + r.Header.Del("Mattermost-Plugin-ID") + r.Header.Del("Mattermost-User-Id") if token != "" { session, err := a.GetSession(token) diff --git a/plugin/context.go b/plugin/context.go index 98e786e8c5..d8fa94f645 100644 --- a/plugin/context.go +++ b/plugin/context.go @@ -12,5 +12,5 @@ type Context struct { IpAddress string AcceptLanguage string UserAgent string - SourcePluginId string + SourcePluginId string // Deprecated: Use the "Mattermost-Plugin-ID" HTTP header instead }