{
 "number": 35768,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/35768",
 "title": "wallet: Reject whitespace-only wallet names",
 "author": "vicjuma",
 "author_association": "CONTRIBUTOR",
 "created_at": "2026-07-21T22:27:34Z",
 "updated_at": "2026-09-16T19:58:50Z",
 "age_days": 57,
 "draft": false,
 "labels": [
  "Wallet"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "8464a0e37ae28bfebf105404996762a8237738dc",
 "head_ref": "wallet-improve-wallet-name-validation",
 "head_repo": "vicjuma/bitcoin",
 "head_history": [
  {
   "t": "2026-07-22T10:01:41Z",
   "sha": "203efb1a42c5e5fabafeca7fe4a77f50b637cb55"
  },
  {
   "t": "2026-07-22T21:02:03Z",
   "sha": "8464a0e37ae28bfebf105404996762a8237738dc"
  }
 ],
 "additions": 15,
 "deletions": 3,
 "changed_files": 5,
 "commit_count": 1,
 "size_bucket": "S",
 "mergeable_state": "clean",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {},
   "conflicts": [
    {
     "number": 35833,
     "title": "log: prevent user input from injecting fake log lines",
     "author": "l0rinc"
    }
   ]
  }
 },
 "acks_parsed": {},
 "acks_tally": {
  "ack": 0,
  "stale_ack": 0,
  "concept_ack": 0,
  "approach_ack": 0,
  "nack": 0,
  "concept_nack": 0,
  "approach_nack": 0
 },
 "reviews": {
  "approved": 0,
  "changes_requested": 0,
  "distinct_reviewers": [
   "achow101",
   "frankomosh",
   "maflcko",
   "polespinasa"
  ]
 },
 "signals": {
  "needs_rebase": false,
  "ci_failed": false,
  "mergeable_state": "clean",
  "last_author_activity": "2026-08-26T08:07:53Z",
  "last_reviewer_activity": "2026-08-26T08:06:18Z",
  "last_reviewer": "polespinasa",
  "author_silent_days": 22,
  "waiting_on_author_days": 0,
  "days_since_update": 0
 },
 "refs": {
  "mentioned": [
   35833
  ],
  "depends_on": [],
  "fixes": [],
  "linked_issues": [],
  "references": [
   {
    "number": 35833,
    "type": "pull",
    "state": "open",
    "merged": false,
    "merged_at": null,
    "title": "log: prevent user input from injecting fake log lines"
   }
  ],
  "conflicts": [
   35833
  ]
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [],
 "body": "### Summary\nThis PR trims wallet names using util::TrimStringView before the empty check, across all call sites that currently guard against empty wallet names\n\n**Motivation:** Although there is a check against empty wallet names, it does not reject wallet names consisting solely of whitespace. As a result, the RPC command below succeeds and creates a wallet with a whitespace-only name. Such names are not meaningful and are effectively indistinguishable from nameless directories to users, so they should be rejected in the same way as empty wallet names.\n\n```sh\nbitcoin-cli createwallet \"    \"\n```\n`util::TrimStringView;` has been preferred as opposed to `util::TrimString;` to prevent mutating the user input but guarding against space-only names. This means that the wallet name can have leading and trailing white space unless requested otherwise.\n\n### Testing\n**Before:**\n```sh\nratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$ ./bitcoin-cli createwallet \"                            \"\n{\n  \"name\": \"                            \"\n}\nratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$ ls ~/.bitcoin/regtest/wallets/\n '                        '   '                           '   '                            '\nratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$\n```\n\n**After:**\n```sh\nratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli createwallet \"                    \"\nerror code: -8\nerror message:\nWallet name cannot be empty\nratedg@0xratedg:~/Desktop/bitcoin/build/bin$\n```",
 "commits": [
  {
   "sha": "8464a0e37ae28bfebf105404996762a8237738dc",
   "date": "2026-07-22T20:59:05Z",
   "message": "wallet: Reject whitespace-only wallet names\n\nThis PR trims wallet names using util::TrimStringView before the empty check,\nacross all call sites that currently guard against empty wallet names"
  }
 ],
 "timeline": [
  {
   "t": "2026-07-22T10:01:41Z",
   "kind": "force_push",
   "who": "vicjuma",
   "commit": "203efb1a42c5e5fabafeca7fe4a77f50b637cb55"
  },
  {
   "t": "2026-07-22T12:25:29Z",
   "kind": "comment",
   "who": "maflcko",
   "assoc": "MEMBER",
   "text": "What is the benefit here? Seems highly risky, because it could mean that a pre-existing wallet name that is nested in whitespace could possibly not be loaded/restored/dumped/etc.\n\nSo ~0 for a risky change without any benefits."
  },
  {
   "t": "2026-07-22T12:46:19Z",
   "kind": "comment",
   "who": "vicjuma",
   "assoc": "CONTRIBUTOR",
   "text": "[quoted text omitted]\n\nThanks for the feedback. My motivation was to prevent wallet names that consist solely of whitespace, since they can be confusing to users and difficult to distinguish in the UI or when passed through the RPC interface. For instance, a user creates a wallet with 2 spaces`  `, 3 spaces `   `, and 4 spaces`    `, which results in a very confusing directory structure. That is why I approached it with `TrimStringView`  instead of `TrimString`. I would humbly like to understand whether there are use cases where a wallet name consisting only of whitespace would be intentionally created or relied upon.\n\nPlease note that the PR is not trimming the user inputs\n\n```txt\nratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli createwallet \"               testallet               \"\n{\n  \"name\": \"               testallet               \"\n}\n```\n\nthe above is totally valid, and it is saved as such. The one below is, however, rejected because it contains only spaces\n\n```txt\nratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli createwallet \"                              \"\nerror code: -8\nerror message:\nWallet name cannot be empty\nratedg@0xratedg:~/Desktop/bitcoin/build/bin$\n```\n`NB: I doubt whether someone would resort to the latter.`"
  },
  {
   "t": "2026-07-22T12:49:44Z",
   "kind": "comment",
   "who": "vicjuma",
   "assoc": "CONTRIBUTOR",
   "text": "IMO, I do not see the difference between ` ` and `       `"
  },
  {
   "t": "2026-07-22T13:26:08Z",
   "kind": "comment",
   "who": "maflcko",
   "assoc": "MEMBER",
   "text": "[quoted text omitted]\n\nI don't know if a user exists with a space-only wallet, but breaking the UX for them for no reason seems pointless?"
  },
  {
   "t": "2026-07-22T13:43:46Z",
   "kind": "comment",
   "who": "vicjuma",
   "assoc": "CONTRIBUTOR",
   "text": "[quoted text omitted]\n\nDoes it break the UX? The check was there already `name.empty()` only this time `TrimStringView(name).empty())`. I'm genuinely trying to understand how this change could negatively impact the user experience. I'd really appreciate any examples or scenarios I may be overlooking"
  },
  {
   "t": "2026-07-22T19:50:54Z",
   "kind": "comment",
   "who": "achow101",
   "assoc": "MEMBER",
   "text": "It's reasonable to disallow such names when creating a new wallet, but still allow existing wallets to be loaded."
  },
  {
   "t": "2026-07-22T21:02:03Z",
   "kind": "force_push",
   "who": "vicjuma",
   "commit": "8464a0e37ae28bfebf105404996762a8237738dc"
  },
  {
   "t": "2026-07-22T21:06:07Z",
   "kind": "comment",
   "who": "vicjuma",
   "assoc": "CONTRIBUTOR",
   "text": "[quoted text omitted]\n\nI have restored the `src/wallet/wallet.cpp:458::RestoreWallet`. I have left the `src/wallet/dump.cpp:124:bool CreateFromDump` however, meaning that a wallet will have to be imported into a properly named wallet. If otherwise, I can revert it too."
  },
  {
   "t": "2026-07-28T05:17:19Z",
   "kind": "review",
   "who": "frankomosh",
   "assoc": "CONTRIBUTOR",
   "state": "COMMENTED",
   "commit": "8464a0e37ae28bfebf105404996762a8237738dc",
   "text": "Are non-ASCII covered by TrimStringView? Or should they even matter in this case?"
  },
  {
   "t": "2026-07-28T06:19:55Z",
   "kind": "comment",
   "who": "vicjuma",
   "assoc": "CONTRIBUTOR",
   "text": "[quoted text omitted]\n\n`TrimStringView()` ([util/string.h:L162C103](https://github.com/bitcoin/bitcoin/blob/master/src/util/string.h#L162C103-L162C104)) checks for whitespace patterns (6 whitespace characters to be specific)."
  },
  {
   "t": "2026-08-26T07:48:51Z",
   "kind": "comment",
   "who": "polespinasa",
   "assoc": "MEMBER",
   "text": "I think if we are doing this we should disable any white-space beginning or ending a wallet name.\n\nValid cases:\n- `\"this is a valid wallet name\"`\n\nInvalid cases:\n- `\"                               \"`\n- `\"            wallet name\"`\n- `\"wallet name              \"`\n- `\"            wallet name         \"`\n\nBut this restriction must only be applied in wallet creation to keep backwards compatibility. Also the error message should not be \"empty wallet name\" as that is not the case. Functional tests should be added for each case. And a release note will be necessary for this, affecting the GUI and the RPC interface. I think the motivation for this should be avoid not being able to load the wallet as you cannot easily identify the number of white-spaces that the name has."
  },
  {
   "t": "2026-08-26T07:57:59Z",
   "kind": "comment",
   "who": "vicjuma",
   "assoc": "CONTRIBUTOR",
   "text": "[quoted text omitted]\n\nThis is very helpful @polespinasa . Checking before accepting instead of accepting then trimming without users' knowledge, for your last three example cases i.e. I will work on tests and the release notes."
  },
  {
   "t": "2026-08-26T07:59:26Z",
   "kind": "comment",
   "who": "maflcko",
   "assoc": "MEMBER",
   "text": "[quoted text omitted]\n\nSorry for bike-shedding this, but if this was the motivation, what about:\n\n* `wallet                        a                              name`\n* `wallet aaaaaaaaaaaaaaaaaaaaaaaaaaa name`\n\nShould they be invalid as well? Again, no objection. I am just curios what the real motivation here is. Also, this currently code-conflicts with https://github.com/bitcoin/bitcoin/pull/35833."
  },
  {
   "t": "2026-08-26T08:06:18Z",
   "kind": "comment",
   "who": "polespinasa",
   "assoc": "MEMBER",
   "text": "Will take a look to #35833.\n\nAbout motivation, yeah it is tricky because there can always be weird cases, idk where the line is on what should be able to be done and what not. I only specified white-spaces at the begging and at the end bc they are more likely to be \"invisible\" in some desktop interfaces. But if we care about > 1 white-spaces in between also, we could just forbid more than one white-spaces together if between other characters.\n\nAbout the \"... aaaaaaaaaaaaaaaa ...\" I think that is fine as those are \"visible\" characters, but that is just an opinion, obviously still ugly.\n\nI see it more as a \"mistake\" prevention, in case a user by mistake sets an empty space at the beginning and then he is unable to load the wallet."
  },
  {
   "t": "2026-08-26T08:07:53Z",
   "kind": "comment",
   "who": "vicjuma",
   "assoc": "CONTRIBUTOR",
   "text": "My motivation was to prevent space only wallet names by adding more validation. For backward compatibility achow recommended leaving the loading logic for now. I guess it will be done eventually, hahah. IMO I can't seem to find any justification for allowing such names."
  }
 ],
 "labels_log": [
  {
   "t": "2026-07-21T22:27:38Z",
   "action": "labeled",
   "label": "Wallet",
   "who": "DrahtBot"
  },
  {
   "t": "2026-07-22T09:33:22Z",
   "action": "labeled",
   "label": "CI failed",
   "who": "DrahtBot"
  },
  {
   "t": "2026-07-22T11:07:22Z",
   "action": "unlabeled",
   "label": "CI failed",
   "who": "DrahtBot"
  }
 ],
 "state_log": [],
 "text_chars": 6854,
 "text_tokens_estimate": 1713,
 "changed_paths": [
  "src/wallet/dump.cpp",
  "src/wallet/wallet.cpp",
  "src/wallet/wallettool.cpp",
  "test/functional/tool_wallet.py",
  "test/functional/wallet_createwallet.py"
 ],
 "files": [
  {
   "path": "src/wallet/dump.cpp",
   "add": 3,
   "del": 1
  },
  {
   "path": "src/wallet/wallet.cpp",
   "add": 2,
   "del": 1
  },
  {
   "path": "src/wallet/wallettool.cpp",
   "add": 3,
   "del": 1
  },
  {
   "path": "test/functional/tool_wallet.py",
   "add": 6,
   "del": 0
  },
  {
   "path": "test/functional/wallet_createwallet.py",
   "add": 1,
   "del": 0
  }
 ],
 "test_lines": 7,
 "git": {
  "head": "8464a0e37ae28bfebf105404996762a8237738dc",
  "head_matches_backup": true,
  "base": "a2e074d66ac17ca7907909bbbb563e77185a45e5",
  "commits": [
   {
    "sha": "8464a0e37a",
    "subject": "wallet: Reject whitespace-only wallet names",
    "files": 5,
    "add": 15,
    "del": 3
   }
  ],
  "patch_truncated": false
 },
 "input_hash": "1bc9e8c7802c3da1",
 "extracted_at": "2026-09-17T16:15:31+00:00"
}