App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-11-28] [$175] Security - Valid magic code is not accepted when reopening an account

Open applause-bot[bot] opened this issue 2 months ago β€’ 43 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.4.95-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/76118653/folder/52723519/41236673/1807066502?sort=%2Bidentifier Email or phone of affected tester (no customers): n/a Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: iPhone 13 iOS 26.6 App Component: User Settings

Action Performed:

  1. Open the app
  2. Navigate to Account > Security > Close account
  3. Enter some text in the first input
  4. Enter the email in the second input and tap on "close account"
  5. Verify you are logged out
  6. Enter the email of the account you just closed
  7. Enter a valid magic code

Expected Result:

The user should be able to reopen the account and sign in successfully

Actual Result:

Nothing happens after entering a valid magic code. After tapping the Sign In button, the "Incorrect magic code" error appears.

Workaround:

Unknown

Platforms:

  • [x] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [ ] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/af1c5436-44c0-4ed5-ac82-7bc619606e4b

View all open jobs on GitHub

Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7272177

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

applause-bot[bot] avatar Sep 29 '26 11:09 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/f9aaee604638e5f8e2ecb1c04ae6e032573ea069aa64a25a73cb098fc7d1296d

applause-bot[bot] avatar Sep 29 '26 11:09 applause-bot[bot]

Proposal

What is the root cause of that problem?

Closing the account on the iOS/Android apps (HybridApp) wipes the local HybridApp sign-in flag. As a result, the next sign-in succeeds on the server, but the app never leaves the magic code screen.

  1. closeAccount does not go through the normal sign-out path. It relies on the server clearing all Onyx data (User.ts:181-211). That clear removes hybridApp.useNewDotSignInPage. Only resetSignInFlow() sets this flag back to true, and only the normal sign-out calls it (SignInRedirect.ts:115).
  2. The magic code auto-submits. SigninUser succeeds, uses up the code, and returns an authToken.
  3. signInToOldDotAndChooseExperience returns early because useNewDotSignInPage is not set, so readyToShowAuthScreens is never set to true (HybridApp.ts:89).
  4. On HybridApp, the signed-in screens only render when readyToShowAuthScreens is true (AppNavigator.native.tsx:17-22). The magic code form stays on screen, so "nothing happens."
  5. Tapping Sign In sends the already-used code again. The server rejects it with "Incorrect magic code."

This explains why only the native apps are affected: on web, authenticated alone shows the signed-in screens.

What changes do you think we should make in order to solve the problem?

In closeAccount, after a successful response on HybridApp, reset the HybridApp sign-in flow alongside signOutFromOldDot(). For example, call resetSignInFlow() or send the user through redirectToSignIn(). The next sign-in then runs the normal HybridApp flow and shows the signed-in screens.

Make sure the reset runs after the server-driven Onyx clear. Otherwise the clear can wipe the flag again.

What alternative solutions did you explore? (Optional)

Give ONYXKEYS.HYBRID_APP a default of {useNewDotSignInPage: true} in the HybridApp Onyx initialKeyStates. Any Onyx.clear(), from close account or any other server-driven clear, then restores a usable sign-in state.

Confidence, unverified points, and related changes

Confidence: medium. The code path supports this explanation, but I have not confirmed it on a device or in production logs.

  • I could not test on web: Melvin cannot get magic codes to re-sign in a closed account. Web is not a reported platform anyway.
  • To confirm, check the tester's requests. SigninUser #1 should succeed and #2 should fail with "Incorrect magic code." The client log should also lack [HybridApp] Performing sign-in on OldDot side after the first SigninUser.
  • Possible workaround this predicts: force-quit and reopen the app after closing the account, then sign in.
  • Other possible blockers on the same path: a reopened account's SigninUser response may lack nvp_tryNewDot, autoGeneratedLogin/autoGeneratedPassword, or the 2FA fields that HybridApp.ts:98 requires. That would also leave the user stuck. It needs backend or log checks.
  • Recent change to this flow: [Payment due @suneox] Add validate code page for CloseAccount (merged 2026-09-19, included in 9.4.95-0). It moved signOutFromOldDot() to run only after a successful response. I could not check whether the native signOutFromOldDot (in Mobile-Expensify) used to restore this flag, so I have not confirmed this PR as the regression.
  • I did not find likely duplicate open issues.

Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/102528) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Sep 29 '26 11:09 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @TaduJR (External)

melvin-bot[bot] avatar Sep 29 '26 11:09 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022104893255610467459

melvin-bot[bot] avatar Sep 29 '26 11:09 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

On HybridApp (iOS / Android), when reopening a previously closed account, entering a valid magic code does not advance the user past the magic code screen. Tapping "Sign In" again results in an "Incorrect magic code" error because the code was already consumed.

What is the root cause of that problem?

  1. In src/libs/actions/User.ts within closeAccount: When an account is closed, upon server response, the app only calls HybridAppModule.signOutFromOldDot(). It does not call resetSignInFlow(), nor does it route through clearStorageAndRedirect (which is what normal sign-out does in SignInRedirect.ts:115).
  2. When the backend processes CloseAccount, a Pusher event clears all Onyx data. This wipes ONYXKEYS.HYBRID_APP, resetting hybridApp.useNewDotSignInPage to undefined.
  3. When the user subsequently attempts to reopen the account and signs in with their magic code, SigninUser succeeds and consumes the magic code.
  4. However, in src/libs/HybridApp.ts within signInToOldDotAndChooseExperience:
    if (!session?.authToken || !hybridApp?.useNewDotSignInPage) {
        return;
    }
    
    Because hybridApp?.useNewDotSignInPage is undefined/falsy, the function returns immediately.
  5. Consequently, setReadyToShowAuthScreens(true) is never called.
  6. In AppNavigator.native.tsx, authenticated screens only render when readyToShowAuthScreens is true. The UI remains stuck on the magic code form.
  7. Any subsequent tap on "Sign In" attempts to resubmit the already-used magic code, causing the server to return "Incorrect magic code".

What changes do you think we should make in order to solve the problem?

  1. In src/libs/actions/User.ts (closeAccount): When the close account request succeeds on HybridApp, call resetSignInFlow() alongside HybridAppModule.signOutFromOldDot():
    API.write(WRITE_COMMANDS.CLOSE_ACCOUNT, parameters, {
        optimisticData,
        failureData,
    }).then((response) => {
        if (!CONFIG.IS_HYBRID_APP || response?.jsonCode !== CONST.JSON_CODE.SUCCESS) {
            return;
        }
        resetSignInFlow();
        HybridAppModule.signOutFromOldDot();
    });
    
  2. Additionally, in initialKeyStates.ts (or wherever initial Onyx key state is registered for ONYXKEYS.HYBRID_APP), ensure useNewDotSignInPage: true is preserved as the default state so that any server-driven Onyx.clear() leaves the client in a valid ready-to-sign-in state.

What alternative solutions did you explore? (Optional)

Calling redirectToSignIn('closeAccount') upon successful completion of closeAccount. However, calling resetSignInFlow() directly keeps the lightweight nature of the existing completion callback without redundant redirect transitions.

bonnhatnguyen avatar Sep 29 '26 14:09 bonnhatnguyen

@TaduJR Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Oct 02 '26 23:10 melvin-bot[bot]

@TaduJR Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Oct 03 '26 01:10 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

On HybridApp (iOS / Android), when reopening a previously closed account, entering a valid magic code does not transition the user past the magic code screen. Tapping "Sign In" a second time returns "Incorrect magic code" because the magic code was already consumed during the initial sign-in attempt.

What is the root cause of that problem?

There are two interconnected root causes:

  1. Missing resetSignInFlow() in User.closeAccount: During normal user login, src/libs/HybridApp.ts:119 sets setUseNewDotSignInPage(false). When a user closes their account, src/libs/actions/User.ts:206-211 handles the successful CLOSE_ACCOUNT response by calling only HybridAppModule.signOutFromOldDot(). Unlike standard sign-out in src/libs/actions/SignInRedirect.ts:114-117, it never invokes resetSignInFlow().
  2. Missing [ONYXKEYS.HYBRID_APP] in initialKeyStates: When CloseAccount succeeds, the backend triggers a Pusher clear / server-driven Onyx clear. In src/setup/index.ts:55-70, ONYXKEYS.HYBRID_APP does not have default initial key states defined. Consequently, when Onyx is wiped or re-initialized, hybridApp.useNewDotSignInPage is cleared to undefined (or remains false if preserved).

When the reopened account subsequently signs in with a magic code:

  • The initial SigninUser API call succeeds on the server and returns authToken.
  • However, in src/libs/HybridApp.ts:89-91, signInToOldDotAndChooseExperience checks:
    if (!session?.authToken || !hybridApp?.useNewDotSignInPage) {
        return;
    }
    
    Since hybridApp?.useNewDotSignInPage is false or undefined, the function returns early and never calls setReadyToShowAuthScreens(true).
  • In src/libs/Navigation/AppNavigator/AppNavigator.native.tsx:17-23, authenticated screens are guarded by:
    return authenticated && hybridApp?.readyToShowAuthScreens;
    
    Because readyToShowAuthScreens is false, the UI remains stuck on the magic code entry page.
  • Subsequent taps on "Sign In" attempt to reuse the already-consumed magic code, triggering the backend error "Incorrect magic code".

What changes do you think we should make in order to solve the problem?

  1. Call resetSignInFlow() in User.closeAccount: In src/libs/actions/User.ts:206-211, import resetSignInFlow from @userActions/HybridApp and invoke it upon successful completion:

    API.write(WRITE_COMMANDS.CLOSE_ACCOUNT, parameters, {
        optimisticData,
        failureData,
    }).then((response) => {
        // The account stays open when the validateCode is rejected, so OldDot must stay signed in to keep the state of both apps in sync
        if (!CONFIG.IS_HYBRID_APP || response?.jsonCode !== CONST.JSON_CODE.SUCCESS) {
            return;
        }
        resetSignInFlow();
        HybridAppModule.signOutFromOldDot();
    });
    
  2. Add ONYXKEYS.HYBRID_APP to initialKeyStates in setup/index.ts: In src/setup/index.ts:55-70, register default initial states so any Onyx.clear() (server-driven or local) automatically restores a clean sign-in state:

    [ONYXKEYS.HYBRID_APP]: {
        readyToShowAuthScreens: false,
        useNewDotSignInPage: true,
    },
    

What alternative solutions did you explore? (Optional)

  • Routing closeAccount completion through clearStorageAndRedirect('closeAccount'): While functional, clearStorageAndRedirect initiates additional full navigation tear-downs and telemetry that could conflict with the backend's server-driven data purge. Adding resetSignInFlow() alongside HybridAppModule.signOutFromOldDot() and setting the fallback in initialKeyStates provides a robust, defense-in-depth fix without side effects.

Tests

  1. Unit Test (tests/unit/CloseAccountTest.ts):

    • Mock CONFIG.IS_HYBRID_APP = true.
    • Seed ONYXKEYS.HYBRID_APP with {useNewDotSignInPage: false, readyToShowAuthScreens: true}.
    • Execute closeAccount('test reason', '123456') simulating a CONST.JSON_CODE.SUCCESS response.
    • Assert ONYXKEYS.HYBRID_APP is updated with {useNewDotSignInPage: true, readyToShowAuthScreens: false}.
    • Call Onyx.clear().
    • Assert ONYXKEYS.HYBRID_APP in initialKeyStates restores {useNewDotSignInPage: true, readyToShowAuthScreens: false}.
  2. Manual Regression Verification:

    • On a HybridApp build (iOS / Android), navigate to Settings > Security > Close Account.
    • Enter reason and confirm with validate code.
    • Confirm account closes and app returns to the public sign-in screen.
    • Reopen/sign in to the account using a magic code.
    • Verify that submitting the magic code immediately transitions into the authenticated experience without error or hang.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0170d6b02e9440e604

camesenin avatar Oct 04 '26 23:10 camesenin

βœ… Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 04 '26 23:10 melvin-bot[bot]

@TaduJR Still overdue 6 days?! Let's take care of this!

melvin-bot[bot] avatar Oct 06 '26 22:10 melvin-bot[bot]

@TaduJR Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

melvin-bot[bot] avatar Oct 08 '26 22:10 melvin-bot[bot]

@TaduJR 12 days overdue. Walking. Toward. The. Light...

melvin-bot[bot] avatar Oct 12 '26 21:10 melvin-bot[bot]

@TaduJR this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

melvin-bot[bot] avatar Oct 13 '26 21:10 melvin-bot[bot]

This issue has not been updated in over 14 days. @TaduJR eroding to Weekly issue.

melvin-bot[bot] avatar Oct 15 '26 21:10 melvin-bot[bot]

@TaduJR this issue is now 4 weeks old, please consider:

  • Finding a contributor to fix the bug
  • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
  • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

Thanks!

melvin-bot[bot] avatar Oct 27 '26 21:10 melvin-bot[bot]

@MelvinBot implement this

TaduJR avatar Oct 30 '26 21:10 TaduJR

πŸ€– Draft PR created: Restart the HybridApp sign-in flow after closing an account Please mark it as "Ready for review" or ask me to do that for you when it is ready for review.

The PR adds the HybridApp sign-in reset (useNewDotSignInPage: true, readyToShowAuthScreens: false) to the CloseAccount request's successData. Onyx applies it after the server's clear, so the next magic code sign-in shows the signed-in screens.

One difference from the proposal: I didn't put the reset in the .then callback. API.write resolves when the request is queued, before the response arrives. A reset there would be wiped by the clear.

⚠️ For the same reason, HybridAppModule.signOutFromOldDot() in that .then never runs. I left it unchanged and flagged it in the PR for a decision.

The new unit tests pass and fail without the fix. I haven't tested this on a device: the bug only affects iOS and Android, and closing the shared test account can't be undone.

MelvinBot avatar Oct 30 '26 22:10 MelvinBot

MelvinBot Proposal LGTM!

πŸŽ€πŸ‘€πŸŽ€ C+ Reviewed.

TaduJR avatar Nov 01 '26 14:11 TaduJR

Triggered auto assignment to @mollfpr, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Nov 01 '26 14:11 melvin-bot[bot]

πŸ“£ @TaduJR πŸŽ‰ An offer has been automatically sent to your Upwork account for the Reviewer role πŸŽ‰ Thanks for contributing to the Expensify app!

Offer link Upwork job

melvin-bot[bot] avatar Nov 01 '26 15:11 melvin-bot[bot]