Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions gno.land/cmd/gnoweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ import (
"go.uber.org/zap/zapcore"
)

// normalizeRemoteURL ensures the remote URL has a valid HTTP(S) protocol.
// - tcp:// is converted to http:// (RPC uses HTTP over TCP)
// - No protocol defaults to http://
// - http:// and https:// are kept as-is
func normalizeRemoteURL(remote string) string {
if strings.HasPrefix(remote, "tcp://") {
return strings.Replace(remote, "tcp://", "http://", 1)
}
if strings.HasPrefix(remote, "http://") || strings.HasPrefix(remote, "https://") {
return remote
}
return "http://" + remote
}

// Authorized external image host providers.
var cspImgHost = []string{
// Gno-related hosts
Expand Down Expand Up @@ -225,10 +239,10 @@ func setupWeb(cfg *webCfg, _ []string, io commands.IO) (func() error, error) {
// Setup app
appcfg := gnoweb.NewDefaultAppConfig()
appcfg.ChainID = cfg.chainid
appcfg.NodeRemote = cfg.remote
appcfg.NodeRemote = normalizeRemoteURL(cfg.remote)
appcfg.NodeRequestTimeout = cfg.remoteTimeout
appcfg.RemoteHelp = cfg.remoteHelp
if appcfg.RemoteHelp == "" {
appcfg.RemoteHelp = normalizeRemoteURL(cfg.remoteHelp)
if appcfg.RemoteHelp == "" || appcfg.RemoteHelp == "http://" {
appcfg.RemoteHelp = appcfg.NodeRemote
}
appcfg.Analytics = cfg.analytics
Expand Down Expand Up @@ -262,7 +276,7 @@ func setupWeb(cfg *webCfg, _ []string, io commands.IO) (func() error, error) {
logger.Info("Running", "listener", bindaddr.String())

// Setup security headers
secureHandler := SecureHeadersMiddleware(app, !cfg.noStrict, cfg.remote)
secureHandler := SecureHeadersMiddleware(app, !cfg.noStrict, appcfg.NodeRemote)

// Setup server
server := &http.Server{
Expand Down
24 changes: 24 additions & 0 deletions gno.land/cmd/gnoweb/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ import (
"github.com/stretchr/testify/require"
)

func TestNormalizeRemoteURL(t *testing.T) {
t.Parallel()

cases := []struct {
name string
input string
expected string
}{
{"tcp protocol", "tcp://127.0.0.1:26657", "http://127.0.0.1:26657"},
{"http protocol", "http://127.0.0.1:26657", "http://127.0.0.1:26657"},
{"https protocol", "https://rpc.gno.land:443", "https://rpc.gno.land:443"},
{"no protocol", "127.0.0.1:26657", "http://127.0.0.1:26657"},
{"no protocol with domain", "rpc.gno.land:443", "http://rpc.gno.land:443"},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
result := normalizeRemoteURL(tc.input)
assert.Equal(t, tc.expected, result)
})
}
}

func TestSetupWeb(t *testing.T) {
opts := defaultWebOptions
opts.bind = "127.0.0.1:0" // random port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class ActionFunctionController extends BaseController {
// Fetch the qeval result from the remote
private async _fetchQEval(remote: string, data: string): Promise<string> {
try {
const url = `http://${remote}/abci_query?path=vm%2fqeval&data=${btoa(data)}`;
const url = `${remote}/abci_query?path=vm%2fqeval&data=${btoa(data)}`;
const response = await fetch(url);
if (!response.ok) return "";

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading