DataSourceProxy: Handle URL parsing error (#23731)
* pluginproxy: Handle URL parsing error * pkg/api: Validate data source URLs * pkg/api: Return 400 for URL validation error
This commit is contained in:
+12
-1
@@ -1,6 +1,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/pluginproxy"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
@@ -32,7 +35,15 @@ func (hs *HTTPServer) ProxyDataSourceRequest(c *models.ReqContext) {
|
||||
// macaron does not include trailing slashes when resolving a wildcard path
|
||||
proxyPath := ensureProxyPathTrailingSlash(c.Req.URL.Path, c.Params("*"))
|
||||
|
||||
proxy := pluginproxy.NewDataSourceProxy(ds, plugin, c, proxyPath, hs.Cfg)
|
||||
proxy, err := pluginproxy.NewDataSourceProxy(ds, plugin, c, proxyPath, hs.Cfg)
|
||||
if err != nil {
|
||||
if errors.Is(err, pluginproxy.URLValidationError{}) {
|
||||
c.JsonApiErr(400, fmt.Sprintf("Invalid data source URL: %q", ds.Url), err)
|
||||
} else {
|
||||
c.JsonApiErr(500, "Failed creating data source proxy", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
proxy.HandleRequest()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user