fix: make the wallet-access 2FA step non-dismissable (CW-1711) (#3742)
What changed, and why it matters
This commit fixes a bug in Cake Wallet's two-factor authentication (2FA) screen. Previously, when the app required a 2FA code to unlock the wallet, users could bypass that requirement by pressing the back arrow or using Android's back gesture. The fix removes the back arrow and blocks the back gesture when the screen is meant to be mandatory, so the wallet cannot be accessed without entering the 2FA code.
Review other security-critical screens (PIN, password, seed phrase access) to ensure they also use PopScope or equivalent non-dismissable guards. Verify that the isClosable flag is correctly passed from all call sites, especially the resume lock and cold-start flows.
Security signals we found
2FA bypass via UI dismissal
Authentication gate not enforced on back navigation
Cold-start/resume lock screen bypass
Missing PopScope/canPop guard on security-critical route
Evidence from the diff
The TOTP authentication page (TotpAuthCodePage) was ignoring its isClosable flag after a UI redesign. The page always rendered a back arrow that popped the route, and Android back gestures could also dismiss it. When used as a wallet-access lock, this allowed the app to resume or start without completing 2FA. The patch wraps the page in a PopScope with canPop set to isClosable, hides the leading back icon when isClosable is false, and adds a same-size placeholder to preserve the top bar height for the title.
Changed components
lib/src/screens/setup_2fa/setup_2fa_enter_code_page.dartTotpAuthCodePageTOTPEnterCodeModalTopBarInspect captured patch +18 / −8
### lib/src/screens/setup_2fa/setup_2fa_enter_code_page.dart
@@ -91,12 +91,19 @@ class TotpAuthCodePageState extends State<TotpAuthCodePage> {
@override
Widget build(BuildContext context) {
- return Scaffold(
- key: _key,
- body: TOTPEnterCode(
- setup2FAViewModel: widget.setup2FAViewModel,
- isForSetup: widget.totpArguments.isForSetup ?? false,
- isClosable: widget.totpArguments.isClosable ?? true,
+ final isClosable = widget.totpArguments.isClosable ?? true;
+
+ // When not closable (wallet access lock), block the system back gesture too,
+ // otherwise popping this route skips the 2FA check.
+ return PopScope(
+ canPop: isClosable,
+ child: Scaffold(
+ key: _key,
+ body: TOTPEnterCode(
+ setup2FAViewModel: widget.setup2FAViewModel,
+ isForSetup: widget.totpArguments.isForSetup ?? false,
+ isClosable: isClosable,
+ ),
),
);
}
@@ -143,8 +150,11 @@ class _TOTPEnterCodeState extends State<TOTPEnterCode> {
children: [
ModalTopBar(
title: widget.isForSetup ? S.current.setup_2fa : S.current.verify_with_2fa,
- leadingIcon: Icon(Icons.arrow_back_ios_new),
- leadingSemanticLabel: S.current.seed_alert_back,
+ leadingIcon: widget.isClosable ? Icon(Icons.arrow_back_ios_new) : null,
+ // Same-size placeholder keeps the bar's height so the title still shows.
+ leadingWidget:
+ widget.isClosable ? null : SizedBox.square(dimension: ModalTopBar.buttonSize),
+ leadingSemanticLabel: widget.isClosable ? S.current.seed_alert_back : null,
onLeadingPressed: Navigator.of(context).pop,
),
Expanded(Why this scored 51/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.