fix(openalias): keep the alias when a preview is repeated
What changed, and why it matters
This commit fixes a bug in Stack Wallet's send flow when using OpenAlias (human-readable addresses like alice@example.com that resolve to crypto addresses). Previously, after previewing a transaction, the app replaced the alias with the resolved crypto address in the input field. If the user went back and previewed again, the app would try to re-resolve the now-plain address as if it were an alias, or lose track of the original alias. The fix keeps the alias visible to the user while internally using the resolved address for the transaction, and caches the resolution so repeated previews don't trigger unnecessary or incorrect lookups. There is no direct evidence this was exploitable for theft, but address/alias confusion in a wallet send flow is a sensitive area.
Treat as a defensive correctness fix rather than an active vulnerability. Reviewers should verify that _openAlias is cleared appropriately on send completion and wallet switch, and that the cached resolution cannot be reused across different coins/wallets. Consider whether OpenAlias DNSSEC validation is enforced, since this change does not alter DNS trust assumptions.
Security signals we found
OpenAlias resolution state now cached and reused, reducing window for DNS/lookup spoofing or race conditions
UI no longer overwrites alias input with resolved address, preventing user confusion about what recipient was actually used
Transaction construction now consistently uses a separate resolved recipient address rather than the mutable text field
Potential for address/alias mismatch or stale resolution mitigated by keyed cache check (openAliasKey)
No explicit security advisory, CVE, or vendor security disclosure present in commit or references
Evidence from the diff
The patch changes both mobile (send_view.dart) and desktop (desktop_send.dart) send widgets to store an OpenAliasResolved object (_openAlias) instead of overwriting _address and the text controller with the resolved address. _resolveOpenAlias now returns the full OpenAliasResolved outcome rather than just the alias string. During preview/send, if the entered text is an OpenAlias, the code checks the cached resolution; if the cached alias matches the current input, it reuses the resolved address without re-querying the OpenAlias service. Otherwise it resolves and caches. The actual transaction recipients use recipientAddress (resolved if available, else raw input), while the UI keeps showing the alias. Tests verify repeated previews reuse the alias, edited aliases trigger re-lookup, and adding a recipient after preview carries the resolved address. The change reduces lookup churn and prevents the UI from flipping from alias to raw address after preview.
Changed components
lib/pages/send_view/send_view.dartlib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dartOpenAlias resolution and send preview flowTransaction recipient construction (TxRecipient / sparkRecipients)Inspect captured patch +162 / −44
### lib/pages/send_view/send_view.dart
@@ -152,6 +152,7 @@ class _SendViewState extends ConsumerState<SendView> {
Amount? _cachedAmountToSend;
String? _address;
+ OpenAliasResolved? _openAlias;
/// The [pRecipient] index of each recipient's form while sending to more
/// than one recipient, otherwise null.
@@ -239,8 +240,13 @@ class _SendViewState extends ConsumerState<SendView> {
}
void _addRecipientTapped() {
+ final resolved = _openAlias;
+ final address =
+ resolved != null && resolved.alias == openAliasKey(_address ?? "")
+ ? resolved.address
+ : _address ?? "";
_setMultiRecipients([
- (address: _address ?? "", amount: ref.read(pSendAmount), label: null),
+ (address: address, amount: ref.read(pSendAmount), label: null),
(address: "", amount: null, label: null),
]);
}
@@ -1021,10 +1027,9 @@ class _SendViewState extends ConsumerState<SendView> {
}
}
- /// Replaces the OpenAlias in the address field with the address it resolves
- /// to. Returns the alias, trimmed and lowercased, or null if the lookup
+ /// Looks up the OpenAlias in the address field. Returns null if the lookup
/// failed or was cancelled.
- Future<String?> _resolveOpenAlias(String application) async {
+ Future<OpenAliasResolved?> _resolveOpenAlias(String application) async {
final resolution = ref
.read(pOpenAliasService)
.resolve(
@@ -1053,12 +1058,9 @@ class _SendViewState extends ConsumerState<SendView> {
switch (outcome) {
case OpenAliasCancelled():
return null;
- case OpenAliasResolved(:final alias, :final address):
+ case OpenAliasResolved():
Navigator.of(context, rootNavigator: true).pop();
- sendToController.text = address;
- _address = address;
- _setValidAddressProviders(_address);
- return alias;
+ return outcome;
case OpenAliasFailed(:final title, :final message):
Navigator.of(context, rootNavigator: true).pop();
unawaited(
@@ -1077,13 +1079,21 @@ class _SendViewState extends ConsumerState<SendView> {
await Future<void>.delayed(const Duration(milliseconds: 100));
final wallet = ref.read(pWallets).getWallet(walletId);
String? openAlias;
+ String? resolvedAddress;
final application = coin.openAliasApplication;
if (application != null &&
!coin.validateAddress(_address ?? "") &&
isOpenAlias(_address ?? "")) {
- openAlias = await _resolveOpenAlias(application);
- if (openAlias == null || !mounted) return;
+ var resolved = _openAlias;
+ if (resolved?.alias != openAliasKey(_address!)) {
+ resolved = _openAlias = await _resolveOpenAlias(application);
+ }
+ if (resolved == null || !mounted) return;
+ openAlias = resolved.alias;
+ resolvedAddress = resolved.address;
+ _setValidAddressProviders(resolvedAddress);
}
+ late final recipientAddress = resolvedAddress ?? _address!;
final Amount amount = ref.read(pSendAmount)!;
final Amount availableBalance;
@@ -1227,7 +1237,7 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
sparkRecipients: [
(
- address: _address!,
+ address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
@@ -1246,11 +1256,11 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
recipients: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
@@ -1273,18 +1283,18 @@ class _SendViewState extends ConsumerState<SendView> {
? null
: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
sparkRecipients: ref.read(pValidSparkSendToAddress)
? [
(
- address: _address!,
+ address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
@@ -1303,10 +1313,12 @@ class _SendViewState extends ConsumerState<SendView> {
txData: TxData(
recipients: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
- addressType: wallet.cryptoCurrency.getAddressType(_address!)!,
+ addressType: wallet.cryptoCurrency.getAddressType(
+ recipientAddress,
+ )!,
),
],
openAlias: openAlias,
@@ -1331,11 +1343,11 @@ class _SendViewState extends ConsumerState<SendView> {
_multiRecipients?.toTxRecipients(wallet.cryptoCurrency) ??
[
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
@@ -1445,6 +1457,7 @@ class _SendViewState extends ConsumerState<SendView> {
if (!mounted) {
return;
}
+ _openAlias = null;
sendToController.text = "";
cryptoAmountController.text = "";
baseAmountController.text = "";
### lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart
@@ -139,6 +139,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
Amount? _cachedAmountToSend;
String? _address;
+ OpenAliasResolved? _openAlias;
/// The [pRecipient] index of each recipient's form while sending to more
/// than one recipient, otherwise null.
@@ -440,10 +441,9 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
}
}
- /// Replaces the OpenAlias in the address field with the address it resolves
- /// to. Returns the alias, trimmed and lowercased, or null if the lookup
+ /// Looks up the OpenAlias in the address field. Returns null if the lookup
/// failed or was cancelled.
- Future<String?> _resolveOpenAlias(String application) async {
+ Future<OpenAliasResolved?> _resolveOpenAlias(String application) async {
final resolution = ref
.read(pOpenAliasService)
.resolve(
@@ -479,12 +479,9 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
switch (outcome) {
case OpenAliasCancelled():
return null;
- case OpenAliasResolved(:final alias, :final address):
+ case OpenAliasResolved():
Navigator.of(context, rootNavigator: true).pop();
- sendToController.text = address;
- _address = address;
- _setValidAddressProviders(_address);
- return alias;
+ return outcome;
case OpenAliasFailed(:final title, :final message):
Navigator.of(context, rootNavigator: true).pop();
unawaited(
@@ -505,13 +502,21 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
final wallet = ref.read(pWallets).getWallet(walletId);
String? openAlias;
+ String? resolvedAddress;
final application = coin.openAliasApplication;
if (application != null &&
!coin.validateAddress(_address ?? "") &&
isOpenAlias(_address ?? "")) {
- openAlias = await _resolveOpenAlias(application);
- if (openAlias == null || !mounted) return;
+ var resolved = _openAlias;
+ if (resolved?.alias != openAliasKey(_address!)) {
+ resolved = _openAlias = await _resolveOpenAlias(application);
+ }
+ if (resolved == null || !mounted) return;
+ openAlias = resolved.alias;
+ resolvedAddress = resolved.address;
+ _setValidAddressProviders(resolvedAddress);
}
+ late final recipientAddress = resolvedAddress ?? _address!;
// Handle MWC slatepack transactions directly.
if (isMimblewimblecoin && ref.read(pIsSlatepack(widget.walletId))) {
@@ -701,7 +706,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
txData: TxData(
sparkRecipients: [
(
- address: _address!,
+ address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
@@ -722,11 +727,11 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
txData: TxData(
recipients: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
@@ -751,18 +756,18 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
? null
: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
sparkRecipients: ref.read(pValidSparkSendToAddress)
? [
(
- address: _address!,
+ address: recipientAddress,
amount: amount,
memo: memoController.text,
isChange: false,
@@ -781,10 +786,12 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
txData: TxData(
recipients: [
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
- addressType: wallet.cryptoCurrency.getAddressType(_address!)!,
+ addressType: wallet.cryptoCurrency.getAddressType(
+ recipientAddress,
+ )!,
),
],
openAlias: openAlias,
@@ -808,11 +815,11 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
_multiRecipients?.toTxRecipients(wallet.cryptoCurrency) ??
[
TxRecipient(
- address: _address!,
+ address: recipientAddress,
amount: amount,
isChange: false,
addressType: wallet.cryptoCurrency.getAddressType(
- _address!,
+ recipientAddress,
)!,
),
],
@@ -949,6 +956,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
if (!mounted) {
return;
}
+ _openAlias = null;
sendToController.text = "";
cryptoAmountController.text = "";
baseAmountController.text = "";
@@ -1170,8 +1178,13 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
}
void _addRecipientTapped() {
+ final resolved = _openAlias;
+ final address =
+ resolved != null && resolved.alias == openAliasKey(_address ?? "")
+ ? resolved.address
+ : _address ?? "";
_setMultiRecipients([
- (address: _address ?? "", amount: ref.read(pSendAmount), label: null),
+ (address: address, amount: ref.read(pSendAmount), label: null),
(address: "", amount: null, label: null),
]);
}
### test/pages/send_view/open_alias_preview_test.dart
@@ -433,7 +433,70 @@ void main() {
expect(find.text('OpenAlias'), findsOneWidget);
expect(find.text('alice@example.com'), findsOneWidget);
expect(find.text(literal), findsWidgets);
- expect(h.text(tester), literal);
+ expect(h.text(tester), alias);
+ });
+
+ testWidgets('$layout a repeated Preview reuses the resolved alias', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.preview(tester);
+ h.succeed();
+ await h.finish(tester);
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+
+ h.navigator.currentState!.pop();
+ await tester.pumpAndSettle();
+ expect(find.byType(ConfirmTransactionView), findsNothing);
+ expect(h.text(tester), alias);
+ expect(h.enabled(tester), isTrue);
+
+ await h.preview(tester);
+ await h.finish(tester);
+ expect(h.lookups, hasLength(1));
+ expect(h.wallet.prepared, hasLength(2));
+ expect(h.wallet.prepared.last.recipients!.single.address, literal);
+ expect(h.wallet.prepared.last.openAlias, 'alice@example.com');
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ expect(h.confirmed(tester).openAlias, 'alice@example.com');
+ expect(find.text('OpenAlias'), findsOneWidget);
+ expect(find.text('alice@example.com'), findsOneWidget);
+ expect(find.text(literal), findsWidgets);
+ });
+
+ testWidgets('$layout an edited alias is looked up again', (tester) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.preview(tester);
+ h.succeed();
+ await h.finish(tester);
+ h.navigator.currentState!.pop();
+ await tester.pumpAndSettle();
+
+ await h.enter(tester, 'bob@example.com');
+ await h.preview(tester);
+ expect(h.lookups, hasLength(2));
+ expect(h.lookups.last.alias, 'bob@example.com');
+ h.lookups.last.result.complete(
+ CsOpenAliasRecipient(
+ domain: 'bob.example.com',
+ address: 'second-recipient',
+ fields: const {'recipient_address': 'second-recipient'},
+ ),
+ );
+ await h.finish(tester);
+ expect(
+ h.confirmed(tester).recipients!.single.address,
+ 'second-recipient',
+ );
+ expect(h.confirmed(tester).openAlias, 'bob@example.com');
+ expect(h.text(tester), 'bob@example.com');
});
testWidgets('$layout the lookup runs before the send-all confirmation', (
@@ -450,7 +513,7 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('Confirm send all'), findsOneWidget);
expect(h.wallet.prepared, isEmpty);
- expect(h.text(tester), literal);
+ expect(h.text(tester), alias);
});
testWidgets('$layout Cancel during the lookup cancels it', (tester) async {
@@ -541,6 +604,35 @@ void main() {
});
}
+ testWidgets('$layout Add recipient after a Preview carries the address', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.preview(tester);
+ h.succeed();
+ await h.finish(tester);
+ h.navigator.currentState!.pop();
+ await tester.pumpAndSettle();
+
+ await tester.tap(
+ find.byWidgetPredicate(
+ (widget) =>
+ widget is CustomTextButton && widget.text == 'Add recipient',
+ ),
+ );
+ await tester.pumpAndSettle();
+ final forms = find.byType(Recipient);
+ expect(forms, findsNWidgets(2));
+ expect(
+ find.descendant(of: forms.first, matching: find.text(literal)),
+ findsOneWidget,
+ );
+ expect(h.lookups, hasLength(1));
+ });
+
testWidgets('$layout multiple recipients never start a lookup', (
tester,
) async {Why this scored 36/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.