http: support unix sockets

bitcoin/bitcoin: PR #36434

4 minor findings · 3 suggestions

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

Findings

Link

[minor] · Startup replaces a live listener's Unix socket pathname

Separately locked nodes sharing a writable absolute RPC socket path silently replace one another's endpoint; no in-tree or documented configuration sharing such a path was found.

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

Details and suggested fix

PreparePath() removes every existing socket inode before bind(), without checking whether it has a live listener. Two same-user nodes with distinct data and blocks directories can therefore both start with the same absolute -rpcbind=unix:/path. The second node takes the pathname, so new connections reach it rather than the first node. Existing connections can survive, and RPC authentication still applies. Stopping the second node does not restore access to the first because StopListening() only closes descriptors. IPC uses the same cleanup policy, but that does not distinguish a stale socket from a live HTTP endpoint.

Before unlinking, probe the endpoint and reject a successful connection as already in use; only treat ECONNREFUSED as evidence permitting stale-file cleanup. A probe alone does not serialize simultaneous starters, so concurrent ownership also needs protection. Add a two-node shared-path regression test.


Link

[minor] · Post-bind socket chmod can follow a substituted symlink

If an operator places the socket in an attacker-writable non-sticky directory, a local actor can race the pathname chmod and apply mode 0600 to another file owned by the daemon user.

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

Details and suggested fix

fs::permissions(..., perm_options::replace, ec) follows symlinks. Between bind() and this call, an actor who can replace directory entries can substitute a symlink to a file outside the socket directory. The daemon then clears that target's execute, group, and other permission bits. PreparePath() checks for symlinks before binding, so it does not cover this window. The documentation advises a restricted directory, and directories created by the daemon are protected by umask 0077; the issue requires an explicitly chosen directory permitting replacement. That umask also already makes the newly bound socket owner-only. Add fs::perm_options::nofollow to the permissions operation so a substituted symlink cannot redirect the mode change.


Link

[minor] · HTTP test connections discard the configured RPC timeout

reset_conn() replaces its timeout-configured connection with an unbounded TCP connection or a Unix connection fixed at 60 seconds, changing how stalled or slow functional tests fail.

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

Details and suggested fix

The initial HTTPConnection(timeout=self.timeout) is immediately discarded. The selected TCP constructor receives no timeout, while UnixHTTPConnection uses its default of 60 seconds instead of the already-scaled node.rpc_timeout. Some checks override the socket timeout later, but check_default_connection() immediately reads responses without doing so. A stalled TCP response can therefore wait until the runner terminates the test, and --httpunix ignores --timeout-factor, potentially failing slow runs prematurely. Remove the discarded construction and pass timeout=self.timeout to both selected constructors.


Link

[minor] · The new validity guard rejects previously usable CLI destinations

bitcoin-cli now rejects -rpcconnect=0.0.0.0 before connect(), preventing local RPC connections on Linux; this platform-specific case was not reproduced, and no in-tree or documented configuration using it was found.

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

Details and suggested fix

The CLI previously passed each Lookup() result directly to ConnectDirectly(). It now goes through SocketAddr::Connect(), which rejects destinations failing CNetAddr::IsValid(), including unspecified addresses and IPv6 documentation prefixes. Lookup() does not apply that validity check. On Linux, connecting to an unspecified destination can reach the local listener, so the same address and port that previously worked now produce Could not connect to the server without attempting a connection. The guard came from Proxy::Connect(). Keep that guard in Proxy, validate Unix paths in their branch, and let the CService branch retain the CLI's previous ConnectDirectly() behavior.


Optional improvements

Link

[suggestion] · Group-authorized RPC clients have no persistent Unix socket permission setting

The documented group-based RPC deployment cannot adopt the new socket without post-start permission changes; existing TCP access remains available.

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

Details and suggested fix

doc/init.md documents controlling RPC clients by group membership, and -rpccookieperms=group lets a separate service user read the authentication cookie. That user still cannot connect to this socket because its mode is unconditionally replaced with 0600. Manual chmod or chgrp does not survive recreation at startup. Provide an explicit opt-in socket-permission setting while retaining the owner-only default and normal RPC authentication. If group access is deferred, document that these deployments should retain TCP. The new owner-only documentation is accurate, but it does not explain this limitation for existing group-based setups.


Link

[suggestion] · Unix socket tests do not assert owner-only permissions

The new Unix socket checks inspect file type but not permission bits, so widening the socket mode would leave their assertions passing.

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

Details and suggested fix

interface_http.py --httpunix asserts only S_ISSOCK, and the relative-path cases in rpc_bind.py do the same. Successful same-user RPC requests also do not establish owner-only access. The documentation presents filesystem permissions as the replacement for -rpcallowip on Unix connections, so check this property explicitly. Assert that stat.S_IMODE(os.stat(path).st_mode) has no group or other bits set; with the current explicit chmod, asserting exactly 0o600 also works.


Link

[suggestion] · The release note overstates failure on a non-socket path

An existing regular file causes that Unix bind to fail, but startup still succeeds if another RPC endpoint binds.

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

Details and suggested fix

PreparePath() returns the non-socket condition as a per-endpoint error. InitHTTPServer() logs it and continues, requiring only one successful bind. For example, -rpcbind=unix:<existing-regular-file> -rpcbind=127.0.0.1 -rpcallowip=127.0.0.1 can start on TCP alone. Reword the note to say that the Unix endpoint fails to bind and startup fails only if no endpoint binds, rather than promising unconditional startup failure for this condition.


Coverage details

Earlier concerns

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