fix(input): strip Unicode/CJK whitespace across address, key, and URL inputs

Follow-up to the key-import fix: an audit found the same ASCII-only-trim pattern
across the input layer, where a pasted value carrying CJK full-width (U+3000),
NBSP, zero-width, or BOM whitespace survived trimming and then failed validation
or an RPC. Most paths failed closed (same value validated and acted on → "won't
work" rather than a wrong send), but several mattered — above all the Lite
Import Key path, the exact recurrence of the reported bug on the Lite variant.

Single-token inputs (keys, addresses, URLs) now go through
util::stripAllWhitespaceForKey; path/label inputs use the new
util::trimUnicodeWhitespace (edge-trim, preserves internal spaces):

- Lite Import Key (settings_page) — strip-all before importKeyAsync. [fund recovery]
- Lite wallet path (open/restore) — edge-trim the request path AND the empty gate
  (they had diverged: gate trimmed, request used raw).
- Contacts — gate on and save the cleaned label/address; clean on paste; an
  address never persists with stray whitespace (which silently broke every later
  use + defeated duplicate detection).
- Send recipient — strip-all on paste and on field edit, so a CJK-pasted valid
  address validates and sends.
- Chat new-conversation z-address — validate and send the cleaned value.
- Chat restore-by-address — strip-all (the old trim even missed '\r'), so a
  padded address matches the deleted list instead of broadcasting a junk memo.
- Mining pool URL + payout — strip-all at persist and in the payout check.
- Validate-address dialog — strip-all before classify.
- Lite custom server URL — strip-all; its label edge-trimmed.
- Payment URI — strip-all the parsed address.
- Defense-in-depth: importPrivateKey / sweepPrivateKey strip-all the key;
  importWalletFile edge-trims the path.

Adds trimUnicodeWhitespace coverage to testKeyInputSanitization. Build + tests +
hygiene green. (Deferred, noted for follow-up: the console tokenizer treating
Unicode whitespace as a separator, and repairing already-polluted address-book
entries on load.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 12:11:54 -06:00
co-authored by Claude Opus 4.8
parent 0a957e9555
commit 6bb72f9878
16 changed files with 411 additions and 69 deletions
+11 -7
View File
@@ -200,13 +200,10 @@ static void DrawTxIcon(ImDrawList* dl, const std::string& type,
static void PasteClipboardToAddress() {
const char* clipboard = ImGui::GetClipboardText();
if (clipboard) {
std::string trimmed(clipboard);
while (!trimmed.empty() && (trimmed.front() == ' ' || trimmed.front() == '\t' ||
trimmed.front() == '\n' || trimmed.front() == '\r'))
trimmed.erase(trimmed.begin());
while (!trimmed.empty() && (trimmed.back() == ' ' || trimmed.back() == '\t' ||
trimmed.back() == '\n' || trimmed.back() == '\r'))
trimmed.pop_back();
// An address is a single token — strip ALL whitespace (ASCII + Unicode), so a clipboard carrying a
// trailing full-width/zero-width space (common from CJK apps) doesn't land a "valid" address that
// then fails validation and blocks Send.
const std::string trimmed = dragonx::util::stripAllWhitespaceForKey(clipboard);
snprintf(s_to_address, sizeof(s_to_address), "%s", trimmed.c_str());
}
}
@@ -1454,6 +1451,13 @@ void RenderSendTab(App* app)
bool paste_hovered = false;
ImGui::InputText("##ToAddr", s_to_address, sizeof(s_to_address));
// Clean the field once the user finishes typing/Ctrl+V — an address is a single token, so strip
// all whitespace (incl. CJK full-width / zero-width characters) so validation and Send agree on
// a clean recipient instead of silently blocking Send over an invisible stray character.
if (ImGui::IsItemDeactivatedAfterEdit()) {
const std::string c = dragonx::util::stripAllWhitespaceForKey(s_to_address);
snprintf(s_to_address, sizeof(s_to_address), "%s", c.c_str());
}
// Capture input rect for preview overlay
ImVec2 inputMin = ImGui::GetItemRectMin();
ImGui::PopItemWidth();