fix(openalias): drop the resolved alias when the recipient field changes
What changed, and why it matters
This commit fixes a bug in Stack Wallet's OpenAlias lookup for cryptocurrency sending. Previously, if a user cleared the recipient field and retyped the same alias, the wallet reused the old address lookup instead of fetching it again. The fix now drops the cached lookup whenever the recipient text changes, ensuring a fresh lookup occurs. This is a correctness and potential security fix because a stale or attacker-controlled alias resolution could be reused when the user expected a new lookup.
Review OpenAlias lookup and caching logic across the app for similar stale-cache patterns; ensure DNS/TLS resolution failures are handled safely; consider whether cached resolutions should also be invalidated on other state changes (e.g., wallet switch, network change).
Security signals we found
Stale cached alias resolution could be reused across recipient field changes
OpenAlias lookup result is invalidated when recipient text changes
Mobile and desktop send flows both patched with identical logic
Regression test added to prevent reuse of old lookup
Evidence from the diff
The patch changes the _address field in both mobile (send_view.dart) and desktop (desktop_send.dart) send widgets from a plain nullable String to a getter/setter pair backed by _addressValue. The setter compares openAliasKey(value ?? "") against _openAlias?.alias and clears _openAlias when they differ. This invalidates the cached OpenAlias resolution on any recipient text change, preventing stale lookups from being reused when the same alias is retyped after clearing. A regression test verifies that clearing and retyping the alias triggers two lookups and resolves to the expected literal address.
Changed components
lib/pages/send_view/send_view.dartlib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dartOpenAlias recipient resolution in send flowInspect captured patch +38 / −2
### lib/pages/send_view/send_view.dart
@@ -151,9 +151,18 @@ class _SendViewState extends ConsumerState<SendView> {
late final bool isEth;
Amount? _cachedAmountToSend;
- String? _address;
+ String? _addressValue;
OpenAliasResolved? _openAlias;
+ String? get _address => _addressValue;
+
+ // Clearing and retyping an alias passes through other text, so the lookup
+ // is dropped then rather than kept for the same alias typed again.
+ set _address(String? value) {
+ _addressValue = value;
+ if (openAliasKey(value ?? "") != _openAlias?.alias) _openAlias = null;
+ }
+
/// The [pRecipient] index of each recipient's form while sending to more
/// than one recipient, otherwise null.
List<int>? _recipientIndexes;
### lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart
@@ -138,9 +138,18 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
String? _onChainNote;
Amount? _cachedAmountToSend;
- String? _address;
+ String? _addressValue;
OpenAliasResolved? _openAlias;
+ String? get _address => _addressValue;
+
+ // Clearing and retyping an alias passes through other text, so the lookup
+ // is dropped then rather than kept for the same alias typed again.
+ set _address(String? value) {
+ _addressValue = value;
+ if (openAliasKey(value ?? "") != _openAlias?.alias) _openAlias = null;
+ }
+
/// The [pRecipient] index of each recipient's form while sending to more
/// than one recipient, otherwise null.
List<int>? _recipientIndexes;
### test/pages/send_view/open_alias_preview_test.dart
@@ -547,6 +547,24 @@ void main() {
expect(h.confirmed(tester).recipients!.single.address, literal);
});
+ testWidgets('$layout clearing and retyping the alias looks it up again', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.previewAndReturn(tester);
+
+ await h.enter(tester, '');
+ await h.enter(tester, alias);
+ await h.preview(tester);
+ expect(h.lookups, hasLength(2));
+ h.succeed();
+ await h.finish(tester);
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ });
+
testWidgets('$layout the lookup runs before the send-all confirmation', (
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.