What changed, and why it matters
This commit fixes UI bugs in Stack Wallet's multi-recipient send screen. The changes make payment-request names display more safely (so a malicious name can't be confused with a trusted contact label), ensure payment-request messages are actually used, and add several 'mounted' checks to prevent crashes when a user navigates away during QR scanning or clipboard access. The patch is defensive and improves security posture, but it is a partial UI fix rather than a complete elimination of all related risks.
Review the remaining places where payment-request data is rendered to ensure similar spoofing mitigations are applied consistently across the app. Verify that multi-recipient URI messages are handled (currently the diff only wires onMessage for single-recipient URIs). Continue the mounted-check audit for other async UI callbacks in send flows.
Security signals we found
UI spoofing mitigation: payment-request names are visually distinguished from user/address-book labels
Sanitization of payment-request names: whitespace and Unicode control/format characters collapsed to a single space
Missing data handling: tx_description/message from BIP21-style URIs now propagated to note field
Async lifecycle safety: added mounted checks after awaits before setState/dialog usage
Centralized payment-URI detection heuristic in AddressUtils.mayBePaymentUri
Test coverage added for name replacement, message passing, and control-character display
Evidence from the diff
The diff updates the send/recipient UI across Frost multisig, mobile, and desktop flows. Key changes: (1) Payment-request labels are now shown with the explicit prefix ‘Name in payment request:’ via a new PaymentRequestName widget, and whitespace/control characters are collapsed, mitigating UI spoofing where a request name could be mistaken for an address-book label. (2) A new onMessage callback propagates tx_description/message fields from single-recipient payment URIs into the transaction note, which previously were silently dropped. (3) AddressUtils.mayBePaymentUri centralizes the heuristic for pasted/payment-URI detection. (4) Several async gaps now guard with if (!mounted) return before setState or dialog use. (5) Tests are added/updated for name replacement, message propagation, and one-line display.
Changed components
lib/pages/send_view/frost_ms/frost_send_view.dartlib/pages/send_view/frost_ms/recipient.dartlib/pages/send_view/send_view.dartlib/pages/send_view/sub_widgets/multi_recipient.dartlib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dartlib/utilities/address_utils.dartInspect captured patch +213 / −31
### lib/pages/send_view/frost_ms/frost_send_view.dart
@@ -413,6 +413,9 @@ class _FrostSendViewState extends ConsumerState<FrostSendView> {
ref.read(pWalletBalance(walletId)).spendable,
);
},
+ onMessage: (message) => setState(() {
+ noteController.text = message;
+ }),
),
),
],
### lib/pages/send_view/frost_ms/recipient.dart
@@ -55,6 +55,7 @@ class Recipient extends ConsumerStatefulWidget {
required this.addAnotherRecipientTapped,
required this.sendAllTapped,
this.onMultiRecipientUri,
+ this.onMessage,
});
final String walletId;
@@ -71,6 +72,10 @@ class Recipient extends ConsumerStatefulWidget {
/// which are rejected if this is null.
final void Function(PaymentUriData paymentData)? onMultiRecipientUri;
+ /// Called with the message of a scanned or pasted payment request for this
+ /// recipient alone, which otherwise goes unused.
+ final void Function(String message)? onMessage;
+
@override
ConsumerState<Recipient> createState() => _RecipientState();
}
@@ -86,7 +91,7 @@ class _RecipientState extends ConsumerState<Recipient> {
RecipientId get _id => (walletId: widget.walletId, index: widget.index);
- void _updateRecipientData({String? label}) {
+ void _updateRecipientData({String? label, bool replaceLabel = false}) {
final address = addressController.text;
final amount = ref
.read(pAmountFormatter(widget.coin))
@@ -96,8 +101,11 @@ class _RecipientState extends ConsumerState<Recipient> {
ref.read(pRecipient(_id).notifier).state = (
address: address,
amount: amount,
- // A payment request's name only applies to the address it gave.
- label: label ?? (previous?.address == address ? previous?.label : null),
+ // Importing a new request replaces its name, including an absent one.
+ // Ordinary edits keep the name only while the address stays the same.
+ label: replaceLabel
+ ? label
+ : (previous?.address == address ? previous?.label : null),
);
widget.onChanged?.call();
}
@@ -144,7 +152,14 @@ class _RecipientState extends ConsumerState<Recipient> {
setState(() {
_addressIsEmpty = addressController.text.isEmpty;
});
- _updateRecipientData(label: paymentData.label);
+ final label = paymentData.label?.trim();
+ _updateRecipientData(
+ label: label == null || label.isEmpty ? null : label,
+ replaceLabel: true,
+ );
+ if (paymentData.message != null) {
+ widget.onMessage?.call(paymentData.message!);
+ }
} else {
if (addressController.text != input) {
addressController.text = input;
@@ -194,9 +209,9 @@ class _RecipientState extends ConsumerState<Recipient> {
FocusScope.of(context).unfocus();
await Future<void>.delayed(const Duration(milliseconds: 75));
}
+ if (!mounted) return;
if (Util.isDesktop) {
- if (!mounted) return;
final qrCodeData = await showDialog<String>(
context: context,
builder: (context) => const QrCodeScannerDialog(),
@@ -311,9 +326,7 @@ class _RecipientState extends ConsumerState<Recipient> {
children: [
Flexible(
child: Text(
- isSingle
- ? "Send to"
- : label ?? "Recipient ${widget.displayNumber}",
+ isSingle ? "Send to" : "Recipient ${widget.displayNumber}",
style: STextStyles.smallMed12(context),
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
@@ -327,6 +340,10 @@ class _RecipientState extends ConsumerState<Recipient> {
),
],
),
+ if (label != null) ...[
+ const SizedBox(height: 4),
+ PaymentRequestName(label),
+ ],
const SizedBox(height: 8),
ClipRRect(
borderRadius: BorderRadius.circular(
@@ -342,9 +359,7 @@ class _RecipientState extends ConsumerState<Recipient> {
style: STextStyles.field(context),
onChanged: (newValue) {
final previous = ref.read(pRecipient(_id))?.address ?? "";
- // More than one character at once was pasted, and may be a
- // payment request.
- if ((newValue.length - previous.length).abs() > 1) {
+ if (AddressUtils.mayBePaymentUri(newValue, previous)) {
_applyAddressInput(newValue.trim());
return;
}
@@ -399,6 +414,7 @@ class _RecipientState extends ConsumerState<Recipient> {
final ClipboardData? data = await ref
.read(pClipboard)
.getData(Clipboard.kTextPlain);
+ if (!mounted) return;
if (data?.text != null &&
data!.text!.isNotEmpty) {
String content = data.text!.trim();
@@ -518,3 +534,29 @@ class _RecipientState extends ConsumerState<Recipient> {
);
}
}
+
+/// A recipient's name from a payment request, attributed to the request so
+/// it can't pass for a name the app, or the user, gave the address.
+class PaymentRequestName extends StatelessWidget {
+ const PaymentRequestName(this.name, {super.key, this.style});
+
+ final String name;
+
+ /// Defaults to [STextStyles.label].
+ final TextStyle? style;
+
+ @override
+ Widget build(BuildContext context) {
+ // One line of plain text: a line break or a control character in the
+ // name could otherwise put part of it where an app label would be.
+ final shown = name
+ .replaceAll(RegExp(r'[\s\p{Cc}\p{Cf}]+', unicode: true), ' ')
+ .trim();
+ return Text(
+ "Name in payment request: \"$shown\"",
+ style: style ?? STextStyles.label(context),
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
+ );
+ }
+}
### lib/pages/send_view/send_view.dart
@@ -85,10 +85,10 @@ import '../../widgets/textfield_icon_button.dart';
import '../address_book_views/address_book_view.dart';
import '../coin_control/coin_control_view.dart';
import 'confirm_transaction_view.dart';
+import 'frost_ms/recipient.dart';
import 'sub_widgets/building_transaction_dialog.dart';
import 'sub_widgets/dual_balance_selection_sheet.dart';
import 'sub_widgets/epic_slatepack_dialog.dart';
-import 'frost_ms/recipient.dart';
import 'sub_widgets/multi_recipient.dart';
import 'sub_widgets/mwc_slatepack_dialog.dart';
import 'sub_widgets/transaction_fee_selection_sheet.dart';
@@ -482,6 +482,7 @@ class _SendViewState extends ConsumerState<SendView> {
FocusScope.of(context).unfocus();
await Future<void>.delayed(const Duration(milliseconds: 75));
}
+ if (!mounted) return;
final qrResult = await ref.read(pBarcodeScanner).scan(context: context);
@@ -495,7 +496,7 @@ class _SendViewState extends ConsumerState<SendView> {
// );
Logging.instance.d("qrResult content: ${qrResult.rawContent}");
- if (qrResult.rawContent == null) return;
+ if (qrResult.rawContent == null || !mounted) return;
final paymentData = AddressUtils.parsePaymentUri(
qrResult.rawContent!,
@@ -1945,6 +1946,9 @@ class _SendViewState extends ConsumerState<SendView> {
onAdd: _addRecipientForm,
onRemove: _removeRecipientForm,
onMultiRecipientUri: _replaceMultiRecipients,
+ onMessage: (message) => setState(() {
+ noteController.text = message;
+ }),
),
if (!isPaynymSend &&
!isSlatepackMode &&
@@ -1972,11 +1976,10 @@ class _SendViewState extends ConsumerState<SendView> {
onChanged: (newValue) async {
final trimmed = newValue.trim();
- if ((trimmed.length -
- (_address?.length ?? 0))
- .abs() >
- 1 ||
- trimmed.contains(':')) {
+ if (AddressUtils.mayBePaymentUri(
+ trimmed,
+ _address ?? "",
+ )) {
final parsed =
AddressUtils.parsePaymentUri(
trimmed,
### lib/pages/send_view/sub_widgets/multi_recipient.dart
@@ -117,6 +117,7 @@ class RecipientForms extends StatelessWidget {
required this.onAdd,
required this.onRemove,
required this.onMultiRecipientUri,
+ required this.onMessage,
});
final String walletId;
@@ -129,6 +130,9 @@ class RecipientForms extends StatelessWidget {
final void Function(int index) onRemove;
final void Function(PaymentUriData paymentData) onMultiRecipientUri;
+ /// Called with the message of a payment request for one recipient.
+ final void Function(String message) onMessage;
+
@override
Widget build(BuildContext context) {
return Column(
@@ -150,6 +154,7 @@ class RecipientForms extends StatelessWidget {
// Send all is not offered with several recipients.
sendAllTapped: () => "",
onMultiRecipientUri: onMultiRecipientUri,
+ onMessage: onMessage,
),
),
const SizedBox(height: 16),
@@ -194,17 +199,19 @@ class RecipientAmountList extends ConsumerWidget {
child: Container(height: 1, color: colors.backgroundAppBar),
);
+ final requestNames = labels ?? const <String?>[];
+
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
for (int i = 0; i < recipients.length; i++) ...[
if (i > 0) divider,
- Text(
- (labels != null && i < labels!.length ? labels![i] : null) ??
- "Recipient ${i + 1}",
- style: labelStyle,
- ),
+ Text("Recipient ${i + 1}", style: labelStyle),
+ if (i < requestNames.length && requestNames[i] != null) ...[
+ const SizedBox(height: 4),
+ PaymentRequestName(requestNames[i]!, style: labelStyle),
+ ],
const SizedBox(height: 4),
SelectableText(recipients[i].address, style: valueStyle),
const SizedBox(height: 8),
### lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart
@@ -26,9 +26,9 @@ import '../../../../models/paynym/paynym_account_lite.dart';
import '../../../../models/send_view_auto_fill_data.dart';
import '../../../../notifications/show_flush_bar.dart';
import '../../../../pages/send_view/confirm_transaction_view.dart';
+import '../../../../pages/send_view/frost_ms/recipient.dart';
import '../../../../pages/send_view/sub_widgets/building_transaction_dialog.dart';
import '../../../../pages/send_view/sub_widgets/epic_slatepack_dialog.dart';
-import '../../../../pages/send_view/frost_ms/recipient.dart';
import '../../../../pages/send_view/sub_widgets/multi_recipient.dart';
import '../../../../pages/send_view/sub_widgets/mwc_slatepack_dialog.dart';
import '../../../../pages/send_view/sub_widgets/transaction_fee_selection_sheet.dart';
@@ -165,6 +165,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
context: context,
builder: (context) => const QrCodeScannerDialog(),
);
+ if (!mounted) return;
if (qrResult == null) {
Logging.instance.w("Qr scanning cancelled");
} else {
@@ -2019,6 +2020,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
onAdd: _addRecipientForm,
onRemove: _removeRecipientForm,
onMultiRecipientUri: _replaceMultiRecipients,
+ onMessage: (message) => _note = message,
),
if (!isPaynymSend &&
!((isMimblewimblecoin || isEpiccash) &&
@@ -2049,8 +2051,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
onChanged: (newValue) async {
final trimmed = newValue;
- if ((trimmed.length - (_address?.length ?? 0)).abs() > 1 ||
- trimmed.contains(':')) {
+ if (AddressUtils.mayBePaymentUri(trimmed, _address ?? "")) {
final parsed = AddressUtils.parsePaymentUri(
trimmed,
logging: Logging.instance,
### lib/utilities/address_utils.dart
@@ -188,6 +188,12 @@ class AddressUtils {
];
}
+ /// Whether [input], the new text of an address field whose text was
+ /// [previous], may be a payment URI worth parsing: several characters
+ /// changed at once, as when pasted, or it contains a scheme separator.
+ static bool mayBePaymentUri(String input, String previous) =>
+ (input.length - previous.length).abs() > 1 || input.contains(':');
+
/// Centralized method to handle various cryptocurrency URIs and return a common object.
///
/// Multi-recipient URIs are only returned when [allowMultipleRecipients] is
### test/pages/send_view/frost_ms/recipient_test.dart
@@ -58,6 +58,7 @@ void main() {
late ProviderContainer container;
late List<PaymentUriData> multiRecipientUris;
late _FakeScanner scanner;
+ late List<String> messages;
/// Lays widgets out for desktop or mobile on any host platform.
void useLayout({required bool desktop}) {
@@ -83,6 +84,7 @@ void main() {
unit = StateProvider((_) => AmountUnit.normal);
clipboard = FakeClipboard();
multiRecipientUris = [];
+ messages = [];
container = ProviderContainer(
overrides: [
pAmountUnit.overrideWithProvider(
@@ -142,6 +144,7 @@ void main() {
onMultiRecipientUri: handlesMultiRecipientUris
? multiRecipientUris.add
: null,
+ onMessage: messages.add,
),
),
),
@@ -164,34 +167,104 @@ void main() {
initial: (address: "address0", amount: xmr("1"), label: "Alice"),
);
- expect(find.text("Alice"), findsOneWidget);
+ expect(find.text('Name in payment request: "Alice"'), findsOneWidget);
+ expect(find.text("Recipient 1"), findsOneWidget);
expect(find.text("Invalid address"), findsNothing);
await tester.enterText(addressField(), "bad");
await tester.pump();
- expect(find.text("Alice"), findsNothing);
+ expect(find.text('Name in payment request: "Alice"'), findsNothing);
expect(find.text("Recipient 1"), findsOneWidget);
expect(find.text("Invalid address"), findsOneWidget);
expect(recipient(), (address: "bad", amount: xmr("1"), label: null));
});
+ for (final (name, request, amount) in [
+ ("missing", "monero:address0?tx_amount=2", "2"),
+ ("empty", "monero:address0?tx_amount=2&recipient_name=", "2"),
+ ("whitespace", "monero:address0?tx_amount=2&recipient_name=%20%09%0A", "2"),
+ ("missing without an amount", "monero:address0", "1"),
+ ]) {
+ testWidgets("clears the previous request's name when $name", (
+ tester,
+ ) async {
+ await pumpRecipient(
+ tester,
+ initial: (address: "address0", amount: xmr("1"), label: "Alice"),
+ );
+
+ await tester.enterText(addressField(), request);
+ await tester.pump();
+
+ expect(recipient(), (
+ address: "address0",
+ amount: xmr(amount),
+ label: null,
+ ));
+ expect(text(tester, addressField()), "address0");
+ expect(text(tester, amountField()), amount);
+ expect(find.text('Name in payment request: "Alice"'), findsNothing);
+ expect(find.byType(PaymentRequestName), findsNothing);
+ });
+ }
+
+ testWidgets("replaces the name with the new request's trimmed name", (
+ tester,
+ ) async {
+ await pumpRecipient(
+ tester,
+ initial: (address: "address0", amount: xmr("1"), label: "Alice"),
+ );
+
+ await tester.enterText(
+ addressField(),
+ "monero:address0?recipient_name=%20Bob%20",
+ );
+ await tester.pump();
+
+ expect(recipient(), (address: "address0", amount: xmr("1"), label: "Bob"));
+ expect(find.text('Name in payment request: "Bob"'), findsOneWidget);
+ expect(find.text('Name in payment request: "Alice"'), findsNothing);
+ });
+
+ testWidgets("keeps the request's name when the amount is edited", (
+ tester,
+ ) async {
+ await pumpRecipient(
+ tester,
+ initial: (address: "address0", amount: xmr("1"), label: "Alice"),
+ );
+
+ await tester.enterText(amountField(), "2");
+ await tester.pump();
+
+ expect(recipient(), (
+ address: "address0",
+ amount: xmr("2"),
+ label: "Alice",
+ ));
+ expect(find.text('Name in payment request: "Alice"'), findsOneWidget);
+ });
+
testWidgets("keeps the amount when the display unit changes", (tester) async {
container.read(unit.notifier).state = AmountUnit.milli;
await pumpRecipient(
tester,
- initial: (address: "address0", amount: xmr("1"), label: null),
+ initial: (address: "address0", amount: xmr("1"), label: "Alice"),
);
expect(text(tester, amountField()), "1000");
container.read(unit.notifier).state = AmountUnit.normal;
await tester.pump();
expect(text(tester, amountField()), "1");
+ expect(recipient()!.label, "Alice");
// Editing the recipient afterwards must not read "1000" as XMR.
await tester.enterText(addressField(), "address1");
await tester.pump();
expect(recipient()!.amount, xmr("1"));
+ expect(recipient()!.label, isNull);
});
testWidgets("fills the address, amount, and name from a pasted request", (
@@ -211,7 +284,7 @@ void main() {
expect(text(tester, addressField()), "address5");
expect(text(tester, amountField()), "0.25");
- expect(find.text("Bob"), findsOneWidget);
+ expect(find.text('Name in payment request: "Bob"'), findsOneWidget);
expect(recipient(), (
address: "address5",
amount: xmr("0.25"),
@@ -232,6 +305,50 @@ void main() {
expect(recipient()!.amount, xmr("2"));
});
+ testWidgets("passes a single request's message on", (tester) async {
+ await pumpRecipient(tester);
+
+ await tester.enterText(
+ addressField(),
+ "monero:address5?tx_amount=2&tx_description=Lunch",
+ );
+ await tester.pump();
+
+ expect(messages, ["Lunch"]);
+ expect(recipient()!.address, "address5");
+ });
+
+ testWidgets("shows a request's name on one line", (tester) async {
+ await pumpRecipient(
+ tester,
+ initial: (
+ address: "address0",
+ amount: xmr("1"),
+ label: "Alice\"\nYour wallet (change)\u202E",
+ ),
+ );
+
+ expect(find.text("Recipient 1"), findsOneWidget);
+ expect(
+ find.text('Name in payment request: "Alice" Your wallet (change)"'),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets("parses a typed request of the same length as the address", (
+ tester,
+ ) async {
+ await pumpRecipient(
+ tester,
+ initial: (address: "address12", amount: xmr("1"), label: null),
+ );
+
+ await tester.enterText(addressField(), "monero:ab");
+ await tester.pump();
+
+ expect(recipient()!.address, "ab");
+ });
+
const multiRecipientUri =
"monero:address1;address2?tx_amount=1;2&recipient_name=A;B";
@@ -247,6 +364,7 @@ void main() {
await tester.pump();
expect(multiRecipientUris.single.recipients.length, 2);
+ expect(messages, isEmpty);
// The recipient is left as it was until the screen replaces it.
expect(text(tester, addressField()), "address0");
expect(recipient(), (address: "address0", amount: xmr("1"), label: null));
### test/pages/send_view/sub_widgets/multi_recipient_test.dart
@@ -188,7 +188,8 @@ void main() {
),
);
- expect(find.text("Alice"), findsOneWidget);
+ expect(find.text('Name in payment request: "Alice"'), findsOneWidget);
+ expect(find.text("Recipient 1"), findsOneWidget);
expect(find.text("Recipient 2"), findsOneWidget);
expect(find.text("Recipient 3"), findsOneWidget);
expect(find.text("1 XMR"), findsOneWidget);
@@ -223,6 +224,7 @@ void main() {
onAdd: () => added++,
onRemove: removed.add,
onMultiRecipientUri: (_) {},
+ onMessage: (_) {},
),
);
Why this scored 40/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.