Skip to content

Commit d946edf

Browse files
troyanovbrian-brazil
authored andcommitted
Fix: Strict mode to enforce FQDN (#65)
* Fix: Strict mode to enforce FQDN Go docs: https://golang.org/pkg/net/url/#Parse > Trying to parse a hostname and path without a scheme is invalid but may not necessarily return an error, due to parsing ambiguities. ``` fqdnURL, err := url.Parse(*myFqdn) if err != nil { c.handleErr(request, client, err) return } ``` Example: myFqdn was set to `b607b847b180`, scheme is missing, but no error (as mentioned in the docs). We don't need to treat myFqdn as URL since it is not an URL but rather FQDN (which is schemaless)
1 parent c710c40 commit d946edf

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

client/client.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,7 @@ func (c *Coordinator) doScrape(request *http.Request, client *http.Client) {
104104
request.URL.RawQuery = params.Encode()
105105
}
106106

107-
fqdnURL, err := url.Parse(*myFqdn)
108-
if err != nil {
109-
c.handleErr(request, client, err)
110-
return
111-
}
112-
if request.URL.Hostname() != fqdnURL.Hostname() {
107+
if request.URL.Hostname() != *myFqdn {
113108
c.handleErr(request, client, errors.New("scrape target doesn't match client fqdn"))
114109
return
115110
}
@@ -225,6 +220,7 @@ func main() {
225220
kingpin.Parse()
226221
logger := promlog.New(&promlogConfig)
227222
coordinator := Coordinator{logger: logger}
223+
228224
if *proxyURL == "" {
229225
level.Error(coordinator.logger).Log("msg", "--proxy-url flag must be specified.")
230226
os.Exit(1)

0 commit comments

Comments
 (0)