Skip to content

Commit

Permalink
Harden the IsURL check
Browse files Browse the repository at this point in the history
The IsURL check simply called url.ParseRequestURI and relied on whether it errors
or not to detect whether the given string is a url or not. Turns out that
url.ParseRequestURI does not error out if the given string is a complete
filesystem path /path/to/file.

This commit hardens the IsURL check. It checks whether the returned URL object
by url.ParseRequestURI() has an actual Host component or not. If not, isURL returns
false.

Refs argoproj#509.
  • Loading branch information
Shri Javadekar authored and shrinandj committed Dec 1, 2017
1 parent bfa62af commit eed54f5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions util/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ func MustHomeDir() string {

// IsURL returns whether or not a string is a URL
func IsURL(u string) bool {
_, err := url.ParseRequestURI(u)
return err == nil
var parsedURL *url.URL
var err error

parsedURL, err = url.ParseRequestURI(u)
if err == nil {
if parsedURL != nil && parsedURL.Host != "" {
return true
}
}
return false
}

0 comments on commit eed54f5

Please sign in to comment.