Cross site scripting in Grafana proxy
Description
Grafana is an open-source platform for monitoring and observability. In affected versions an attacker could serve HTML content thru the Grafana datasource or plugin proxy and trick a user to visit this HTML page using a specially crafted link and execute a Cross-site Scripting (XSS) attack. The attacker could either compromise an existing datasource for a specific Grafana instance or either set up its own public service and instruct anyone to set it up in their Grafana instance. To be impacted, all of the following must be applicable. For the data source proxy: A Grafana HTTP-based datasource configured with Server as Access Mode and a URL set, the attacker has to be in control of the HTTP server serving the URL of above datasource, and a specially crafted link pointing at the attacker controlled data source must be clicked on by an authenticated user. For the plugin proxy: A Grafana HTTP-based app plugin configured and enabled with a URL set, the attacker has to be in control of the HTTP server serving the URL of above app, and a specially crafted link pointing at the attacker controlled plugin must be clocked on by an authenticated user. For the backend plugin resource: An attacker must be able to navigate an authenticated user to a compromised plugin through a crafted link. Users are advised to update to a patched version. There are no known workarounds for this vulnerability.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
github.com/grafana/grafanaGo | >= 2.0.0-beta1, < 7.5.15 | 7.5.15 |
github.com/grafana/grafanaGo | >= 8.0.0, < 8.3.5 | 8.3.5 |
Affected products
1Patches
127726868b3d7[v7.5.x] Fix for CVE-2022-21702 (#226)
7 files changed · +79 −2
pkg/api/pluginproxy/ds_proxy.go+1 −0 modified@@ -49,6 +49,7 @@ func (t *handleResponseTransport) RoundTrip(req *http.Request) (*http.Response, return nil, err } res.Header.Del("Set-Cookie") + proxyutil.SetProxyResponseHeaders(res.Header) return res, nil }
pkg/api/pluginproxy/ds_proxy_test.go+12 −0 modified@@ -605,6 +605,18 @@ func TestDataSourceProxy_requestHandling(t *testing.T) { assert.Equal(t, "important_cookie=important_value", proxy.ctx.Resp.Header().Get("Set-Cookie")) }) + t.Run("When response should set Content-Security-Policy header", func(t *testing.T) { + ctx, ds := setUp(t) + dsPlugin := &plugins.DataSourcePlugin{} + proxy, err := NewDataSourceProxy(ds, dsPlugin, ctx, "/render", &setting.Cfg{}) + require.NoError(t, err) + + proxy.HandleRequest() + + require.NoError(t, writeErr) + assert.Equal(t, "sandbox", proxy.ctx.Resp.Header().Get("Content-Security-Policy")) + }) + t.Run("Data source returns status code 401", func(t *testing.T) { ctx, ds := setUp(t, setUpCfg{ writeCb: func(w http.ResponseWriter, r *http.Request) {
pkg/api/pluginproxy/pluginproxy.go+7 −1 modified@@ -71,5 +71,11 @@ func NewApiPluginProxy(ctx *models.ReqContext, proxyPath string, route *plugins. } } - return &httputil.ReverseProxy{Director: director} + return &httputil.ReverseProxy{Director: director, ModifyResponse: modifyResponse} +} + +func modifyResponse(resp *http.Response) error { + proxyutil.SetProxyResponseHeaders(resp.Header) + + return nil }
pkg/api/pluginproxy/pluginproxy_test.go+44 −0 modified@@ -2,6 +2,7 @@ package pluginproxy import ( "net/http" + "net/http/httptest" "testing" "github.com/grafana/grafana/pkg/bus" @@ -11,6 +12,7 @@ import ( "github.com/grafana/grafana/pkg/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + macaron "gopkg.in/macaron.v1" ) func TestPluginProxy(t *testing.T) { @@ -148,6 +150,48 @@ func TestPluginProxy(t *testing.T) { ) assert.Equal(t, "https://example.com", req.URL.String()) }) + + t.Run("When proxying a request should set expected response headers", func(t *testing.T) { + requestHandled := false + backendServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(200) + _, _ = w.Write([]byte("I am the backend")) + requestHandled = true + })) + + responseRecorder := &closeNotifierResponseRecorder{ + ResponseRecorder: httptest.NewRecorder(), + } + responseWriter := macaron.NewResponseWriter("GET", responseRecorder) + + t.Cleanup(responseRecorder.Close) + t.Cleanup(backendServer.Close) + + route := &plugins.AppPluginRoute{ + Path: "/", + URL: backendServer.URL, + } + + ctx := &models.ReqContext{ + SignedInUser: &models.SignedInUser{}, + Context: &macaron.Context{ + Req: macaron.Request{ + Request: httptest.NewRequest("GET", "/", nil), + }, + Resp: responseWriter, + }, + } + proxy := NewApiPluginProxy(ctx, "", route, "", &setting.Cfg{}) + proxy.ServeHTTP(ctx.Resp, ctx.Req.Request) + + for { + if requestHandled { + break + } + } + + require.Equal(t, "sandbox", ctx.Resp.Header().Get("Content-Security-Policy")) + }) } // getPluginProxiedRequest is a helper for easier setup of tests based on global config and ReqContext.
pkg/plugins/backendplugin/manager.go+1 −0 modified@@ -406,6 +406,7 @@ func flushStream(plugin Plugin, stream CallResourceClientResponseStream, w http. } } + proxyutil.SetProxyResponseHeaders(w.Header()) w.WriteHeader(resp.Status) }
pkg/plugins/backendplugin/manager_test.go+8 −1 modified@@ -177,7 +177,8 @@ func TestManager(t *testing.T) { t.Run("Call resource should return expected response", func(t *testing.T) { ctx.plugin.CallResourceHandlerFunc = backend.CallResourceHandlerFunc(func(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error { return sender.Send(&backend.CallResourceResponse{ - Status: http.StatusOK, + Status: http.StatusOK, + Headers: map[string][]string{}, }) }) @@ -186,7 +187,13 @@ func TestManager(t *testing.T) { w := httptest.NewRecorder() err = ctx.manager.callResourceInternal(w, req, backend.PluginContext{PluginID: testPluginID}) require.NoError(t, err) + for { + if w.Flushed { + break + } + } require.Equal(t, http.StatusOK, w.Code) + require.Equal(t, "sandbox", w.Header().Get("Content-Security-Policy")) }) }) })
pkg/util/proxyutil/proxyutil.go+6 −0 modified@@ -42,3 +42,9 @@ func ClearCookieHeader(req *http.Request, keepCookiesNames []string) { req.AddCookie(c) } } + +// SetProxyResponseHeaders sets proxy response headers. +// Sets Content-Security-Policy: sandbox +func SetProxyResponseHeaders(header http.Header) { + header.Set("Content-Security-Policy", "sandbox") +}
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
14- github.com/advisories/GHSA-xc3p-28hw-q24gghsaADVISORY
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/2PFW6Q2LXXWTFRTMTRN4ZGADFRQPKJ3D/mitrevendor-advisoryx_refsource_FEDORA
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/36GUEPA5TPSC57DZTPYPBL6T7UPQ2FRH/mitrevendor-advisoryx_refsource_FEDORA
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/HLAQRRGNSO5MYCPAXGPH2OCSHOGHSQMQ/mitrevendor-advisoryx_refsource_FEDORA
- nvd.nist.gov/vuln/detail/CVE-2022-21702ghsaADVISORY
- github.com/grafana/grafana/commit/27726868b3d7c613844b55cd209ca93645c99b85ghsax_refsource_MISCWEB
- github.com/grafana/grafana/security/advisories/GHSA-xc3p-28hw-q24gghsax_refsource_CONFIRMWEB
- grafana.com/blog/2022/02/08/grafana-7.5.15-and-8.3.5-released-with-moderate-severity-security-fixesghsaWEB
- grafana.com/blog/2022/02/08/grafana-7.5.15-and-8.3.5-released-with-moderate-severity-security-fixes/mitrex_refsource_MISC
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/2PFW6Q2LXXWTFRTMTRN4ZGADFRQPKJ3DghsaWEB
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/36GUEPA5TPSC57DZTPYPBL6T7UPQ2FRHghsaWEB
- lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/HLAQRRGNSO5MYCPAXGPH2OCSHOGHSQMQghsaWEB
- security.netapp.com/advisory/ntap-20220303-0005ghsaWEB
- security.netapp.com/advisory/ntap-20220303-0005/mitrex_refsource_CONFIRM
News mentions
0No linked articles in our index yet.