diff --git a/cmd/prometheus/config.go b/cmd/prometheus/config.go index 73f17986d2..2460e96f7a 100644 --- a/cmd/prometheus/config.go +++ b/cmd/prometheus/config.go @@ -319,6 +319,11 @@ func parse(args []string) error { return nil } +func startsOrEndsWithQuote(s string) bool { + return strings.HasPrefix(s, "\"") || strings.HasPrefix(s, "'") || + strings.HasSuffix(s, "\"") || strings.HasSuffix(s, "'") +} + func parsePrometheusURL() error { if cfg.prometheusURL == "" { hostname, err := os.Hostname() @@ -330,6 +335,8 @@ func parsePrometheusURL() error { return err } cfg.prometheusURL = fmt.Sprintf("http://%s:%s/", hostname, port) + } else if startsOrEndsWithQuote(cfg.prometheusURL) { + return fmt.Errorf("web.external-url must not begin or end with quotes") } promURL, err := url.Parse(cfg.prometheusURL) @@ -349,6 +356,8 @@ func parsePrometheusURL() error { func validateAlertmanagerURL(u string) error { if u == "" { return nil + } else if startsOrEndsWithQuote(u) { + return fmt.Errorf("alertmanager.url must not begin or end with quotes: %s", u) } url, err := url.Parse(u) if err != nil { diff --git a/cmd/prometheus/config_test.go b/cmd/prometheus/config_test.go index f26f8cbe1d..3248820d07 100644 --- a/cmd/prometheus/config_test.go +++ b/cmd/prometheus/config_test.go @@ -40,6 +40,10 @@ func TestParse(t *testing.T) { input: []string{"-web.external-url", "'https://url/prometheus'"}, valid: false, }, + { + input: []string{"-web.external-url", "'relative/path/with/quotes'"}, + valid: false, + }, { input: []string{"-alertmanager.url", ""}, valid: true, @@ -56,6 +60,14 @@ func TestParse(t *testing.T) { input: []string{"-alertmanager.url", "https://double--dash.de"}, valid: true, }, + { + input: []string{"-alertmanager.url", "'http://starts/with/quote"}, + valid: false, + }, + { + input: []string{"-alertmanager.url", "ends/with/quote\""}, + valid: false, + }, } for i, test := range tests {