Skip to content

Commit

Permalink
fix: warn user when using unencrypted non-local urls (#205)
Browse files Browse the repository at this point in the history
Adds a log warning whenever unencrypted non-local urls are used in flags. Since it uses `url.Parse`, it should also give an error if unable to parse the url. 

Closes : #178
  • Loading branch information
adamewozniak authored Feb 22, 2022
1 parent a29d4ea commit 841a053
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
40 changes: 26 additions & 14 deletions cmd/peggo/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions cmd/peggo/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
13 changes: 10 additions & 3 deletions cmd/peggo/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 841a053

Please sign in to comment.