From e07761eb33b74baaf728a3eccb137eaf1ae0ccf8 Mon Sep 17 00:00:00 2001 From: Shraddha Agrawal Date: Thu, 23 Apr 2020 08:40:24 +0530 Subject: [PATCH] cli: validate endpoint using ParseRequestURI (fix #4407) (#4416) --- cli/cli.go | 2 +- cli/commands/init.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/cli.go b/cli/cli.go index 8e317223763..70c7c4335b1 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -161,7 +161,7 @@ func (s *ServerConfig) GetVersionEndpoint() string { // ParseEndpoint ensures the endpoint is valid. func (s *ServerConfig) ParseEndpoint() error { - nurl, err := url.Parse(s.Endpoint) + nurl, err := url.ParseRequestURI(s.Endpoint) if err != nil { return err } diff --git a/cli/commands/init.go b/cli/commands/init.go index e155af340c4..24080604c85 100644 --- a/cli/commands/init.go +++ b/cli/commands/init.go @@ -2,6 +2,7 @@ package commands import ( "fmt" + "net/url" "os" "path/filepath" "strings" @@ -183,6 +184,9 @@ func (o *InitOptions) createFiles() error { } } if o.Endpoint != "" { + if _, err := url.ParseRequestURI(o.Endpoint); err != nil { + return errors.Wrap(err, "error validating endpoint URL") + } config.ServerConfig.Endpoint = o.Endpoint } if o.AdminSecret != "" {