Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
13 changes: 12 additions & 1 deletion gno.land/pkg/gnoweb/frontend/js/controller-action-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,21 @@ export class ActionFunctionController extends BaseController {
);
}

// Normalize a remote URL for browser fetch
// - http:// and https:// are used as-is
// - tcp:// is converted to http:// (RPC over HTTP)
// - No protocol defaults to http://
private _normalizeRemoteUrl(url: string): string {
if (url.startsWith("tcp://")) return url.replace("tcp://", "http://");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change tcp://127.0.0.1:26657 to http://127.0.0.1:26657, then we also need to change it here when we set the CSP for connect-src:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... probably for other changes to the remote string, but I can't test them locally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... In fact, maybe it's better to correct the cfg.remote URL much earlier before it is used, like here:

appcfg.NodeRemote = cfg.remote

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jefft0! You are right, this will keep the JS fetch clean too. I Updated the PR to normalize the URL at the Go level instead

if (url.startsWith("http://") || url.startsWith("https://")) return url;
return `http://${url}`;
}

// 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 baseUrl = this._normalizeRemoteUrl(remote);
const url = `${baseUrl}/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