Commit cf7a4997 by Robin Gustafsson Committed by Daniel Lee

proxyds: delete cookies except those listed in keepCookies

parent bcc85862
......@@ -135,9 +135,24 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
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("Set-Cookie")
for _, c := range keptCookies {
req.AddCookie(c)
}
// clear X-Forwarded Host/Port/Proto headers
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() {
plugin := &plugins.DataSourcePlugin{}
json := simplejson.New()
json.Set("keepCookies", []string{})
json, _ := simplejson.NewJson([]byte(`{"keepCookies": []}`))
ds := &m.DataSource{
Type: m.DS_GRAPHITE,
......@@ -179,8 +178,7 @@ func TestDSRouteRule(t *testing.T) {
Convey("When proxying a data source with keep cookies specified", func() {
plugin := &plugins.DataSourcePlugin{}
json := simplejson.New()
json.Set("keepCookies", []string{"JSESSION_ID"})
json, _ := simplejson.NewJson([]byte(`{"keepCookies": ["JSESSION_ID"]}`))
ds := &m.DataSource{
Type: m.DS_GRAPHITE,
......@@ -199,7 +197,7 @@ func TestDSRouteRule(t *testing.T) {
proxy.getDirector()(&req)
Convey("Should keep named cookies", func() {
So(req.Header.Get("Cookie"), ShouldEqual, "JSESSION=test")
So(req.Header.Get("Cookie"), ShouldEqual, "JSESSION_ID=test")
})
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment