From 56a0b255af916c867abeaf35f866886eb10ec79e Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 31 Oct 2022 15:36:45 -0400 Subject: [PATCH] better URL validation (#83) --- cmd/zrok/http_backend.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/zrok/http_backend.go b/cmd/zrok/http_backend.go index 4d6c2f8b..e613b814 100644 --- a/cmd/zrok/http_backend.go +++ b/cmd/zrok/http_backend.go @@ -16,6 +16,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "net/url" "os" "os/signal" "strings" @@ -48,6 +49,17 @@ func newHttpBackendCommand() *httpBackendCommand { } func (self *httpBackendCommand) run(_ *cobra.Command, args []string) { + targetEndpoint, err := url.Parse(args[0]) + if err != nil { + if !panicInstead { + showError("invalid target endpoint URL", err) + } + panic(err) + } + if targetEndpoint.Scheme == "" { + targetEndpoint.Scheme = "https" + } + if !self.quiet { if err := ui.Init(); err != nil { if !panicInstead { @@ -77,7 +89,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) { } cfg := &backend.Config{ IdentityPath: zif, - EndpointAddress: args[0], + EndpointAddress: targetEndpoint.String(), } zrok, err := zrokdir.ZrokClient(env.ApiEndpoint)