Skip to content

[$250] Copilot - User will force sign out after issue new card using full delegate access #83539

Closed

Description

@jponikarchuk

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: v9.3.26-4
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #81817
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Windows 11 / Chrome, Android 13 / Xiaomi Poco F5, iOS 15.8.3 / iPhone 7 Plus
App Component: Workspace Settings

Action Performed:

Precondition:

  • User A, login using Expensifial account, create a workspace, and enable the Expensify Card feature
  • User A, add user B as a Copilot account with full delegate access (can use a Gmail account)
  1. Login to user B
  2. Navigate to Account and switch as user A
  3. Go to Workspace > Expensify Card
  4. Click the Issue card and follow the issue card flow
  5. In the RHP magic code, enter the magic code that was sent to user A's email

Expected Result:

User does not auto sign out after issue new card using full delegate access

Actual Result:

User will force sign out after issue new card using full delegate access
Note:

  • Sometimes the user will force sign out after navigating to another section
  • The new card is successfully added after the user relogin to user B's account

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @rushatgabhane
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022026924444293717309
  • Upwork Job ID: 2026924444293717309
  • Last Price Increase: 2026-02-26

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 26, 2026
  2. melvin-bot commented on Feb 26, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #81817

  3. melvin-bot commented on Feb 26, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. melvin-bot commented on Feb 26, 2026

    @melvin-bot

    Triggered auto assignment to @trjExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. github-actions commented on Feb 26, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  6. OSBotify commented on Feb 26, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #81817 - "Allow full Copilot users to access Expensify Card pages" by @MelvinBot (High confidence)
    Related Issues: #79095

    Recommendation: REVERT

    The frontend PR was merged without the corresponding backend changes being deployed first. The PR description explicitly states: "The backend change (allowing ROLE_ALL auth token type for CreateAdminIssuedVirtualCard command) is out of scope for this frontend PR and needs to be handled separately."

    This means the frontend allows full Copilot users to proceed through the card issuance flow, but when they submit the magic code, the backend rejects the request (likely with a 407 NOT_AUTHENTICATED or similar error), which triggers a sign-out.

    Labels: Keeping DeployBlockerCash (blocks App deploy). The DeployBlocker label was not present on this issue.

    📋 Detailed Analysis

    Evidence

    PR #81817 changed the delegate access checks from isActingAsDelegate to isDelegateAccessRestricted for Expensify Card pages. This allows full Copilot users (ROLE_ALL delegates) to access the card issuance flow, but the backend API command CreateAdminIssuedVirtualCard has not been updated to accept ROLE_ALL auth token types.

    The PR modified these files:

    • IssueNewCardPage.tsx - Changed access check from isActingAsDelegate to isDelegateAccessRestricted
    • WorkspaceExpensifyCardListPage.tsx - Same change
    • WorkspaceExpensifyCardPageEmptyState.tsx - Same change
    • WorkspaceExpensifyCardBankAccounts.tsx - Changed DENIED_ACCESS_VARIANTS.DELEGATE to DENIED_ACCESS_VARIANTS.SUBMITTER
    • IssueNewCardConfirmMagicCodePage.tsx - Added session email fallback

    Verification

    The bug is reproducible on staging but not validated on production, which aligns with PR #81817 being in the current staging deploy (v9.3.26-4) at position #87 in the chronologically ordered list.

    The issue affects the card issuance flow specifically when:

    1. A full Copilot delegate accesses the Expensify Card section
    2. They complete the issue card flow
    3. They submit the magic code
    4. The backend rejects the request due to auth token restrictions
    5. The rejection response causes the frontend to sign out the user

    Root Cause

    Frontend-Backend Mismatch: The frontend was deployed to allow full Copilot users to access card issuance pages, but the backend API was not updated to accept ROLE_ALL delegate auth tokens for the CreateAdminIssuedVirtualCard command. When the magic code is submitted, the backend likely returns an authentication error (jsonCode 407 or similar), which triggers the reauthentication middleware or forces a sign-out.

    The fix requires EITHER:

    1. Revert PR Allow full Copilot users to access Expensify Card pages #81817 to restore the original delegate access restrictions (recommended for immediate unblock)
    2. Deploy backend changes first, then re-merge the frontend PR
  7. MelvinBot commented on Feb 26, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When a Copilot user (User B) with full delegate access acts on behalf of User A and issues a new Expensify Card through the magic code flow, User B is force-signed out after entering the magic code. The card is successfully created, but the user's session is disrupted.

    What is the root cause of that problem?

    PR #81817 changed the frontend delegate access guards on the card issuance pages from blocking all delegates to only blocking submitter-only delegates, allowing full Copilot users (role=all) to reach the card issuance flow. However, the delegate's restricted auth token can expire during the magic code flow (while waiting for User A to share the code), or the backend may not fully accept the restricted token for the CreateAdminIssuedVirtualCard/CreateExpensifyCard commands.

    When any API call returns a 407 NOT_AUTHENTICATED while connected as a delegate, the Reauthentication middleware triggers re-authentication using the stashed credentials — which belong to User B's original account, not User A's. The code at Authentication.ts:197-203 detects the delegate session and calls restoreDelegateSession(), which clears Onyx and restores User B's original session at Delegate.ts:698-709. From the user's perspective, this looks like a force sign-out.

    The card is still created because the backend processes the creation request before the token issue manifests on a subsequent API call (explaining the "sometimes the user will force sign out after navigating to another section" symptom).

    The PR body itself explicitly states: "The backend change (allowing ROLE_ALL auth token type for CreateAdminIssuedVirtualCard command) is out of scope for this frontend PR and needs to be handled separately."

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

    The fix requires a backend change to ensure the CreateAdminIssuedVirtualCard and CreateExpensifyCard commands accept the ROLE_ALL restricted auth token type used by delegate sessions. This was explicitly called out as out of scope in the original PR #81817.

    Additionally, to improve resilience for the magic code flow specifically, the frontend could extend the IssueNewCardConfirmMagicCodePage to handle the delegate token expiration more gracefully — for example, by detecting the delegate session state and warning the user or refreshing the delegate token before submitting the card creation request, rather than allowing the silent sign-out.

    What alternative solutions did you explore? (Optional)

    1. Revert PR Allow full Copilot users to access Expensify Card pages #81817 to re-block all delegates from the card issuance flow until the backend change is deployed. This is the simplest immediate fix if the backend change is not ready.
    2. Add a delegate token refresh before the CreateExpensifyCard/CreateAdminIssuedVirtualCard API call to ensure the token is still valid after the user enters the magic code.
    Detailed Investigation

    Evidence Chain

    1. PR Allow full Copilot users to access Expensify Card pages #81817 changed the access guard — IssueNewCardPage.tsx:53,135 uses isDelegateAccessRestricted (from DelegateNoAccessModalProvider/index.tsx:28), which only blocks submitter-only delegates via AccountUtils.isDelegateOnlySubmitter. Full copilots (role=all) pass through.

    2. Delegate sessions use restricted tokens — When a delegate connects via Delegate.connect(), they receive a restrictedToken (not a full authToken). The delegate's original credentials are stashed in STASHED_CREDENTIALS and STASHED_SESSION.

    3. Magic code is sent to the delegator (User A) — The ResendValidateCode command takes no parameters and uses the current session identity (User A's in delegate mode). The magic code page displays User A's email at IssueNewCardConfirmMagicCodePage.tsx:28.

    4. Card creation uses API.write() — issueExpensifyCard() sends CreateAdminIssuedVirtualCard or CreateExpensifyCard through the sequential queue. Client-side Onyx updates only touch ISSUE_NEW_EXPENSIFY_CARD — no session data.

    5. 407 triggers delegate session restoration — The Reauthentication middleware catches NOT_AUTHENTICATED responses. The reauthenticate() function detects delegate mode and calls restoreDelegateSession(), which clears Onyx and restores User B's own session.

    Open Questions

    • Has the backend change for ROLE_ALL auth token type on card creation commands been deployed yet?
    • Does the restricted delegate token expire during the magic code wait time, or does the backend reject the command outright?
    • Is CreateExpensifyCard (physical card) affected the same way as CreateAdminIssuedVirtualCard (virtual card)?

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  8. 18 remaining items

  9. inimaga commented on Feb 26, 2026

    @inimaga
    Contributor

    Demoting this for now. See here for reasoning.

  10. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    ExternalAdded to denote the issue can be worked on by a contributor
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 26, 2026
  11. rushatgabhane commented on Mar 1, 2026

    @rushatgabhane
    Member

    Looks all good now

    Screen.Recording.2026-03-01.at.23.08.35.mov
  12. rushatgabhane commented on Mar 1, 2026

    @rushatgabhane
    Member

    can close after @jponikarchuk retests

  13. trjExpensify commented on Mar 2, 2026

    @trjExpensify
    Contributor

    What did the retest say?

  14. jponikarchuk commented on Mar 2, 2026

    @jponikarchuk
    Author

    @rushatgabhane @trjExpensify Issue is not reproducible for me now

    bandicam.2026-03-02.21-06-22-547.mp4
  15. trjExpensify commented on Mar 2, 2026

    @trjExpensify
    Contributor

    Perfect, closing!

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions