diff --git a/cmd/peggo/bridge.go b/cmd/peggo/bridge.go index 0315a9bb..93610415 100644 --- a/cmd/peggo/bridge.go +++ b/cmd/peggo/bridge.go @@ -72,8 +72,19 @@ func deployGravityCmd() *cobra.Command { return err } - tmRPCEndpoint := konfig.String(flagTendermintRPC) - cosmosGRPC := konfig.String(flagCosmosGRPC) + logger, err := getLogger(cmd) + if err != nil { + return err + } + + tmRPCEndpoint, err := parseURL(logger, konfig, flagTendermintRPC) + if err != nil { + return err + } + cosmosGRPC, err := parseURL(logger, konfig, flagCosmosGRPC) + if err != nil { + return err + } tmRPC, err := rpchttp.New(tmRPCEndpoint, "/websocket") if err != nil { @@ -83,11 +94,6 @@ func deployGravityCmd() *cobra.Command { fmt.Fprintf(os.Stderr, "Connected to Tendermint RPC: %s\n", tmRPCEndpoint) clientCtx = clientCtx.WithClient(tmRPC).WithNodeURI(tmRPCEndpoint) - logger, err := getLogger(cmd) - if err != nil { - return err - } - daemonClient, err := client.NewCosmosClient(clientCtx, logger, cosmosGRPC) if err != nil { return err @@ -212,8 +218,19 @@ func deployERC20Cmd() *cobra.Command { return err } - tmRPCEndpoint := konfig.String(flagTendermintRPC) - cosmosGRPC := konfig.String(flagCosmosGRPC) + logger, err := getLogger(cmd) + if err != nil { + return err + } + + tmRPCEndpoint, err := parseURL(logger, konfig, flagTendermintRPC) + if err != nil { + return err + } + cosmosGRPC, err := parseURL(logger, konfig, flagCosmosGRPC) + if err != nil { + return err + } tmRPC, err := rpchttp.New(tmRPCEndpoint, "/websocket") if err != nil { @@ -223,11 +240,6 @@ func deployERC20Cmd() *cobra.Command { fmt.Fprintf(os.Stderr, "Connected to Tendermint RPC: %s\n", tmRPCEndpoint) clientCtx = clientCtx.WithClient(tmRPC).WithNodeURI(tmRPCEndpoint) - logger, err := getLogger(cmd) - if err != nil { - return err - } - daemonClient, err := client.NewCosmosClient(clientCtx, logger, cosmosGRPC) if err != nil { return err diff --git a/cmd/peggo/flags.go b/cmd/peggo/flags.go index c50af46d..60dbbb93 100644 --- a/cmd/peggo/flags.go +++ b/cmd/peggo/flags.go @@ -2,7 +2,12 @@ package peggo import ( + "net/url" + "strings" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/knadh/koanf" + "github.com/rs/zerolog" "github.com/spf13/pflag" ) @@ -103,3 +108,18 @@ func bridgeFlagSet() *pflag.FlagSet { return fs } + +// parseURL logs a warning if the flag provided is an +// unencrypted non-local string, and returns the value. +// Ref: https://github.com/umee-network/peggo/issues/178 +func parseURL(logger zerolog.Logger, konfig *koanf.Koanf, flag string) (string, error) { + endpoint := konfig.String(flag) + u, err := url.Parse(endpoint) + if err != nil { + return "", err + } + if strings.EqualFold(u.Scheme, "http") && !strings.Contains(u.Host, "localhost") { + logger.Warn().Str(flag, endpoint).Msg("flag is unsafe; unencrypted non-local url used") + } + return endpoint, nil +} diff --git a/cmd/peggo/orchestrator.go b/cmd/peggo/orchestrator.go index 7abaddaf..d86454b4 100644 --- a/cmd/peggo/orchestrator.go +++ b/cmd/peggo/orchestrator.go @@ -63,8 +63,15 @@ func getOrchestratorCmd() *cobra.Command { return err } - tmRPCEndpoint := konfig.String(flagTendermintRPC) - cosmosGRPC := konfig.String(flagCosmosGRPC) + tmRPCEndpoint, err := parseURL(logger, konfig, flagTendermintRPC) + if err != nil { + return err + } + cosmosGRPC, err := parseURL(logger, konfig, flagCosmosGRPC) + if err != nil { + return err + } + cosmosGasPrices := konfig.String(flagCosmosGasPrices) tmRPC, err := rpchttp.New(tmRPCEndpoint, "/websocket") @@ -269,7 +276,7 @@ func getOrchestratorCmd() *cobra.Command { } func trapSignal(cancel context.CancelFunc) { - var sigCh = make(chan os.Signal, 1) + sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGTERM) signal.Notify(sigCh, syscall.SIGINT)