point to rpcallowip when bitcoin core resets the rpc connection before the connect completes, not only once the request has been sent
What changed, and why it matters
This commit improves an error message in Sparrow Wallet when it cannot talk to a Bitcoin Core node. Starting with Bitcoin Core 32.1, a node may silently close the connection if Sparrow's IP is not in the node's rpcallowip allow-list. The previous code only showed a helpful 'check rpcallowip' hint when the reset happened after a request was sent; now it also shows the hint when the reset happens earlier, while the connection is still being opened. There is no vulnerability being fixed—only a better diagnostic message for users.
No security action required. Treat as a normal UX/diagnostic improvement. Users who see the new message should verify Bitcoin Core's rpcallowip configuration.
Security signals we found
No memory-safety, cryptographic, authentication, or authorization change
No input parsing or deserialization change
Error-message improvement for a configuration mismatch (Bitcoin Core rpcallowip)
Adds unit test for diagnostic behavior
Evidence from the diff
BitcoindTransport.pass() wraps an HTTP call to bitcoind. Bitcoin Core v32.1+ drops TCP connections from non-rpcallowip clients without an HTTP response. The existing code caught IOException after writing the request body and re-threw it with a hint to check rpcallowip. This patch moves the hint string up, catches SocketException around getOutputStream().write(), and, when not using a SOCKS proxy and the message contains ‘Connection reset’, re-throws as IOException with the same rpcallowip hint. A new test verifies that a refused connection (no reset) does not incorrectly suggest rpcallowip. The change is purely diagnostic/UX.
Changed components
src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindTransport.javasrc/test/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindTransportRejectionTest.javaInspect captured patch +26 / −2
### src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindTransport.java
@@ -105,9 +105,19 @@ public String pass(String request) throws IOException {
log.debug("> " + request);
+ //From v32.1 Bitcoin Core closes the connection from a client outside rpcallowip without answering, where earlier versions answered 403 below
+ String closedMessage = "Bitcoin Core at " + bitcoindUrl.getAuthority() + " closed the connection without responding, check its rpcallowip settings";
+
try(OutputStream os = connection.getOutputStream()) {
byte[] jsonBytes = request.getBytes(StandardCharsets.UTF_8);
os.write(jsonBytes);
+ } catch(SocketException e) {
+ //The close can also reset the connection before the connect completes, where other socket errors (unreachable network, local firewall) never reached the node,
+ //and a reset from a SOCKS proxy is the proxy's own failure
+ if(!useProxy && e.getMessage() != null && e.getMessage().contains("Connection reset")) {
+ throw new IOException(closedMessage, e);
+ }
+ throw e;
}
int statusCode;
@@ -116,8 +126,7 @@ public String pass(String request) throws IOException {
} catch(InterruptedIOException e) {
throw e;
} catch(IOException e) {
- //From v32.1 Bitcoin Core closes the connection from a client outside rpcallowip without answering, where earlier versions answered 403 below
- throw new IOException("Bitcoin Core at " + bitcoindUrl.getAuthority() + " closed the connection without responding, check its rpcallowip settings", e);
+ throw new IOException(closedMessage, e);
}
//Trust on first use, as for non-CA-certified Electrum servers: the certificate presented by the node on the first connection is saved, and required on all connections thereafter
### src/test/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindTransportRejectionTest.java
@@ -14,6 +14,7 @@
import java.nio.file.Path;
import java.time.Duration;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -46,6 +47,20 @@ public void resetConnectionPointsToRpcAllowIp() throws Exception {
assertRpcAllowIpHint(true);
}
+ @Test
+ public void refusedConnectionDoesNotPointToRpcAllowIp() throws Exception {
+ int port;
+ try(ServerSocket serverSocket = new ServerSocket(0, 50, InetAddress.getLoopbackAddress())) {
+ port = serverSocket.getLocalPort();
+ }
+
+ BitcoindTransport transport = new BitcoindTransport(new Server("http://127.0.0.1:" + port), "test", "user:pass");
+ assertTimeoutPreemptively(Duration.ofSeconds(10), () -> {
+ IOException thrown = assertThrows(IOException.class, () -> transport.pass("{\"id\":1,\"method\":\"getblockchaininfo\",\"params\":[]}"));
+ assertFalse(thrown.getMessage().contains("rpcallowip"), "Expected no rpcallowip hint, got: " + thrown);
+ });
+ }
+
private static void assertRpcAllowIpHint(boolean reset) throws Exception {
try(ServerSocket serverSocket = new ServerSocket(0, 50, InetAddress.getLoopbackAddress())) {
Thread acceptor = new Thread(() -> {Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.