apply the wallet name dialog character filter to names suggested by imported wallet files
What changed, and why it matters
This commit fixes a UI ordering bug in Sparrow Wallet's wallet import flow. Previously, when a wallet file suggested a wallet name, the name was put into the text box before the character filter was attached, so dangerous characters like semicolons or backslashes could slip through. The fix simply applies the filter first, then sets the suggested name, so any bad characters are sanitized before the user sees them. A new test confirms that storage rejects names containing punctuation that could be misused.
Review whether any other dialogs or fields set initial text before installing formatters, and ensure the storage layer also validates wallet names independently of UI filtering. Users should upgrade to a release containing this commit if they import wallets from files with names that may contain special characters.
Security signals we found
Input sanitization ordering fix for wallet name derived from imported file
Character filter now covers semicolon and backtick in WalletNameDialog
New unit test explicitly rejects punctuation that could enable path traversal or SQL injection
Potential for stored wallet name to reach database/file layer with unescaped special characters
Evidence from the diff
WalletLabelDialog and WalletNameDialog both create a CustomTextField, previously called setText(initialName) before installing a TextFormatter that replaces filesystem/URL-sensitive characters (\/:*?"<>|;`) with underscores. Because JavaFX TextFormatter only processes subsequent changes, the initial value was not sanitized. The patch moves setText(initialName) after setTextFormatter(…), ensuring imported wallet filenames are filtered. A new DbPersistenceTest#walletNamePunctuation test asserts that names containing ; or \ are rejected by storage and that a benign name with parentheses, comma, hash, ampersand, and period is accepted.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/WalletLabelDialog.javasrc/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.javasrc/test/java/com/sparrowwallet/sparrow/io/DbPersistenceTest.javaInspect captured patch +17 / −2
### src/main/java/com/sparrowwallet/sparrow/control/WalletLabelDialog.java
@@ -44,11 +44,11 @@ public WalletLabelDialog(String initialName, String walletType) {
final VBox content = new VBox(20);
label = (CustomTextField) TextFields.createClearableTextField();
- label.setText(initialName);
label.setTextFormatter(new TextFormatter<>((change) -> {
change.setText(change.getText().replaceAll("[\\\\/:*?\"<>|]", "_"));
return change;
}));
+ label.setText(initialName);
content.getChildren().add(label);
dialogPane.setContent(content);
### src/main/java/com/sparrowwallet/sparrow/control/WalletNameDialog.java
@@ -76,11 +76,11 @@ public WalletNameDialog(String initialName, boolean hasExistingTransactions, Pol
final VBox content = new VBox(20);
name = (CustomTextField)TextFields.createClearableTextField();
- name.setText(initialName);
name.setTextFormatter(new TextFormatter<>((change) -> {
change.setText(change.getText().replaceAll("[\\\\/:*?\"<>|;`]", "_"));
return change;
}));
+ name.setText(initialName);
//The dialog header is the field's only label, so a hidden label names it for screen readers with no visible change
Label nameLabel = new Label("Wallet name");
nameLabel.setLabelFor(name);
### src/test/java/com/sparrowwallet/sparrow/io/DbPersistenceTest.java
@@ -27,6 +27,7 @@
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Comparator;
+import java.util.List;
import java.util.stream.Stream;
public class DbPersistenceTest {
@@ -116,6 +117,20 @@ public void domainRejected() throws Exception {
assertRejected(buildWalletFile("create domain wallet_master.dm as int default 0"));
}
+ @Test
+ public void walletNamePunctuation() throws Exception {
+ for(String walletName : List.of("a;b", "Savings;", "Savings;ıd=1", "Savings;a\\b=1")) {
+ Assertions.assertThrows(StorageException.class, () -> createUnencryptedWallet(walletName), walletName);
+ }
+ try(Stream<Path> paths = Files.list(tempDir)) {
+ Assertions.assertEquals(0, paths.count());
+ }
+
+ Storage storage = createUnencryptedWallet("Savings (old), #2 & co.");
+ storage.closeAndWait();
+ Assertions.assertTrue(storage.getWalletFile().exists());
+ }
+
@Test
public void analyzedWalletWithChildWalletsLoads() throws Exception {
Storage storage = createUnencryptedWallet("Savings");Why this scored 42/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.