mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
wallet: Reject whitespace-only wallet names #35768
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35768
Loading…
Reference in a new issue
No description provided.
Delete branch "wallet-improve-wallet-name-validation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
util::TrimStringView;has been preferred as opposed toutil::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:
After:
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.
🚧 At least one of the CI tasks failed.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/29873844736/job/88871531263LLM reason (✨ experimental): CI failed because the Python lint checks reported trailing/blank-line whitespace in
test/functional/tool_wallet.py(ruff W293 / trailing_whitespace), causingpy_lintto 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.
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.
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 withTrimStringViewinstead ofTrimString. 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
the above is totally valid, and it is saved as such. The one below is, however, rejected because it contains only spaces
NB: I doubt whether someone would resort to the latter.IMO, I do not see the difference between
andI 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 timeTrimStringView(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 overlookingIt'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 thesrc/wallet/dump.cpp:124:bool CreateFromDumphowever, meaning that a wallet will have to be imported into a properly named wallet. If otherwise, I can revert it too.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).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.
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.
Sorry for bike-shedding this, but if this was the motivation, what about:
wallet a namewallet aaaaaaaaaaaaaaaaaaaaaaaaaaa nameShould 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.
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.
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.
Base:
66776840beb558f7e84451c2c55457f0e06242f0Head:
8464a0e37ae28bfebf105404996762a8237738dc🟡 Minor
Restore still accepts whitespace-only wallet names (src/wallet/wallet.cpp:389, head)
CreateWalletrejects whitespace-only names, butRestoreWalletchecks onlywallet_name.empty()whenallow_unnamedis false. TherestorewalletRPC and interface restore caller use that default. With a valid backup and an available destination,RestoreWalletuses the whitespace-only name to create the destination and copy the wallet there. Apply the trimmed-view check to named restores while preserving theallow_unnamedmigration case.💡 Suggestion
Check that whitespace-named destinations are absent (test/functional/tool_wallet.py:436, head)
The whitespace-name cases pass
-wallet=but checkwallets_path / "wallet.dat", not the requested destination. The current guards return before creating a wallet, but these assertions would miss a regression that createdwallets_path / " "and then returned the expected error. Assert that the whitespace-named destination does not exist after each rejection.Review coverage was incomplete. The adversarial_glm review did not complete.
Full review report
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?
I agree in closing this and opening an issue to discuss if we care about this "weird" names.
Agreed @sedited