Review report

core: PR #36434

3 minor findings · 3 suggestions

Earlier concerns neither republished nor resolved: 1 minor finding · 3 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · Startup replaces an existing live Unix RPC socket

A second node using the same custom socket path unlinks the first node’s endpoint and serves new clients itself; how often operators share such paths is unconfirmed.

Location: src/netbase.cpp:801 (head).

Details and suggested fix

UnixSocketAddr::PreparePath() removes an existing socket without checking whether a server is listening. Because BindAndStartListening() calls it before bind(), a Unix socket never reaches the existing “probably already running” error used for an occupied TCP address. If two bitcoind instances with different datadirs use the same absolute -rpcbind=unix:<path>, or a relative path that escapes the datadir with .., the second unlinks the first node’s socket and binds its own. The first node keeps running, but new clients reach the second node. Cookie authentication produces authorization errors; with shared rpcauth or rpcpassword, commands run on the wrong node. Stopping the second node does not restore the path. Default and datadir-relative paths are protected by the datadir lock. The same removal behavior applies to -ipcbind, while the release notes promise to remove a “stale socket file.” Before unlinking, attempt connect(): if it succeeds, return the existing “probably already running” error, and remove the socket only on ECONNREFUSED. This probe still races with concurrent startup, but handles an already-running node. No in-tree configuration shares a custom path, so production prevalence is unconfirmed.


Link

[minor] · bitcoin-cli rejects unspecified IP addresses before connecting

A validity check inherited from proxy handling makes -rpcconnect=0.0.0.0 fail on Linux, although it previously reached a local listener; production usage is unconfirmed.

Location: src/netbase.cpp:834 (head).

Details and suggested fix

bitcoin-cli now connects through SocketAddr::Connect(), which returns early when IsValid() is false. For a CService, this calls CNetAddr::IsValid(), which rejects 0.0.0.0 (INADDR_ANY) and the IPv6 unspecified address ::. Before this change, HTTPClient::Connect() passed each resolved CService directly to ConnectDirectly(), and neither ConnectDirectly() nor Lookup() filters these addresses. On Linux, connecting to 0.0.0.0 reaches a local listener, so bitcoin-cli -rpcconnect=0.0.0.0 (for example, copied from rpcbind=0.0.0.0) previously reached a local node. It now fails with “Could not connect to the server”; with -rpcwait and the default -rpcwaittimeout=0, it retries forever. Keep the guard in the old Proxy::Connect() path and remove it from the CService branch of SocketAddr::Connect(). An invalid Unix path already fails in GetSockAddr(). Adjust the unit test that expects SocketAddr{}.Connect() to return null. No in-tree caller or test uses this destination, so production usage is unconfirmed.


Link

[minor] · reset_conn() drops the configured socket timeout

Functional-test TCP sockets now have no timeout, while Unix sockets use a fixed 60 seconds that ignores --timeout-factor.

Location: test/functional/interface_http.py:48 (head).

Details and suggested fix

The base reset_conn() constructed HTTPConnection(..., timeout=self.timeout), where self.timeout is node.rpc_timeout scaled by the timeout factor. Although that construction remains, both branches replace the connection before calling connect(). The TCP branch omits timeout, so http.client uses the global default, which is no timeout because nothing in the repository calls socket.setdefaulttimeout(). The Unix branch also omits it, so UnixHTTPConnection uses its fixed 60-second default. Helpers such as the blocking recv_raw() in expect_timeout() rely on the constructor timeout. If the server regresses and never responds or closes, the TCP test can hang until something outside it kills the process instead of failing after rpc_timeout. Remove the redundant first construction and pass timeout=self.timeout to both HTTPConnection and UnixHTTPConnection.


Optional improvements

Link

[suggestion] · Unix RPC sockets cannot grant group access

Group-based RPC deployments cannot connect through the Unix socket, even when -rpccookieperms=group makes the cookie readable to those members.

Location: src/httpserver.cpp:840 (head).

Details and suggested fix

After bind(), the socket mode is always replaced with 0600. The comment says the umask “may leave it accessible to other local users,” but SetupEnvironment() sets the umask to 0077 in bitcoind and bitcoin-qt before binding, so the socket is already owner-only. The chmod adds no protection and prevents any configuration from widening access. doc/init.md describes controlling RPC-client access through group membership, and -rpccookieperms=group makes the cookie group-readable for that purpose. With -rpcbind=unix, those group members can read the cookie but get EACCES when connecting, because Linux requires write permission on the socket file. Manual chmod is lost when startup recreates the socket. If group access is out of scope, document that and correct the comment. Otherwise, apply the -rpccookieperms mode, or a dedicated option, to the socket while keeping owner-only access as the default. Widening access also exposes the unauthenticated -rest endpoints served on the same socket.


Link

[suggestion] · The negative log assertion cannot match, and the tests do not check socket permissions

The unexpected-message string omits the unix: prefix in the logged address, and no test asserts the promised owner-only socket mode.

Location: test/functional/rpc_bind.py:242 (head).

Details and suggested fix

InitHTTPServer() logs Binding RPC on address %s using ToStringAddrPort(), which produces unix:/tmp/... for a Unix socket. The unexpected_msgs entry here omits the prefix, and assert_debug_log() uses substring matching, so this entry cannot match. The later assert not os.path.exists(unix_bind) still covers the behavior, but the log assertion adds nothing. Use f"Binding RPC on address unix:{unix_bind}", as the next block does. Separately, the --httpunix checks in interface_http.py and rpc_bind.py assert only that the path is a socket, although the release notes and BindAndStartListening() promise owner-only access. Add assert stat.S_IMODE(os.stat(path).st_mode) & 0o077 == 0 alongside those socket-type checks.


Link

[suggestion] · Connection errors can report an address bitcoin-cli did not try

When a hostname resolves to multiple addresses, the error can pair one attempt’s failure with an untried address and omits the hostname supplied by the user.

Location: src/bitcoin-cli.cpp:1296 (head).

Details and suggested fix

CallRPC() shares one deadline across all resolved addresses and stops when it expires. On failure, the error reports host_and_sockaddrs.second.back() alongside last_error. If -rpcconnect resolves to several addresses, such as localhost resolving to ::1 and 127.0.0.1, an early attempt can use up the timeout before the last address is tried. The message then names that untried address. Even when every address is tried, it replaces the user-supplied hostname with an IP. Before this change, the error named the supplied host and port. Track the last SocketAddr actually attempted and report it, or fall back to the -rpcconnect value. Only the diagnostic text is affected.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.