Fix to check white list when the frontend tries to connect DB

This commit is contained in:
Nozomi Anzai 2016-08-17 14:33:59 +09:00
parent bdf68b2183
commit 157435a61c

View File

@ -91,21 +91,24 @@ func ProxyDataSourceRequest(c *middleware.Context) {
return return
} }
targetUrl, _ := url.Parse(ds.Url) switch ds.Type {
if len(setting.DataProxyWhiteList) > 0 { case m.DS_CLOUDWATCH:
if _, exists := setting.DataProxyWhiteList[targetUrl.Host]; !exists {
c.JsonApiErr(403, "Data proxy hostname and ip are not included in whitelist", nil)
return
}
}
if ds.Type == m.DS_CLOUDWATCH {
cloudwatch.HandleRequest(c, ds) cloudwatch.HandleRequest(c, ds)
} else if ds.Type == m.DS_SQLDB { case m.DS_SQLDB:
host, _ := ds.JsonData.Get("host").String()
if !checkWhiteList(c, host) {
return
}
sqldb.HandleRequest(c, ds) sqldb.HandleRequest(c, ds)
} else { default:
targetUrl, _ := url.Parse(ds.Url)
if !checkWhiteList(c, targetUrl.Host) {
return
}
proxyPath := c.Params("*") proxyPath := c.Params("*")
proxy := NewReverseProxy(ds, proxyPath, targetUrl) proxy := NewReverseProxy(ds, proxyPath, targetUrl)
proxy.Transport = dataProxyTransport proxy.Transport = dataProxyTransport
@ -113,3 +116,14 @@ func ProxyDataSourceRequest(c *middleware.Context) {
c.Resp.Header().Del("Set-Cookie") c.Resp.Header().Del("Set-Cookie")
} }
} }
func checkWhiteList(c *middleware.Context, host string) bool {
if host != "" && len(setting.DataProxyWhiteList) > 0 {
if _, exists := setting.DataProxyWhiteList[host]; !exists {
c.JsonApiErr(403, "Data proxy hostname and ip are not included in whitelist", nil)
return false
}
}
return true
}