Skip to content

[Due for payment 2026-10-08] [$175] Mobile Biometrics - Enter incorrect Magic Code redirect to verification failed screen #101508

Closed

Description

@applause-bot

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


Version Number: v9.4.84-0
Reproducible in staging?: Yes
Reproducible in production?: No
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/74548906/folder/52723519/96645709/1771054333?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: Android 16 / Honor x6b
App Component: User Settings

Action Performed:

Precondition: Device must have a system-level Screen Lock (PIN/Pattern) and Biometrics (Fingerprint or FaceID)

  1. Open the Expensify app
  2. Tap the screen with 4 fingers simultaneously to bring up the hidden Test Tool menu
  3. Locate Biometrics row
  4. Tab "Test" button
  5. Enter the incorrect Magic Code
  6. Verify the error appears
    Result: Any error is shown, user is redirected to Verification fail screen
  7. Verify the Didn't receive magic code? status message appear
    Result: as user is redirected to fail screen user need to iniciate the requeste instead or ask for another magic code

Expected Result:

The user should be able to request a new Magic Code and continue the verification process, after tapping “Didn’t receive magic code?”

Actual Result:

After entering an incorrect Magic Code, the user is redirected to the Verification Failed screen. The user remains on the failure flow and must initiate the Magic Code request again instead of being able to directly request another code.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7262839_1789693097033.video_ok.mp4

View all open jobs on GitHub

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

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

Activity

  1. applause-bot commented on Sep 18, 2026

    @applause-bot
    Author

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

  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 18, 2026
  3. MelvinBot commented on Sep 18, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    An invalid magic code is supposed to be a continuable error that keeps the user on the magic code screen. That classification is failing, so the flow is treated as fatal and pushed to the "Verification failed" outcome screen.

    The intended path is:

    1. src/libs/MultifactorAuthentication/shared/helpers.ts:85 resolves the API response to a reason.
    2. If that reason is CLIENT_ERRORS.INVALID_VALIDATE_CODE, the reducer stores it as continuableError and leaves error undefined — stateReducer.ts:45-50.
    3. process() then short-circuits on continuableError and the user stays put — MultifactorAuthenticationMainContext.tsx:195 — with the inline "Incorrect or invalid security code" message at ValidateCodePage.tsx:83-86.

    Step 1 is the weak link. The reason is derived by string-matching the free-text API message:

    helpers.ts:46-50 does lowerMessage.endsWith('invalid validate code'). If the message does not end with that exact phrase, the match misses and getFallbackReason returns CLIENT_ERRORS.UNRECOGNIZED. That is a normal (non-continuable) error, so process() calls handleCallback(false) and navigates to the failure outcome — MultifactorAuthenticationMainContext.tsx:199-211 and :162-163.

    The specific screen reported corroborates this. "Verification failed" is DefaultClientFailureScreen (defaultScreens.tsx:10-21), which only renders for a 4xx-derived reason. So the 4xx did arrive — it just was not recognised as "invalid validate code".

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

    Stop depending on an exact-suffix match of a free-text message to decide whether the flow can continue.

    1. In resolveReason / findReasonByBackendMessage (helpers.ts:46-69), match on a substring (and trim punctuation) rather than endsWith, so wording or trailing-punctuation drift cannot silently reclassify a recoverable error as fatal.
    2. Add a targeted fallback: a 4xx on REQUEST_AUTHENTICATION_CHALLENGE while a user-entered validateCode is in flight should default to CLIENT_ERRORS.INVALID_VALIDATE_CODE, not UNRECOGNIZED. Failing back to "let the user retype the code" is strictly safer than dead-ending the flow.
    3. Add unit coverage for this path — there is currently none (INVALID_VALIDATE_CODE appears in no test under tests/), which is why the regression reached staging.

    Secondary issue, same test case (step 7). Even when the continuable path works, the resend link is not immediately available: ValidateCodeResendButton.tsx:41 starts with isCountdownRunning = true and only swaps in the "Request a new code" text after the countdown ends (:75). After an incorrect code we should show the resend link right away instead of making the user wait out the timer.

    What alternative solutions did you explore? (Optional)

    Alternatives considered and ruled out
    • The page converts the error itself. ValidateCodePage.tsx:92-101 promotes a continuableError to a fatal one if the reason is not INVALID_VALIDATE_CODE. Ruled out: the reducer only ever populates continuableError for that exact reason, so this branch is unreachable today.
    • Stale-state race in the driving effect. continuableError is deliberately absent from the effect deps at MultifactorAuthenticationMainContext.tsx:429-450. I traced submit → error → retype → resubmit and the flow recovers correctly, so this is not the cause. It does mean resubmitting the identical code is a no-op, which is a separate minor wart.
    • A SERVER_ERRORS / UNHANDLED_API_RESPONSE reason. Ruled out by the reported screen: those route to DefaultServerFailureScreen ("Oops"), not "Verification failed" (OutcomePage.tsx).

    Confidence: medium. The chain from "reason resolves to UNRECOGNIZED" → failure screen is confirmed in code. The one link I could not verify is why the match misses — that needs the actual API response message for an invalid code on the registration challenge call, which lives outside this repo. If the wording there changed recently, that is a backend-side regression and needs an internal engineer to confirm; the hardening in changes 1–3 is worth doing either way, since App should never dead-end a recoverable flow because a message string drifted.

    How to confirm quickly: reproduce on staging and check the Flow error Sentry breadcrumb (MultifactorAuthenticationMainContext.tsx:208) — it logs both reason and the raw message. If reason is Client: Unrecognized client error, this diagnosis is confirmed and message shows the exact string to match against.

    Possibly related


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


    view run

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Sep 18, 2026
  5. melvin-bot commented on Sep 18, 2026

    @melvin-bot

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

  6. melvin-bot commented on Sep 18, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  7. changed the title [-]Mobile Biometrics- Enter incorrect Magic Code redirect to verification failed screen[/-] [+]Mobile Biometrics - Enter incorrect Magic Code redirect to verification failed screen[/+] on Sep 18, 2026
  8. suneox commented on Sep 21, 2026

    @suneox
    Contributor

    I'll take a look at this one today

  9. suneox commented on Sep 24, 2026

    @suneox
    Contributor

    @MelvinBot Currently the RequestAuthenticationChallenge API response returns

    {
      "jsonCode": 401,
      "message": "401 Not authorized - Invalid validateCode",
      "source": "auth-via-api",
      "onyxData": [],
      "requestID": "a3fff9b87c890dbe-SIN"
    }

    We have a mismatch with BACKEND_MESSAGE.INVALID_VALIDATE_CODE, let's analyze & update the proposal

  10. MelvinBot commented on Sep 24, 2026

    @MelvinBot
    Contributor

    Proposal

    Updated: suneox is right — the mismatch is the whole bug, and it is narrower than my first proposal claimed. Corrected below.

    What is the root cause of that problem?

    The App's copy of the backend message is misspelled, so an invalid magic code is never recognised as recoverable.

    • App expects: Invalid validate code — three words (VALUES.ts:12)
    • Backend sends: Invalid validateCode — one camelCase word

    Both sides are lowercased before comparing (helpers.ts:47), so the casing is irrelevant. The only difference that matters is the extra space. '401 not authorized - invalid validatecode'.endsWith('invalid validate code') is false, so the lookup misses, and the flow falls back to CLIENT_ERRORS.UNRECOGNIZED (helpers.ts:27-30) — a fatal error rather than a continuable one (stateReducer.ts:47-50) — and the user is sent to "Verification failed".

    Two corrections to my earlier proposal:

    1. endsWith is not the bug. It works correctly for Registration required, because endsWith only needs an exact suffix and the backend's 401 Not authorized - / 400 prefix does not interfere. The defect is purely the wrong constant value.
    2. I withdraw the "default a 4xx to INVALID_VALIDATE_CODE" suggestion. See alternatives — it is actively unsafe.
    Why "Verification failed" specifically, and why it's a hard dead-end

    UNRECOGNIZED is not REGISTRATION_REQUIRED, so process() calls handleCallback(false) (MultifactorAuthenticationMainContext.tsx:200-211), which navigates to OUTCOME_FAILURE (:162-163) → DefaultClientFailureScreen (defaultScreens.tsx:10-21).

    Navigation uses StackActions.replace (mfaNavigation.ts:69), so the magic-code route is destroyed rather than pushed over. There is no back target and the outcome screen's only control closes the modal — which is exactly the "must start over" behaviour in the report.

    Independent confirmation of the backend string, from App itself: CONST/index.ts:7145 already hard-codes '401 Not authorized - Invalid validateCode' and compares it with strict === at Session/index.ts:1822; AccountValidatePage.tsx:77 matches the same camelCase form. The three-word spelling appears nowhere in src/ as a wire string — only in this constant and two comments.

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

    1. Correct the constant at VALUES.ts:12 to the camelCase spelling the backend actually sends. Blast radius is two map keys — it is read only at VALUES.ts:102 and :107, and nothing else in src/ or tests/ reads it.

      Do not also change VALUES.ts:30. That is an internal reason token compared by identity in the reducer and in ROUTINE_FAILURES; it never touches the wire.

    2. Add the regression test that would have caught this. helpers.test.ts has 11 cases, and every message-matching assertion uses Registration required — the one constant that already worked. Assert that a 401 with the real RequestAuthenticationChallenge message resolves to CLIENT_ERRORS.INVALID_VALIDATE_CODE. This is the highest-value part of the change.

    3. Optional hardening: normalize the message before matching — trim and strip trailing punctuation — keeping endsWith. Today a trailing period or any appended detail would silently reintroduce this exact bug. Prefer this over switching to includes (reasoning in alternatives).

    4. Remove the dead mapping at VALUES.ts:107. RegisterAuthenticationKey cannot produce this error: it sends only keyInfo (actions/MultifactorAuthentication/index.ts:77-79) and its parameter type explicitly Omits validateCode (config/types.ts:168-176). validateCode is only ever sent on RequestAuthenticationChallenge.

    Heads up: step 7 of the repro is a second, separate bug

    Fixing the above will expose it rather than fix it. The resend link starts hidden behind a 30-second countdown — isCountdownRunning is initialised to true (ValidateCodeResendButton.tsx:41) and the pressable is not rendered at all while it runs (:57), anchored to component mount with CONST.REQUEST_CODE_DELAY = 30 (CONST/index.ts:1548). So a user who enters a wrong code within the first 30 seconds sees the inline error but has no way to request a new code until the timer expires. It is a bounded 0-30s gap, not permanent.

    Worth deciding whether to fold into this issue or split: reveal the pressable whenever hasError is true regardless of the countdown, or seed the countdown from a real requestedAt.

    What alternative solutions did you explore? (Optional)

    Rejected: switch the matcher to includes

    Tempting, and it would survive trailing punctuation — but it converts a loud unknown error into a confidently-wrong handler. A backend message that merely mentions a mapped phrase would match, and Registration required drives the destructive clearLocalMFAPublicKeyList() + re-register path (MultifactorAuthenticationMainContext.tsx:201-205). Normalizing punctuation fixes the same fragility with none of that risk.

    Worth noting either way: no current mapped message is a substring of any other, so there is no cross-matching today. But Object.entries(...).find(...) is first-match-wins in declaration order, so if that ever changed, the order of the entries in VALUES.ts would silently decide the outcome.

    Rejected (withdrawn from my first proposal): default a 4xx on a validateCode request to INVALID_VALIDATE_CODE

    Two concrete hazards:

    1. Registration required also arrives as a 4xx on the same registration-challenge request. If its explicit match ever failed — the exact failure mode we are fixing — the fallback would swallow it and break re-registration recovery.
    2. A genuine unrelated 4xx (rate limit, locked account, expired session) would render as "Incorrect or invalid security code" and pin the user on a retry screen that can never succeed — a worse dead-end, because the flow never terminates. It would also silently move the reason from ANOMALOUS_FAILURES into ROUTINE_FAILURES, downgrading the Sentry log level from error to info and hiding future breakage.

    If a safety net is still wanted, the correct shape is the inverse: make CLIENT_ERRORS.UNRECOGNIZED non-fatal while the user is on the validate-code screen, so they keep the retry and resend affordances instead of being replaced out to the outcome screen. That is a larger design change and belongs in a follow-up, not this fix.

    Ruled out: stale-state race, and the page-level error conversion
    • Stale-state race in the driving effect. continuableError is deliberately absent from the effect deps (MultifactorAuthenticationMainContext.tsx:429-450). Traced submit → error → retype → resubmit; the flow recovers correctly. Not the cause.
    • The page converts the error itself. ValidateCodePage.tsx:92-101 promotes a non-INVALID_VALIDATE_CODE continuable error back to fatal. Unreachable — the reducer only ever populates continuableError for that one reason.

    Confidence: high. The mismatch is deterministic and the chain from it to "Verification failed" is confirmed in code. The backend string is corroborated three ways: the response suneox posted above, and two existing App call sites that already match the camelCase form (one with strict equality).

    Possibly related: [ECUK In-App 3DS] [App] Refactor MultifactorAuthenticationContextProvider - fix React rules violations and race conditions risks — tracking issue for the state machine that drives this flow. Not a duplicate, but a fix here should be aware of it.


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

  11. suneox commented on Sep 24, 2026

    @suneox
    Contributor

    Correcting the invalid constant is a straightforward fix for this issue, the same check used in AccountValidatePage

    @MelvinBot implement this (#101508 (comment)) skip change #3 optional hardening

    🎀 👀 🎀 C+ reviewed

  12. 23 remaining items

  13. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Oct 7, 2026
  14. melvin-bot commented on Oct 7, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  15. melvin-bot commented on Oct 7, 2026

    @melvin-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  16. melvin-bot commented on Oct 12, 2026

    @melvin-bot

    @mallenexpensify Eep! 4 days overdue now. Issues have feelings too...

  17. mallenexpensify commented on Oct 14, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @suneox due $250 via NewDot

  18. garrettmknight commented on Oct 19, 2026

    @garrettmknight
    Contributor

    $250 approved for @suneox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions