fix(openalias): expire a resolved alias with its TTL
What changed, and why it matters
This commit fixes a bug in Stack Wallet where an OpenAlias recipient address (for example, an email-like alias that resolves to a crypto address) could be reused indefinitely once it was first looked up. If the recipient later changed their address, the wallet might still send funds to the old, cached address. The fix makes the cached address expire after the time-to-live (TTL) returned by the OpenAlias lookup, capped at one hour, so the wallet will re-resolve the alias before sending if the cached answer is stale.
Reviewers should confirm that all code paths that consume OpenAliasResolved (including any not shown in this diff) check isCurrent() before reusing a cached address, and that the one-hour cap is appropriate for the threat model. Consider whether the wallet should also clear cached resolutions when the app is backgrounded or the send form is closed.
Security signals we found
Use of stale cached address could lead to sending funds to an address the recipient no longer controls
OpenAlias TTL was previously ignored, extending the window for address-replacement attacks
Fix explicitly caps reuse at one hour even if resolver returns a longer TTL
Both mobile and desktop send paths updated consistently
New unit and widget tests cover expiry and reuse behavior
Evidence from the diff
The patch adds TTL-aware expiration to OpenAlias resolution results. OpenAliasResolved now carries an expiresAt timestamp computed from the resolver’s TTL (clamped to a maximum of one hour). A new isCurrent() method on OpenAliasService checks whether a resolved result is still within its TTL. Both mobile (send_view.dart) and desktop (desktop_send.dart) send flows now re-resolve the alias when the cached result is null, for a different alias, or not current. Tests verify TTL expiration, one-hour clamping, zero-TTL behavior, and re-lookup after expiry.
Changed components
lib/services/openalias/open_alias_service.dartlib/pages/send_view/send_view.dartlib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.darttest/services/openalias/open_alias_service_test.darttest/pages/send_view/open_alias_preview_test.dartInspect captured patch +162 / −17
### lib/pages/send_view/send_view.dart
@@ -242,7 +242,9 @@ class _SendViewState extends ConsumerState<SendView> {
void _addRecipientTapped() {
final resolved = _openAlias;
final address =
- resolved != null && resolved.alias == openAliasKey(_address ?? "")
+ resolved != null &&
+ resolved.alias == openAliasKey(_address ?? "") &&
+ ref.read(pOpenAliasService).isCurrent(resolved)
? resolved.address
: _address ?? "";
_setMultiRecipients([
@@ -1085,7 +1087,9 @@ class _SendViewState extends ConsumerState<SendView> {
!coin.validateAddress(_address ?? "") &&
isOpenAlias(_address ?? "")) {
var resolved = _openAlias;
- if (resolved?.alias != openAliasKey(_address!)) {
+ if (resolved == null ||
+ resolved.alias != openAliasKey(_address!) ||
+ !ref.read(pOpenAliasService).isCurrent(resolved)) {
resolved = _openAlias = await _resolveOpenAlias(application);
}
if (resolved == null || !mounted) return;
### lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart
@@ -508,7 +508,9 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
!coin.validateAddress(_address ?? "") &&
isOpenAlias(_address ?? "")) {
var resolved = _openAlias;
- if (resolved?.alias != openAliasKey(_address!)) {
+ if (resolved == null ||
+ resolved.alias != openAliasKey(_address!) ||
+ !ref.read(pOpenAliasService).isCurrent(resolved)) {
resolved = _openAlias = await _resolveOpenAlias(application);
}
if (resolved == null || !mounted) return;
@@ -1180,7 +1182,9 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
void _addRecipientTapped() {
final resolved = _openAlias;
final address =
- resolved != null && resolved.alias == openAliasKey(_address ?? "")
+ resolved != null &&
+ resolved.alias == openAliasKey(_address ?? "") &&
+ ref.read(pOpenAliasService).isCurrent(resolved)
? resolved.address
: _address ?? "";
_setMultiRecipients([
### lib/services/openalias/open_alias_service.dart
@@ -56,18 +56,21 @@ class OpenAliasService {
bool Function()? supportsTor,
({InternetAddress host, int port}) Function()? torProxy,
OpenAliasLookup? lookup,
+ DateTime Function()? now,
}) : _externalCalls = externalCalls ?? (() => Prefs.instance.externalCalls),
_useTor = useTor ?? (() => Prefs.instance.useTor),
_supportsTor =
supportsTor ?? (() => AppConfig.hasFeature(AppFeature.tor)),
_torProxy = torProxy ?? (() => TorService.sharedInstance.getProxyInfo()),
- _lookup = lookup ?? resolveOpenAlias;
+ _lookup = lookup ?? resolveOpenAlias,
+ _now = now ?? DateTime.now;
final bool Function() _externalCalls;
final bool Function() _useTor;
final bool Function() _supportsTor;
final ({InternetAddress host, int port}) Function() _torProxy;
final OpenAliasLookup _lookup;
+ final DateTime Function() _now;
/// Why no lookup can be sent now, or null when one can.
String? unavailableReason() => _route().unavailable;
@@ -93,6 +96,10 @@ class OpenAliasService {
);
}
+ /// Whether [resolved] is still within the TTL of its answer.
+ bool isCurrent(OpenAliasResolved resolved) =>
+ resolved.expiresAt.isAfter(_now());
+
/// Starts [lookup] for the alias typed into a send field.
OpenAliasResolution resolve(
String input, {
@@ -104,6 +111,7 @@ class OpenAliasService {
lookup(input, isValidAddress: isValidAddress, application: application),
alias: openAliasKey(input),
coinName: coinName,
+ now: _now,
);
({String? unavailable, CsOpenAliasProxy? proxy}) _route() {
@@ -144,10 +152,15 @@ sealed class OpenAliasOutcome {
}
final class OpenAliasResolved extends OpenAliasOutcome {
- const OpenAliasResolved({required this.alias, required this.address});
+ const OpenAliasResolved({
+ required this.alias,
+ required this.address,
+ required this.expiresAt,
+ });
final String alias;
final String address;
+ final DateTime expiresAt;
}
final class OpenAliasFailed extends OpenAliasOutcome {
@@ -161,14 +174,18 @@ final class OpenAliasCancelled extends OpenAliasOutcome {
const OpenAliasCancelled();
}
+// Bounds reuse even if a resolver hands back an inflated TTL.
+const _maxReuse = Duration(hours: 1);
+
/// A lookup started by [OpenAliasService.resolve].
final class OpenAliasResolution {
OpenAliasResolution._(
CsOpenAliasOperation<CsOpenAliasRecipient> Function() start, {
required String alias,
required String coinName,
+ required DateTime Function() now,
}) {
- outcome = _run(start, alias, coinName);
+ outcome = _run(start, alias, coinName, now);
}
late final Future<OpenAliasOutcome> outcome;
@@ -184,12 +201,18 @@ final class OpenAliasResolution {
CsOpenAliasOperation<CsOpenAliasRecipient> Function() start,
String alias,
String coinName,
+ DateTime Function() now,
) async {
try {
_operation = start();
- final address = (await _operation!.result).address;
+ final recipient = await _operation!.result;
if (_cancelled) return const OpenAliasCancelled();
- return OpenAliasResolved(alias: alias, address: address);
+ final ttl = recipient.ttl < _maxReuse ? recipient.ttl : _maxReuse;
+ return OpenAliasResolved(
+ alias: alias,
+ address: recipient.address,
+ expiresAt: now().add(ttl),
+ );
} catch (e, s) {
if (_cancelled) return const OpenAliasCancelled();
Logging.instance.w("OpenAlias lookup failed", error: e, stackTrace: s);
### test/pages/send_view/open_alias_preview_test.dart
@@ -173,10 +173,12 @@ class _Harness {
late final ProviderContainer container;
final navigator = GlobalKey<NavigatorState>();
final lookups = <_Lookup>[];
+ var now = DateTime.utc(2026, 10, 28, 12);
late final service = OpenAliasService(
externalCalls: () => !incognito,
useTor: () => false,
+ now: () => now,
lookup:
(
alias, {
@@ -332,14 +334,24 @@ class _Harness {
expect(tester.takeException(), isNull);
}
- void succeed() => lookups.single.result.complete(
+ void succeed() => lookups.last.result.complete(
CsOpenAliasRecipient(
domain: 'alice.example.com',
address: literal,
fields: const {'recipient_address': literal},
- ttl: const Duration(minutes: 5),
+ ttl: const Duration(seconds: 60),
),
);
+
+ /// Previews, completes the lookup and goes back to the form.
+ Future<void> previewAndReturn(WidgetTester tester) async {
+ await preview(tester);
+ succeed();
+ await finish(tester);
+ expect(find.byType(ConfirmTransactionView), findsOneWidget);
+ navigator.currentState!.pop();
+ await tester.pumpAndSettle();
+ }
}
void main() {
@@ -501,6 +513,40 @@ void main() {
expect(h.text(tester), 'bob@example.com');
});
+ testWidgets('$layout an expired resolution 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.previewAndReturn(tester);
+
+ h.now = h.now.add(const Duration(seconds: 61));
+ await h.preview(tester);
+ expect(h.lookups, hasLength(2));
+ h.succeed();
+ await h.finish(tester);
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ expect(h.confirmed(tester).openAlias, 'alice@example.com');
+ });
+
+ testWidgets('$layout a resolution within its TTL is reused', (
+ tester,
+ ) async {
+ final h = _Harness(desktop);
+ await h.mount(tester);
+ await h.enter(tester, alias);
+ await h.setAmount(tester);
+ await h.previewAndReturn(tester);
+
+ h.now = h.now.add(const Duration(seconds: 59));
+ await h.preview(tester);
+ await h.finish(tester);
+ expect(h.lookups, hasLength(1));
+ expect(h.confirmed(tester).recipients!.single.address, literal);
+ });
+
testWidgets('$layout the lookup runs before the send-all confirmation', (
tester,
) async {
### test/services/openalias/open_alias_service_test.dart
@@ -36,12 +36,34 @@ class _Calls {
}
}
-OpenAliasService _service(OpenAliasLookup lookup, {bool external = true}) =>
- OpenAliasService(
- externalCalls: () => external,
- useTor: () => false,
- lookup: lookup,
- );
+OpenAliasService _service(
+ OpenAliasLookup lookup, {
+ bool external = true,
+ DateTime Function()? now,
+}) => OpenAliasService(
+ externalCalls: () => external,
+ useTor: () => false,
+ lookup: lookup,
+ now: now,
+);
+
+OpenAliasService _answering(Duration ttl, DateTime Function() now) => _service(
+ (alias, {required isValidAddress, required application, required proxy}) =>
+ CsOpenAliasOperation(
+ Future.value(
+ CsOpenAliasRecipient(
+ domain: 'alice.example.com',
+ address: 'resolved',
+ fields: const {'recipient_address': 'resolved'},
+ ttl: ttl,
+ ),
+ ),
+ () {},
+ ),
+ now: now,
+);
+
+final _start = DateTime.utc(2026, 10, 28, 12);
OpenAliasResolution _resolve(OpenAliasService service) => service.resolve(
' Alice@Example.com',
@@ -251,6 +273,52 @@ void main() {
);
});
+ test('the answer expires after its TTL', () async {
+ final outcome = await _resolve(
+ _answering(const Duration(seconds: 60), () => _start),
+ ).outcome;
+ expect(
+ outcome,
+ isA<OpenAliasResolved>().having(
+ (e) => e.expiresAt,
+ 'expiresAt',
+ _start.add(const Duration(seconds: 60)),
+ ),
+ );
+ });
+
+ test('a TTL over an hour is cut to an hour', () async {
+ final outcome = await _resolve(
+ _answering(const Duration(days: 2), () => _start),
+ ).outcome;
+ expect(
+ outcome,
+ isA<OpenAliasResolved>().having(
+ (e) => e.expiresAt,
+ 'expiresAt',
+ _start.add(const Duration(hours: 1)),
+ ),
+ );
+ });
+
+ test('a zero TTL is never current', () async {
+ final service = _answering(Duration.zero, () => _start);
+ final outcome = await _resolve(service).outcome as OpenAliasResolved;
+ expect(outcome.expiresAt, _start);
+ expect(service.isCurrent(outcome), isFalse);
+ });
+
+ test('isCurrent follows the clock', () async {
+ var now = _start;
+ final service = _answering(const Duration(seconds: 60), () => now);
+ final outcome = await _resolve(service).outcome as OpenAliasResolved;
+ expect(service.isCurrent(outcome), isTrue);
+ now = _start.add(const Duration(seconds: 59));
+ expect(service.isCurrent(outcome), isTrue);
+ now = _start.add(const Duration(seconds: 60));
+ expect(service.isCurrent(outcome), isFalse);
+ });
+
test('a lookup failure becomes its user message', () async {
final service = _service((
alias, {Why this scored 60/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.