use the application http client for lnurl-auth and auth47 callback requests
What changed, and why it matters
This commit changes how Sparrow Wallet sends authentication callbacks for two login features (Auth47 and LNURL-auth). Instead of using Java's built-in web request code directly, it now routes those requests through the wallet's shared HTTP client service. This is likely a hardening or consistency improvement, but the diff alone does not prove a specific security vulnerability was fixed.
Treat as a routine hardening/refactoring change. Review the shared HttpClientService to confirm it applies consistent TLS, proxy, redirect, timeout, and header policies for these authentication callbacks. No urgent user action is indicated by the diff alone.
Security signals we found
Centralizes outbound authentication callbacks through a shared HTTP client service
Removes direct java.net.HttpURLConnection and manual stream handling for auth callbacks
Maintains Tor proxy enforcement before sending to .onion hosts
Switches JSON parsing from Gson JsonObject to typed Map deserialization via shared client
No explicit vulnerability description, CVE, or researcher attribution in commit
Evidence from the diff
The patch replaces raw java.net.HttpURLConnection usage in Auth47.send() and LnurlAuth.sendResponse() with calls to AppServices.getHttpClientService(). For Auth47 it uses postString(); for LNURL-auth it uses requestJson(). The Tor proxy check is updated to query the new service. Error handling is adapted to HttpResponseException. The change centralizes outbound HTTP handling, which can improve proxy/TLS/cookie/reuse policy consistency and reduce hand-rolled request bugs, but the diff does not disclose a concrete exploit or CVE.
Changed components
src/main/java/com/sparrowwallet/sparrow/net/Auth47.javasrc/main/java/com/sparrowwallet/sparrow/net/LnurlAuth.javaAuth47 authentication callback (HTTP mode)LNURL-auth authentication callbackInspect captured patch +29 / −61
### src/main/java/com/sparrowwallet/sparrow/net/Auth47.java
@@ -11,15 +11,11 @@
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletNode;
import com.sparrowwallet.sparrow.AppServices;
+import com.sparrowwallet.tern.http.client.HttpResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
import java.net.*;
-import java.nio.charset.StandardCharsets;
import java.util.*;
public class Auth47 {
@@ -88,7 +84,7 @@ public Auth47(URI uri) throws MalformedURLException, URISyntaxException {
}
}
- public void sendResponse(Wallet wallet) throws IOException, Auth47Exception {
+ public void sendResponse(Wallet wallet) throws Exception {
if(!wallet.hasPaymentCode()) {
throw new Auth47Exception("A software wallet is required to authenticate.");
}
@@ -100,13 +96,13 @@ public void sendResponse(Wallet wallet) throws IOException, Auth47Exception {
}
}
- public void sendHttpResponse(Wallet wallet) throws IOException, Auth47Exception {
+ public void sendHttpResponse(Wallet wallet) throws Exception {
String json = getJsonResponse(wallet);
send(json);
}
- public void sendSorobanResponse(Wallet wallet) throws IOException, Auth47Exception {
+ public void sendSorobanResponse(Wallet wallet) throws Exception {
String json = getJsonResponse(wallet);
SorobanResponse sorobanResponse = new SorobanResponse(srbnName, json);
@@ -125,45 +121,27 @@ private String getJsonResponse(Wallet wallet) {
return gson.toJson(response);
}
- private void send(String json) throws IOException, Auth47Exception {
+ private void send(String json) throws Exception {
if(log.isInfoEnabled()) {
log.info("Sending auth47 response " + json + " to " + callback);
}
- Proxy proxy = AppServices.getProxy();
- if(proxy == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX)) {
+ HttpClientService httpClientService = AppServices.getHttpClientService();
+ if(httpClientService.getTorProxy() == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX)) {
throw new Auth47Exception("A Tor proxy must be configured to authenticate this resource.");
}
- HttpURLConnection connection = proxy == null ? (HttpURLConnection) callback.openConnection() : (HttpURLConnection) callback.openConnection(proxy);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "application/json");
- connection.setDoOutput(true);
-
- try(OutputStream os = connection.getOutputStream()) {
- byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);
- os.write(jsonBytes);
- }
-
- int statusCode = connection.getResponseCode();
- if(statusCode == 404) {
- throw new Auth47Exception("Could not authenticate. Callback URL of " + callback + " returned a 404 response.");
- }
-
- StringBuilder res = new StringBuilder();
- try(BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
- String responseLine;
- while((responseLine = br.readLine()) != null) {
- res.append(responseLine.trim());
+ try {
+ String response = httpClientService.postString(callback.toString(), null, "application/json", json);
+ if(log.isDebugEnabled()) {
+ log.debug("Received " + response);
+ }
+ } catch(HttpResponseException e) {
+ if(e.getStatusCode() == 404) {
+ throw new Auth47Exception("Could not authenticate. Callback URL of " + callback + " returned a 404 response.");
}
- }
-
- if(log.isDebugEnabled()) {
- log.debug("Received " + statusCode + " " + res);
- }
- if(statusCode < 200 || statusCode >= 300) {
- throw new Auth47Exception("Could not authenticate. Server returned " + res);
+ throw new Auth47Exception("Could not authenticate. Server returned " + e.getResponseBody());
}
}
### src/main/java/com/sparrowwallet/sparrow/net/LnurlAuth.java
@@ -1,7 +1,5 @@
package com.sparrowwallet.sparrow.net;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
import com.sparrowwallet.drongo.ExtendedKey;
import com.sparrowwallet.drongo.Utils;
import com.sparrowwallet.drongo.crypto.ChildNumber;
@@ -12,14 +10,12 @@
import com.sparrowwallet.drongo.protocol.Sha256Hash;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.AppServices;
+import com.sparrowwallet.tern.http.client.HttpResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
@@ -108,43 +104,37 @@ public String getLoginMessage() {
}
}
- public void sendResponse(Wallet wallet) throws LnurlAuthException, IOException {
+ public void sendResponse(Wallet wallet) throws Exception {
URL callback = getReturnURL(wallet);
if(log.isInfoEnabled()) {
log.info("Sending LNURL-auth response to " + callback);
}
- Proxy proxy = AppServices.getProxy();
- if(proxy == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX)) {
+ HttpClientService httpClientService = AppServices.getHttpClientService();
+ if(httpClientService.getTorProxy() == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX)) {
throw new LnurlAuthException("A Tor proxy must be configured to authenticate this resource.");
}
- HttpURLConnection connection = proxy == null ? (HttpURLConnection) callback.openConnection() : (HttpURLConnection) callback.openConnection(proxy);
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type", "application/json");
-
- StringBuilder res = new StringBuilder();
- try(BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
- String responseLine;
- while((responseLine = br.readLine()) != null) {
- res.append(responseLine.trim());
- }
+ Map<?, ?> result;
+ try {
+ result = httpClientService.requestJson(callback.toString(), Map.class, null);
+ } catch(HttpResponseException e) {
+ throw new LnurlAuthException("Service returned HTTP " + e.getStatusCode() + ": " + e.getResponseBody());
}
if(log.isDebugEnabled()) {
- log.debug("Received from " + callback + ": " + res);
+ log.debug("Received from " + callback + ": " + result);
}
- JsonObject result = JsonParser.parseString(res.toString()).getAsJsonObject();
- String status = result.get("status").getAsString();
+ Object status = result.get("status");
if("OK".equals(status)) {
return;
} else if("ERROR".equals(status)) {
- String reason = result.get("reason").getAsString();
+ Object reason = result.get("reason");
throw new LnurlAuthException("Service returned error: " + reason);
} else {
- throw new LnurlAuthException("Service returned unknown response: " + res);
+ throw new LnurlAuthException("Service returned unknown response: " + result);
}
}
Why this scored 38/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.