reach an onion host written with a trailing dot over tor, and remove the dot from saved server urls
What changed, and why it matters
This commit fixes a handling quirk for Tor 'onion' web addresses when they are written with a trailing dot (for example, 'example.onion.'). Previously, Sparrow did not recognize these dotted onion addresses as Tor destinations, so it might try to connect over the regular internet instead of through Tor, and could fail to enforce the requirement that a Tor proxy must be configured. The change makes Sparrow strip the trailing dot, recognize the address as an onion address, route it through Tor, and save server URLs without the trailing dot.
Users relying on Tor should upgrade to the fixed version. Review any saved server URLs ending in '.onion.' after upgrade to ensure they are normalized. Developers should verify that all onion-host checks across the codebase now use Protocol.isOnionHost().
Security signals we found
Tor/onion address canonicalization bypass
trailing-dot FQDN not recognized as onion host
proxy requirement check bypassed for dotted onion hosts
saved server URL normalization to prevent dotted onion persistence
Evidence from the diff
The patch centralizes onion-host detection in Protocol.isOnionHost() by stripping a possible trailing dot before checking the .onion suffix. It adds Protocol.normalizeOnionUrl() to remove the trailing dot from onion hosts in saved server URLs, and updates Server construction, Auth47, and LnurlAuth to use these helpers. The bug was that a fully-qualified domain name notation such as ‘host.onion.’ was not matched by endsWith(‘.onion’), causing Tor routing/proxy checks to be bypassed or fail.
Changed components
src/main/java/com/sparrowwallet/sparrow/io/Server.javasrc/main/java/com/sparrowwallet/sparrow/net/Auth47.javasrc/main/java/com/sparrowwallet/sparrow/net/LnurlAuth.javasrc/main/java/com/sparrowwallet/sparrow/net/Protocol.javaInspect captured patch +34 / −4
### src/main/java/com/sparrowwallet/sparrow/io/Server.java
@@ -34,7 +34,7 @@ public Server(String url, String alias) {
throw new IllegalArgumentException("Server alias cannot be an empty string");
}
- this.url = url;
+ this.url = Protocol.normalizeOnionUrl(url);
this.alias = alias;
}
### src/main/java/com/sparrowwallet/sparrow/net/Auth47.java
@@ -94,7 +94,7 @@ private void send(String json) throws Exception {
}
HttpClientService httpClientService = AppServices.getHttpClientService();
- if(httpClientService.getTorProxy() == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX)) {
+ if(httpClientService.getTorProxy() == null && Protocol.isOnionHost(callback.getHost())) {
throw new Auth47Exception("A Tor proxy must be configured to authenticate this resource.");
}
### src/main/java/com/sparrowwallet/sparrow/net/LnurlAuth.java
@@ -112,7 +112,7 @@ public void sendResponse(Wallet wallet) throws Exception {
}
HttpClientService httpClientService = AppServices.getHttpClientService();
- if(httpClientService.getTorProxy() == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX)) {
+ if(httpClientService.getTorProxy() == null && Protocol.isOnionHost(callback.getHost())) {
throw new LnurlAuthException("A Tor proxy must be configured to authenticate this resource.");
}
### src/main/java/com/sparrowwallet/sparrow/net/Protocol.java
@@ -150,8 +150,38 @@ public String toUrlString(HostAndPort hostAndPort) {
return toUrlString() + hostAndPort.toString();
}
+ //A trailing dot names the same host, so an onion host written with one must still be reached over Tor
public static boolean isOnionHost(String host) {
- return host != null && host.toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX);
+ return host != null && stripTrailingDot(host).toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX);
+ }
+
+ private static String stripTrailingDot(String host) {
+ return host.endsWith(".") ? host.substring(0, host.length() - 1) : host;
+ }
+
+ /**
+ * Returns the url with the trailing dot removed from an onion host, the form Tor expects, leaving any other url unchanged.
+ */
+ public static String normalizeOnionUrl(String url) {
+ Protocol protocol = getProtocol(url);
+ if(protocol == null) {
+ return url;
+ }
+
+ HostAndPort hostAndPort = protocol.getServerHostAndPort(url);
+ if(!hostAndPort.getHost().endsWith(".") || !isOnionHost(hostAndPort.getHost())) {
+ return url;
+ }
+
+ String current = hostAndPort.toString();
+ HostAndPort normalized = hostAndPort.hasPort() ? HostAndPort.fromParts(stripTrailingDot(hostAndPort.getHost()), hostAndPort.getPort())
+ : HostAndPort.fromHost(stripTrailingDot(hostAndPort.getHost()));
+ int position = url.startsWith(protocol.toUrlString()) ? protocol.toUrlString().length() : 0;
+ if(!url.startsWith(current, position)) {
+ return url;
+ }
+
+ return url.substring(0, position) + normalized + url.substring(position + current.length());
}
public static boolean isOnionAddress(Server server) {Why this scored 44/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.