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:
Ieva
2024-02-23 18:13:21 +02:00
committed by GitHub
parent 65534e62a6
commit 19b1e71fee
3 changed files with 33 additions and 15 deletions
+10 -2
View File
@@ -339,7 +339,7 @@ type Cfg struct {
// IP range access control
IPRangeACEnabled bool
IPRangeACAllowedURLs []string
IPRangeACAllowedURLs []*url.URL
IPRangeACSecretKey string
// SQL Data sources
@@ -1949,7 +1949,15 @@ func (cfg *Cfg) readDataSourceSecuritySettings() {
cfg.IPRangeACEnabled = datasources.Key("enabled").MustBool(false)
cfg.IPRangeACSecretKey = datasources.Key("secret_key").MustString("")
allowedURLString := datasources.Key("allow_list").MustString("")
cfg.IPRangeACAllowedURLs = util.SplitString(allowedURLString)
for _, urlString := range util.SplitString(allowedURLString) {
allowedURL, err := url.Parse(urlString)
if err != nil {
cfg.Logger.Error("Error parsing allowed URL for IP range access control", "error", err)
continue
} else {
cfg.IPRangeACAllowedURLs = append(cfg.IPRangeACAllowedURLs, allowedURL)
}
}
}
func (cfg *Cfg) readSqlDataSourceSettings() {