refuse to sign a paynym authentication token in another format
What changed, and why it matters
This commit adds a safety check so that Sparrow Wallet will refuse to sign a PayNym authentication token if it looks like a web link (for example, starting with 'auth47://' or 'https://'). Before this change, the wallet might have signed such a token, which could potentially let an attacker trick the user into signing a message that authorizes something on a website instead of a simple PayNym token. The change is defensive and includes tests to confirm the new behavior.
Users should upgrade to a Sparrow Wallet version that includes this commit. Developers should review whether other signing entry points enforce similar format restrictions and consider whether the check should be applied consistently across all message-signing flows.
Security signals we found
Input validation added to cryptographic signing function
Rejection of URI-scheme formatted authentication tokens
New unit tests covering both allowed and rejected token formats
Defensive hardening against cross-protocol signing confusion
Evidence from the diff
PayNymService.getSignature() now rejects any authToken that starts with the Auth47 URI scheme (case-insensitive) or contains ‘://’. This prevents the wallet from signing tokens formatted as Auth47 or generic URIs. The patch imports Auth47 to reference its SCHEME constant and adds unit tests verifying that plain tokens are signed while auth47://, AUTH47:, and https:// tokens throw IllegalArgumentException.
Changed components
src/main/java/com/sparrowwallet/sparrow/paynym/PayNymService.javasrc/test/java/com/sparrowwallet/sparrow/paynym/PayNymServiceTest.javaInspect captured patch +46 / −0
### src/main/java/com/sparrowwallet/sparrow/paynym/PayNymService.java
@@ -9,6 +9,7 @@
import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.AppServices;
+import com.sparrowwallet.sparrow.net.Auth47;
import io.reactivex.Observable;
import io.reactivex.rxjavafx.schedulers.JavaFxScheduler;
import io.reactivex.schedulers.Schedulers;
@@ -18,6 +19,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
@@ -249,6 +251,10 @@ public static Observable<Map<String, Object>> updateToken(Wallet wallet) {
}
public static String getSignature(Wallet wallet, String authToken) {
+ if(authToken.toLowerCase(Locale.ROOT).startsWith(Auth47.SCHEME + ":") || authToken.contains("://")) {
+ throw new IllegalArgumentException("Invalid PayNym authentication token");
+ }
+
Wallet masterWallet = wallet.isMasterWallet() ? wallet : wallet.getMasterWallet();
Keystore keystore = masterWallet.getKeystores().get(0);
List<ChildNumber> derivation = keystore.getKeyDerivation().getDerivation();
### src/test/java/com/sparrowwallet/sparrow/paynym/PayNymServiceTest.java
@@ -0,0 +1,40 @@
+package com.sparrowwallet.sparrow.paynym;
+
+import com.sparrowwallet.drongo.crypto.ChildNumber;
+import com.sparrowwallet.drongo.policy.Policy;
+import com.sparrowwallet.drongo.policy.PolicyType;
+import com.sparrowwallet.drongo.protocol.ScriptType;
+import com.sparrowwallet.drongo.wallet.DeterministicSeed;
+import com.sparrowwallet.drongo.wallet.Keystore;
+import com.sparrowwallet.drongo.wallet.Wallet;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class PayNymServiceTest {
+ static Wallet getWallet() throws Exception {
+ DeterministicSeed seed = new DeterministicSeed("reward upper indicate eight swift arch injury crystal super wrestle already dentist", "", 0, DeterministicSeed.Type.BIP39);
+ Wallet wallet = new Wallet();
+ wallet.setPolicyType(PolicyType.SINGLE_HD);
+ wallet.setScriptType(ScriptType.P2WPKH);
+ wallet.getKeystores().add(Keystore.fromSeed(seed, PolicyType.SINGLE_HD, List.of(new ChildNumber(84, true), ChildNumber.ZERO_HARDENED, ChildNumber.ZERO_HARDENED)));
+ wallet.setDefaultPolicy(Policy.getPolicy(PolicyType.SINGLE_HD, ScriptType.P2WPKH, wallet.getKeystores(), 1));
+ return wallet;
+ }
+
+ @Test
+ public void signsAuthToken() throws Exception {
+ assertFalse(PayNymService.getSignature(getWallet(), "a2b4c6d8e0f1").isEmpty());
+ }
+
+ @Test
+ public void refusesTokenInAnotherFormat() throws Exception {
+ Wallet wallet = getWallet();
+ assertThrows(IllegalArgumentException.class, () -> PayNymService.getSignature(wallet, "auth47://a2b4c6d8e0f1?r=https://example.com"));
+ assertThrows(IllegalArgumentException.class, () -> PayNymService.getSignature(wallet, "AUTH47:a2b4c6d8e0f1"));
+ assertThrows(IllegalArgumentException.class, () -> PayNymService.getSignature(wallet, "https://example.com"));
+ }
+}Why this scored 61/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.