wallet: Reject whitespace-only wallet names #35768

pull vicjuma wants to merge 1 commits into bitcoin:master from vicjuma:wallet-improve-wallet-name-validation changing 5 files +15 −3
  1. vicjuma commented at 10:27 PM on July 21, 2026: none

    Summary

    This PR trims wallet names using util::TrimStringView before the empty check, across all call sites that currently guard against empty wallet names

    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.

    bitcoin-cli createwallet "    "
    

    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.

    Testing

    Before:

    ratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$ ./bitcoin-cli createwallet "                            "
    {
      "name": "                            "
    }
    ratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$ ls ~/.bitcoin/regtest/wallets/
     '                        '   '                           '   '                            '
    ratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$ 
    

    After:

    ratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli createwallet "                    "
    error code: -8
    error message:
    Wallet name cannot be empty
    ratedg@0xratedg:~/Desktop/bitcoin/build/bin$
    
  2. DrahtBot added the label Wallet on Jul 21, 2026
  3. DrahtBot commented at 10:27 PM on July 21, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35768.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept NACK maflcko

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. DrahtBot added the label CI failed on Jul 22, 2026
  5. DrahtBot commented at 9:33 AM on July 22, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task lint: https://github.com/bitcoin/bitcoin/actions/runs/29873844736/job/88871531263</sub> <sub>LLM reason (✨ experimental): CI failed because the Python lint checks reported trailing/blank-line whitespace in test/functional/tool_wallet.py (ruff W293 / trailing_whitespace), causing py_lint to exit non-zero.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  6. vicjuma force-pushed on Jul 22, 2026
  7. DrahtBot removed the label CI failed on Jul 22, 2026
  8. maflcko commented at 12:25 PM on July 22, 2026: member

    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.

    So NACK for a risky change without any benefits.

  9. vicjuma commented at 12:46 PM on July 22, 2026: none

    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.

    So NACK for a risky change without any benefits.

    Thanks 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.

    Please note that the PR is not trimming the user inputs

    ratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli createwallet "               testallet               "
    {
      "name": "               testallet               "
    }
    

    the above is totally valid, and it is saved as such. The one below is, however, rejected because it contains only spaces

    ratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli createwallet "                              "
    error code: -8
    error message:
    Wallet name cannot be empty
    ratedg@0xratedg:~/Desktop/bitcoin/build/bin$ 
    

    NB: I doubt whether someone would resort to the latter.

  10. vicjuma commented at 12:49 PM on July 22, 2026: none

    IMO, I do not see the difference between and

  11. maflcko commented at 1:26 PM on July 22, 2026: member

    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.

    I don't know if a user exists with a space-only wallet, but breaking the UX for them for no reason seems pointless?

  12. vicjuma commented at 1:43 PM on July 22, 2026: none

    I don't know if a user exists with a space-only wallet, but breaking the UX for them for no reason seems pointless?

    Does 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

  13. achow101 commented at 7:50 PM on July 22, 2026: member

    It's reasonable to disallow such names when creating a new wallet, but still allow existing wallets to be loaded.

  14. wallet: Reject whitespace-only wallet names
    This PR trims wallet names using util::TrimStringView before the empty check,
    across all call sites that currently guard against empty wallet names
    8464a0e37a
  15. vicjuma force-pushed on Jul 22, 2026
  16. vicjuma commented at 9:06 PM on July 22, 2026: none

    It's reasonable to disallow such names when creating a new wallet, but still allow existing wallets to be loaded.

    I 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.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-07-25 09:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me