IP range AC for data sources: compare the base of the URL only (#83305)
* compare the base of the URL and ignore the path * change the logic to compare scheme and host explicitly * fix the test
This commit is contained in:
+10
-5
@@ -5,7 +5,7 @@ import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"path"
|
||||
"net/url"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
@@ -49,17 +49,22 @@ func (m *HostedGrafanaACHeaderMiddleware) applyGrafanaRequestIDHeader(ctx contex
|
||||
}
|
||||
|
||||
// Check if the request is for a datasource that is allowed to have the header
|
||||
target := pCtx.DataSourceInstanceSettings.URL
|
||||
|
||||
dsURL := pCtx.DataSourceInstanceSettings.URL
|
||||
dsBaseURL, err := url.Parse(dsURL)
|
||||
if err != nil {
|
||||
m.log.Debug("Failed to parse data source URL", "error", err)
|
||||
return
|
||||
}
|
||||
foundMatch := false
|
||||
for _, allowedURL := range m.cfg.IPRangeACAllowedURLs {
|
||||
if path.Clean(allowedURL) == path.Clean(target) {
|
||||
// Only look at the scheme and host, ignore the path
|
||||
if allowedURL.Host == dsBaseURL.Host && allowedURL.Scheme == dsBaseURL.Scheme {
|
||||
foundMatch = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundMatch {
|
||||
m.log.Debug("Data source URL not among the allow-listed URLs", "url", target)
|
||||
m.log.Debug("Data source URL not among the allow-listed URLs", "url", dsBaseURL.String())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user