mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
proxyds: delete cookies except those listed in keepCookies
This commit is contained in:
committed by
Daniel Lee
parent
bcc85862fe
commit
cf7a49977f
@@ -135,9 +135,24 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
|
|||||||
req.Header.Add("Authorization", dsAuth)
|
req.Header.Add("Authorization", dsAuth)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear cookie headers
|
// clear cookie header, except for whitelisted cookies
|
||||||
|
var keptCookies []*http.Cookie
|
||||||
|
if proxy.ds.JsonData != nil {
|
||||||
|
if keepCookies := proxy.ds.JsonData.Get("keepCookies"); keepCookies != nil {
|
||||||
|
keepCookieNames := keepCookies.MustStringArray()
|
||||||
|
for _, c := range req.Cookies() {
|
||||||
|
for _, v := range keepCookieNames {
|
||||||
|
if c.Name == v {
|
||||||
|
keptCookies = append(keptCookies, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
req.Header.Del("Cookie")
|
req.Header.Del("Cookie")
|
||||||
req.Header.Del("Set-Cookie")
|
for _, c := range keptCookies {
|
||||||
|
req.AddCookie(c)
|
||||||
|
}
|
||||||
|
|
||||||
// clear X-Forwarded Host/Port/Proto headers
|
// clear X-Forwarded Host/Port/Proto headers
|
||||||
req.Header.Del("X-Forwarded-Host")
|
req.Header.Del("X-Forwarded-Host")
|
||||||
|
|||||||
@@ -152,8 +152,7 @@ func TestDSRouteRule(t *testing.T) {
|
|||||||
Convey("When proxying a data source with no keepCookies specified", func() {
|
Convey("When proxying a data source with no keepCookies specified", func() {
|
||||||
plugin := &plugins.DataSourcePlugin{}
|
plugin := &plugins.DataSourcePlugin{}
|
||||||
|
|
||||||
json := simplejson.New()
|
json, _ := simplejson.NewJson([]byte(`{"keepCookies": []}`))
|
||||||
json.Set("keepCookies", []string{})
|
|
||||||
|
|
||||||
ds := &m.DataSource{
|
ds := &m.DataSource{
|
||||||
Type: m.DS_GRAPHITE,
|
Type: m.DS_GRAPHITE,
|
||||||
@@ -179,8 +178,7 @@ func TestDSRouteRule(t *testing.T) {
|
|||||||
Convey("When proxying a data source with keep cookies specified", func() {
|
Convey("When proxying a data source with keep cookies specified", func() {
|
||||||
plugin := &plugins.DataSourcePlugin{}
|
plugin := &plugins.DataSourcePlugin{}
|
||||||
|
|
||||||
json := simplejson.New()
|
json, _ := simplejson.NewJson([]byte(`{"keepCookies": ["JSESSION_ID"]}`))
|
||||||
json.Set("keepCookies", []string{"JSESSION_ID"})
|
|
||||||
|
|
||||||
ds := &m.DataSource{
|
ds := &m.DataSource{
|
||||||
Type: m.DS_GRAPHITE,
|
Type: m.DS_GRAPHITE,
|
||||||
@@ -199,7 +197,7 @@ func TestDSRouteRule(t *testing.T) {
|
|||||||
proxy.getDirector()(&req)
|
proxy.getDirector()(&req)
|
||||||
|
|
||||||
Convey("Should keep named cookies", func() {
|
Convey("Should keep named cookies", func() {
|
||||||
So(req.Header.Get("Cookie"), ShouldEqual, "JSESSION=test")
|
So(req.Header.Get("Cookie"), ShouldEqual, "JSESSION_ID=test")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user