Skip to content

wallet: Reject whitespace-only wallet names - #35768

Closed
vicjuma wants to merge 1 commit into
bitcoin:masterfrom
vicjuma:wallet-improve-wallet-name-validation
Closed

vicjuma wants to merge 1 commit into
bitcoin:masterfrom
vicjuma:wallet-improve-wallet-name-validation

Conversation

@vicjuma

@vicjuma vicjuma commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

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$

@DrahtBot

DrahtBot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

No conflicts as of last run.

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/29873844736/job/88871531263
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.

Hints

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.

@vicjuma
vicjuma force-pushed the wallet-improve-wallet-name-validation branch from a530752 to 203efb1 Compare July 22, 2026 10:01
@maflcko

maflcko commented Jul 22, 2026 •

Copy link
Copy Markdown
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 ~0 for a risky change without any benefits.

@vicjuma

vicjuma commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

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.

@vicjuma

vicjuma commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

IMO, I do not see the difference between and

@maflcko

maflcko commented Jul 22, 2026

Copy link
Copy Markdown
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?

@vicjuma

vicjuma commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

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

@achow101

Copy link
Copy Markdown
Member

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

This PR trims wallet names using util::TrimStringView before the empty check,
across all call sites that currently guard against empty wallet names
@vicjuma
vicjuma force-pushed the wallet-improve-wallet-name-validation branch from 203efb1 to 8464a0e Compare July 22, 2026 21:02
@vicjuma

vicjuma commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

@frankomosh frankomosh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are non-ASCII covered by TrimStringView? Or should they even matter in this case?

@vicjuma

vicjuma commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Are non-ASCII covered by TrimStringView? Or should they even matter in this case?

TrimStringView() (util/string.h:L162C103) checks for whitespace patterns (6 whitespace characters to be specific).

@polespinasa

Copy link
Copy Markdown
Member

I think if we are doing this we should disable any white-space beginning or ending a wallet name.

Valid cases:

  • "this is a valid wallet name"

Invalid cases:

  • " "
  • " wallet name"
  • "wallet name "
  • " wallet name "

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

@vicjuma

vicjuma commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

I think if we are doing this we should disable any white-space beginning or ending a wallet name.

Valid cases:

  • "this is a valid wallet name"

Invalid cases:

  • " "
  • " wallet name"
  • "wallet name "
  • " wallet name "

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

@maflcko

maflcko commented Aug 26, 2026

Copy link
Copy Markdown
Member

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.

Sorry for bike-shedding this, but if this was the motivation, what about:

  • wallet a name
  • wallet aaaaaaaaaaaaaaaaaaaaaaaaaaa name

Should they be invalid as well? Again, no objection. I am just curios what the real motivation here is. Also, this currently code-conflicts with #35833.

@polespinasa

polespinasa commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Will take a look to #35833.

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

About the "... aaaaaaaaaaaaaaaa ..." I think that is fine as those are "visible" characters, but that is just an opinion, obviously still ugly.

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

@vicjuma

vicjuma commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

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.

@sedited

sedited commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

There still seems to be no conceptual buy in here and there hasn't been any activity for more than a month. Given the number of pull requests, and limited review resources, maybe this should be closed for now due to lack of interest?

@polespinasa

Copy link
Copy Markdown
Member

I agree in closing this and opening an issue to discuss if we care about this "weird" names.

@vicjuma

vicjuma commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Agreed @sedited

@sedited sedited closed this Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants