Skip to content

Commit

Permalink
Fix: Strict mode to enforce FQDN (#65)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
troyanov authored and brian-brazil committed Nov 25, 2019
1 parent c710c40 commit d946edf
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ func (c *Coordinator) doScrape(request *http.Request, client *http.Client) {
request.URL.RawQuery = params.Encode()
}

fqdnURL, err := url.Parse(*myFqdn)
if err != nil {
c.handleErr(request, client, err)
return
}
if request.URL.Hostname() != fqdnURL.Hostname() {
if request.URL.Hostname() != *myFqdn {
c.handleErr(request, client, errors.New("scrape target doesn't match client fqdn"))
return
}
Expand Down Expand Up @@ -225,6 +220,7 @@ func main() {
kingpin.Parse()
logger := promlog.New(&promlogConfig)
coordinator := Coordinator{logger: logger}

if *proxyURL == "" {
level.Error(coordinator.logger).Log("msg", "--proxy-url flag must be specified.")
os.Exit(1)
Expand Down

0 comments on commit d946edf

Please sign in to comment.