Review report

core: PR #36434

4 minor findings · 4 suggestions

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

Findings

Link

[minor] · bitcoin-cli rejects the unspecified address 0.0.0.0

On Linux, bitcoin-cli -rpcconnect=0.0.0.0 no longer reaches a loopback listener; production use is unconfirmed because no in-tree caller relies on this address.

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, CNetAddr::IsValid() rejects 0.0.0.0 and the IPv6 unspecified address. Before this change, HTTPClient::Connect() passed each resolved CService directly to ConnectDirectly(), which has no such check. On Linux, connecting to 0.0.0.0 reaches a loopback listener, so a command such as bitcoin-cli -rpcconnect=0.0.0.0 could reach a local node. It now fails with “Could not connect to the server”; with -rpcwait and the default -rpcwaittimeout=0, it retries indefinitely. The validity guard came from the old Proxy::Connect(). Keep it in Proxy::Connect() and remove it from the CService branch of SocketAddr::Connect(). An invalid Unix path already fails in GetSockAddr(), so the SocketAddr{} unit test expecting a null result would need adjustment. No in-tree caller or test uses this destination, so production use is unconfirmed.


Link

[minor] · Startup can replace another node’s live Unix RPC socket

A second node using the same custom socket path silently takes over the first node’s RPC endpoint; how often operators use a shared custom path is unconfirmed.

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

Details and suggested fix

UnixSocketAddr::PreparePath() removes an existing socket without checking whether a server is still listening on it. Because BindAndStartListening() calls this immediately before bind(), Unix sockets cannot reach the existing EADDRINUSE “probably already running” error. If two bitcoind instances 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 is no longer reachable through that path, and new clients reach the second node. With cookie authentication, those clients receive authorization errors; with shared rpcauth, their commands run on the wrong node. Stopping the second node does not restore the path. The default and datadir-relative paths are protected by the datadir lock. The release notes describe removing a “stale socket file,” which is narrower than the behavior. -ipcbind also removes an existing socket unconditionally. Before unlinking, connect to the path: if the connection succeeds, fail with the existing “probably already running” error, and remove the file only on ECONNREFUSED. No in-tree configuration shares a custom path, so how often operators encounter this is unconfirmed.


Link

[minor] · BitcoinHTTPConnection.reset_conn() drops the configured timeout

Functional-test TCP connections can block without a timeout, while Unix-socket connections 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 on the first line, both branches replace it before connecting. The TCP branch omits timeout, so http.client uses its global default, which is no timeout because nothing in the repository calls socket.setdefaulttimeout(). The Unix branch also omits the argument, 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, a TCP test can hang until something outside the test kills it instead of failing after rpc_timeout. Remove the first construction and pass timeout=self.timeout to both constructors.


Link

[minor] · Socket permission change can follow a symlink swapped in after bind

A local user who can modify the socket’s parent directory could race startup so bitcoind changes the mode of a different file it owns; practical exposure depends on directory configuration.

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

Details and suggested fix

After bind(), fs::permissions(socket_path, owner_read | owner_write, replace) sets the mode by pathname. Without perm_options::nofollow, std::filesystem::permissions follows symlinks. If another local user can unlink entries in the socket’s parent directory, such as a non-sticky directory they can write, they can replace the new socket with a symlink between bind() and this call. bitcoind then sets mode 0600 on the symlink target. This could remove group access to a file owned by the bitcoind user, or affect any file if bitcoind runs as root. The earlier symlink_status() check in PreparePath() does not protect this step. SetupEnvironment() already sets umask 0077, so bind() creates the socket owner-only. Remove the chmod and rely on the umask to close the race. The documentation advises using a restricted directory, and sticky directories such as /tmp prevent the unlink, so practical exposure depends on configuration.


Optional improvements

Link

[suggestion] · Unix RPC sockets cannot grant group access

Deployments that grant RPC access by group membership cannot use the Unix socket, even with -rpccookieperms=group.

Location: src/httpserver.cpp:835 (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 umask 0077 in bitcoind and bitcoin-qt before binding. The socket is therefore already owner-only, and the chmod adds no protection. No configuration can grant group access. doc/init.md describes controlling bitcoin-cli access by group membership, and -rpccookieperms=group makes the cookie group-readable for that purpose. With -rpcbind=unix, those group members can read the cookie but receive EACCES when they connect. A manual chmod does not persist because 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, keep owner-only as the default, and avoid following a replaced pathname when changing the mode.


Link

[suggestion] · The negative log check in rpc_bind.py cannot match

The unexpected message omits the unix: prefix used in the bind log, so the check passes regardless of what the node logs.

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

Details and suggested fix

InitHTTPServer() logs Binding RPC on address %s using ToStringAddrPort(), which formats a Unix socket as unix:/tmp/.... The unexpected_msgs entry here is Binding RPC on address {unix_bind}, without the prefix. Because assert_debug_log() uses substring matching, this entry cannot match the real log line. 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.


Link

[suggestion] · Release notes overstate when a non-socket path stops startup

Startup fails only if no RPC endpoint binds, so a node can start without one of its configured Unix sockets.

Location: doc/release-notes-36434.md:20 (head).

Details and suggested fix

The release notes say, “Startup fails if the path exists and is not a socket.” PreparePath() does fail that endpoint, but InitHTTPServer() only logs a warning for each failed endpoint, and startup fails only if none of them bind. With -rpcbind=unix -rpcbind=unix:/some/regular-file, the node starts and serves RPC without the second socket. The same occurs with a Unix path plus a TCP -rpcbind and -rpcallowip. The functional test covers only the single-endpoint case. Reword the note to say that the endpoint fails to bind without deleting the file, and that startup fails only if no RPC endpoint can be bound.


Link

[suggestion] · SocketAddr::GetHost() is unused and returns an invalid IPv6 Host value

Only unit tests call the new helper, and following its documentation would produce an invalid Host header for IPv6 literals.

Location: src/netbase.h:228 (head).

Details and suggested fix

This change adds SocketAddr::GetHost() and documents it as “A hostname suitable for an HTTP Host header.” No production code calls it: bitcoin-cli passes the user-supplied host, or localhost for Unix sockets, to HTTPClient::Connect(), and only netbase_tests.cpp uses the helper. For IPv6, it returns ToStringAddr() without brackets, but an IPv6 literal in a Host header must be bracketed in the RFC 3986 IP-literal form. Remove the method and its tests. If a caller is planned, bracket IPv6 and correct the documentation instead.


Coverage details

Earlier concerns

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