Skip to content

fix(cli): reject API URLs that already end in the RPC path - #13870

Open
hmdsefi wants to merge 6 commits into
filecoin-project:masterfrom
hmdsefi:fix/apiinfo-reject-rpc-path
Open

hmdsefi wants to merge 6 commits into
filecoin-project:masterfrom
hmdsefi:fix/apiinfo-reject-rpc-path

Conversation

@hmdsefi

@hmdsefi hmdsefi commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Fixes #10104

Proposed Changes

  • APIInfo.DialArgs returns an error when a URL address already ends in /rpc/v<N>, with or without a trailing slash. Before, it added /rpc/<version> again and dialed, for example, https://api.node.glif.io/rpc/v1/rpc/v1.
  • Test cases for the new error, and one for a URL with a path prefix to show that prefixes still work.
  • CHANGELOG entry.

Additional Info

The error names the suffix to remove and the path Lotus adds:

API address "https://api.node.glif.io/rpc/v1" ends with "/rpc/v1"; remove it, Lotus adds /rpc/v0 itself

Only a path that ends in /rpc/v and a number is rejected, so a proxy path prefix like https://node.glif.io/space06/lotus from #13662 still works. Multiaddr addresses are not affected. Every caller of DialArgs returns its error, so the message reaches the user, for example as could not get DialArgs: ... from GetRawAPIMulti.

I went with an error instead of stripping the suffix, as the issue suggests. The suffix can name a different version than the one being dialed, like /rpc/v1 on a v0 client, and stripping it would hide that.

Tests:

  • go test ./cli/util/ passes. With the apiinfo.go change reverted, the three new error cases fail.
  • golangci-lint reports no issues for ./cli/util/....

Checklist

Before you mark the PR ready for review, please make sure that:

DialArgs joins /rpc/<version> onto URL addresses, so an address such as
https://api.node.glif.io/rpc/v1 was dialed as .../rpc/v1/rpc/v1. Return
an error that says to remove the suffix instead. Path prefixes used by
proxies still work.

Fixes filecoin-project#10104
Comment thread cli/util/apiinfo.go Outdated
return "", err
}
if rpcPath := rpcPathSuffix.FindString(u.Path); rpcPath != "" {
return "", xerrors.Errorf("API address %q ends with %q; remove it, Lotus adds /rpc/%s itself",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@hmdsefi I know it's not a clear distinction in the codebase but we try to reserve xerrors for cases where we want to wrap another error, so since there's no %w in here let's just use fmt.Errorf

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switched to fmt.Errorf in 90d5fc0.

Comment thread cli/util/apiinfo.go Outdated
return "", err
}
if rpcPath := rpcPathSuffix.FindString(u.Path); rpcPath != "" {
return "", xerrors.Errorf("API address %q ends with %q; remove it, Lotus adds /rpc/%s itself",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also you could give the correct address in the error msg since you have it all handy already I think

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The error now names the address without the RPC path in 90d5fc0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📌 Triage

Development

Successfully merging this pull request may close these issues.

Detect badly formatted api endpoints in lite mode, give better errors

2 participants