use the default port for a proxy given without one in http requests, bwt, tor identity changes and tor status checks
What changed, and why it matters
This commit fixes a bug where Sparrow Wallet would use an invalid port number when a user configured a Tor/proxy server address without explicitly specifying a port. Previously, the code called getPort(), which could return -1 or an undefined value when no port was provided, causing connection failures or possibly connecting to the wrong service. The fix supplies the default SOCKS/Tor proxy port (9050) in those situations across Tor status checks, BWT (Bitcoin Wallet Tracker) startup, HTTP proxy setup, Tor identity rotation, and the terminal UI.
Treat as a reliability/robustness fix rather than a critical security vulnerability. Users relying on custom proxy servers should ensure they upgrade and verify proxy settings include an explicit port if non-default. Review whether any other HostAndPort.getPort() calls in the codebase lack a default-port fallback.
Security signals we found
Use of default port fallback for network proxy configuration
Potential prior behavior of connecting to invalid/undefined port when proxy string lacked port
Tor control port derived from proxy port (proxy port + 1), making correct proxy port handling security-relevant for identity rotation
Fix touches both GUI and terminal proxy status checks, BWT bitcoind proxy configuration, and HTTP proxy supplier
Evidence from the diff
The patch replaces direct calls to HostAndPort.getPort() with HostAndPort.getPortOrDefault(ProxyTcpOverTlsTransport.DEFAULT_PROXY_PORT) in five files. HostAndPort.fromString() returns a port only when one is present in the input string; otherwise getPort() historically returns -1 (Guava behavior). The affected code paths opened TCP sockets, configured bitcoindProxy for BWT, built HttpProxy objects, and computed Tor control ports (proxy port + 1). Without the default, these paths could attempt connections to port -1 (invalid) or derive a control port of 0, breaking Tor/proxy functionality. The change also reorders assignment in TorHttpProxySupplier._setTorProxy() so the computed proxy is set before the in-use proxy field.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/TorStatusLabel.javasrc/main/java/com/sparrowwallet/sparrow/net/Bwt.javasrc/main/java/com/sparrowwallet/sparrow/net/TorHttpProxySupplier.javasrc/main/java/com/sparrowwallet/sparrow/net/TorUtils.javasrc/main/java/com/sparrowwallet/sparrow/terminal/ProxyStatusLabel.javaInspect captured patch +9 / −7
### src/main/java/com/sparrowwallet/sparrow/control/TorStatusLabel.java
@@ -5,6 +5,7 @@
import com.sparrowwallet.sparrow.AppServices;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
import com.sparrowwallet.sparrow.io.Config;
+import com.sparrowwallet.sparrow.net.ProxyTcpOverTlsTransport;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;
import javafx.concurrent.Worker;
@@ -80,7 +81,7 @@ protected Task<Void> createTask() {
return new Task<>() {
protected Void call() throws IOException {
HostAndPort proxyHostAndPort = HostAndPort.fromString(Config.get().getProxyServer());
- Socket socket = new Socket(proxyHostAndPort.getHost(), proxyHostAndPort.getPort());
+ Socket socket = new Socket(proxyHostAndPort.getHost(), proxyHostAndPort.getPortOrDefault(ProxyTcpOverTlsTransport.DEFAULT_PROXY_PORT));
socket.close();
return null;
### src/main/java/com/sparrowwallet/sparrow/net/Bwt.java
@@ -191,7 +191,7 @@ private void start(Collection<String> outputDescriptors, Collection<String> addr
HostAndPort torProxy = getTorProxy();
if(Protocol.isOnionAddress(bwtConfig.bitcoindUrl) && torProxy != null) {
- bwtConfig.bitcoindProxy = torProxy.toString();
+ bwtConfig.bitcoindProxy = HostAndPort.fromParts(torProxy.getHost(), torProxy.getPortOrDefault(ProxyTcpOverTlsTransport.DEFAULT_PROXY_PORT)).toString();
}
if((config.getCoreAuthType() == CoreAuthType.COOKIE || config.getCoreAuth() == null || config.getCoreAuth().length() < 2) && config.getCoreDataDir() != null) {
### src/main/java/com/sparrowwallet/sparrow/net/TorHttpProxySupplier.java
@@ -19,7 +19,7 @@ private HttpProxy computeHttpProxy(HostAndPort hostAndPort) {
return null;
}
- return new HttpProxy(HttpProxyProtocol.SOCKS, hostAndPort.getHost(), hostAndPort.getPort());
+ return new HttpProxy(HttpProxyProtocol.SOCKS, hostAndPort.getHost(), hostAndPort.getPortOrDefault(ProxyTcpOverTlsTransport.DEFAULT_PROXY_PORT));
}
public HostAndPort getTorProxy() {
@@ -28,9 +28,9 @@ public HostAndPort getTorProxy() {
// shouldn't call directly but use httpClientService.setTorProxy()
public void _setTorProxy(HostAndPort hostAndPort) {
- // set proxy
- this.torProxy = hostAndPort;
+ //The proxy to apply is computed first, so a proxy that cannot be applied is not reported as the one in use
this.httpProxy = computeHttpProxy(hostAndPort);
+ this.torProxy = hostAndPort;
}
@Override
### src/main/java/com/sparrowwallet/sparrow/net/TorUtils.java
@@ -37,7 +37,7 @@ public static void changeIdentity(HostAndPort proxy) {
if(AppServices.isTorRunning()) {
Tor.getDefault().changeIdentity();
} else {
- HostAndPort control = HostAndPort.fromParts(proxy.getHost(), proxy.getPort() + 1);
+ HostAndPort control = HostAndPort.fromParts(proxy.getHost(), proxy.getPortOrDefault(ProxyTcpOverTlsTransport.DEFAULT_PROXY_PORT) + 1);
InetAddress controlAddress;
try {
controlAddress = InetAddress.getByName(control.getHost());
### src/main/java/com/sparrowwallet/sparrow/terminal/ProxyStatusLabel.java
@@ -4,6 +4,7 @@
import com.googlecode.lanterna.gui2.Label;
import com.sparrowwallet.sparrow.AppServices;
import com.sparrowwallet.sparrow.io.Config;
+import com.sparrowwallet.sparrow.net.ProxyTcpOverTlsTransport;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Task;
import javafx.concurrent.Worker;
@@ -55,7 +56,7 @@ protected Task<Void> createTask() {
return new Task<>() {
protected Void call() throws IOException {
HostAndPort proxyHostAndPort = HostAndPort.fromString(Config.get().getProxyServer());
- Socket socket = new Socket(proxyHostAndPort.getHost(), proxyHostAndPort.getPort());
+ Socket socket = new Socket(proxyHostAndPort.getHost(), proxyHostAndPort.getPortOrDefault(ProxyTcpOverTlsTransport.DEFAULT_PROXY_PORT));
socket.close();
return null;Why this scored 35/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.