Skip to content

Company card- Can assign the same card Wells Fargo direct feed for 2 workspaces #82554

Closed

Description

@nlemma

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.18-6
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/TR-5132/folder/13176706/41236862/1186705757
Email or phone of affected tester (no customers): N/A
Issue reported by: Applause Internal Team
Bug source: Regression TC Execution
Device used: Win 11/Chrome
App Component: Workspace Settings

Action Performed:

Precondition: Create 2 workspaces added Plaid - Wells Fargo direct feed with select Plaid credit card 3333

  1. Open app
  2. Navigate to Company card of the first workspace
  3. Assign Plaid credit card 3333 for admin
  4. Navigate to Company card of the second workspace
  5. Assign Plaid credit card 3333 for employee

Expected Result:

Error should display when assign the same Plaid credit card 3333 for second workspace

Actual Result:

User can assign Plaid credit card 3333 for second workspace

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7076993_1770996256210.Recording__1813.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @youssef-lr

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Feb 16, 2026
  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 16, 2026
  3. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Feb 16, 2026
  4. melvin-bot commented on Feb 16, 2026

    @melvin-bot

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

  5. melvin-bot commented on Feb 16, 2026

    @melvin-bot

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

  6. melvin-bot commented on Feb 16, 2026

    @melvin-bot

    Triggered auto assignment to @CortneyOfstad (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.

  7. ubaidsk commented on Feb 16, 2026

    @ubaidsk
    Contributor

    Proposal

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

    When someone assigns a direct-feed company card in one workspace, the app does not detect that the same card is already assigned in another workspace. Because of that, the same direct-feed card can be assigned twice, which should not happen.

    What is the root cause of that problem?

    The root cause is in isCardAlreadyAssigned() in src/libs/CardUtils.ts.

    https://github.com/Expensify/App/blob/19cf92bcd2a/src/libs/CardUtils.ts#L1109-L1143

    The function previously filtered card-feed entries strictly to feedDomainID === domainOrWorkspaceAccountID for every call. In the assign-card confirmation flow, ConfirmationStep.submit() called this function without any mode that allows cross-workspace scanning for direct feeds, so cards assigned in other workspace accounts were not considered duplicates.

    https://github.com/Expensify/App/blob/19cf92bcd2a/src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx#L94-L125

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

    1. Update isCardAlreadyAssigned() to support two explicit behaviors:
      • default behavior: preserve current scope-limited check for non-direct feeds
      • direct-feed behavior: allow checking across all workspace accounts by adding a new boolean argument (shouldCheckAcrossAllWorkspaceAccounts, default false)
    2. In ConfirmationStep.submit(), pass isDirectFeed(feed) as that new argument so direct feeds use cross-workspace duplicate detection while other feeds keep current behavior.
    3. Keep existing matching and safety behavior unchanged:
      • continue matching by encrypted number or card display name
      • continue skipping cards pending deletion
      • continue rejecting malformed Onyx keys
    4. Lock this behavior with unit tests in CardUtilsTest that verify:
      • default mode only checks the provided workspace account
      • cross-workspace mode finds duplicates in other workspace accounts
      • cross-workspace mode still ignores cards pending deletion

    https://github.com/Expensify/App/blob/19cf92bcd2a/tests/unit/CardUtilsTest.ts#L2711-L2763

    Expected outcome: when assigning a direct-feed card, the app blocks assignment if that card is already assigned in any workspace account within the relevant domain/workspace-account scope; behavior for non-direct feeds remains unchanged.

    What alternative solutions did you explore? (Optional)

  8. HiepPP commented on Feb 16, 2026

    @HiepPP
    Contributor

    Proposal

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

    Assigning the same Plaid direct-feed credit card across two different workspaces succeeds silently instead of showing the "card already assigned" error.

    What is the root cause of that problem?

    There is a behavioral inconsistency between card selection and card confirmation for direct feeds.

    During card selection, getFilteredCardList() correctly collects assigned cards from every workspace and filters them out — so the card dropdown already hides cross-workspace duplicates:

    App/src/libs/CardUtils.ts

    Lines 799 to 811 in 317057c

    const allWorkspaceAssignedCards = new Set<string>();
    for (const workspaceCards of Object.values(workspaceCardFeeds ?? {})) {
    if (!workspaceCards) {
    continue;
    }
    const {cardList, ...workspaceCardItems} = workspaceCards;
    for (const card of Object.values(workspaceCardItems)) {
    if (!card?.cardName) {
    continue;
    }
    allWorkspaceAssignedCards.add(card.cardName);
    }
    }

    However, the confirmation-step validation does not follow the same pattern. getDomainOrWorkspaceAccountID() returns cardFeedData.domainID ?? workspaceAccountID. Direct feeds lack a shared domainID, so each workspace resolves to its own isolated account ID:

    App/src/libs/CardUtils.ts

    Lines 717 to 719 in 317057c

    function getDomainOrWorkspaceAccountID(workspaceAccountID: number, cardFeedData: CardFeedData | undefined): number {
    return cardFeedData?.domainID ?? workspaceAccountID;
    }

    That isolated ID is then passed into the duplicate check, which uses it to scope its scan to a single workspace. Cards assigned under a different workspace account are skipped entirely, so the duplicate goes undetected at confirmation time.

    const domainOrWorkspaceAccountID = getDomainOrWorkspaceAccountID(workspaceAccountID, companyCardFeedData);

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

    Align the confirmation validation with the selection filtering by making the duplicate check feed-type-aware:

    1. In isCardAlreadyAssigned() (src/libs/CardUtils.ts), accept the feed name as a new parameter. Use the existing isDirectFeed() utility to decide whether the domain-scoped guard applies: for direct feeds, bypass it so all workspace entries are scanned; for commercial feeds, keep the current scoped behavior unchanged.

    2. In ConfirmationStep.submit() (src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx), forward the feed value (already available via route.params.feed) into the updated duplicate-check call.

    This brings the confirmation validation in line with the cross-workspace approach getFilteredCardList() already uses at the selection step.

    What alternative solutions did you explore? (Optional)

    A generic boolean toggle would also work, but passing the feed name lets the function decide internally via isDirectFeed(), keeping the call site simple and the logic tied to the actual feed type rather than an opaque flag.

  9. paulnjs commented on Feb 16, 2026

    @paulnjs
    Contributor

    Proposal

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

    User can assign Plaid credit card 3333 for second workspace

    What is the root cause of that problem?

    The code checks cardFeedKeyParts.at(0) !== ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, which compares "cards" vs "cards_" (with trailing underscore). This never matches, so the function silently skips every entry and always returns false.

    if (cardFeedKeyParts.length !== 3 || cardFeedKeyParts.at(0) !== ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST || Number.isNaN(feedDomainID)) {

    Additionally, cardFeedKeyParts.length !== 3 fails for Plaid feeds (e.g we have Onyx key: "cards_12345_plaid.ins_19", length in this case is 4 due to underscore in plaid.ins_19).

    Even the bug above were fixed, feedDomainID !== domainOrWorkspaceAccountID explicitly skips cards from other workspaces. Since each workspace has a unique domain ID, Plaid cards assigned in workspace 1 are invisible when checking from workspace 2.

    if (feedDomainID !== domainOrWorkspaceAccountID) {

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

    1. For key parsing:
      Use key.replace(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, '') + split on first _ only (matching the pattern in

      const feedKey = key.replace(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, '');

    2. Fix cross-workspace check:
      For direct feeds (Plaid/OAuth), check across all workspaces with the same feed name. For commercial feeds, keep domain-scoped check to avoid false positives.

    Introduce new param feedName and pass bankName in ConfimationStep.tsx
    Update isCardAlreadyAssigned function

    App/src/libs/CardUtils.ts

    Lines 1114 to 1127 in 317057c

    return Object.entries(workspaceCardFeeds).some(([key, workspaceCards]) => {
    if (!workspaceCards) {
    return false;
    }
    const cardFeedKeyParts = key.split('_');
    const feedDomainID = Number(cardFeedKeyParts.at(1));
    if (cardFeedKeyParts.length !== 3 || cardFeedKeyParts.at(0) !== ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST || Number.isNaN(feedDomainID)) {
    return false;
    }
    if (feedDomainID !== domainOrWorkspaceAccountID) {
    return false;
    }

    to:

        const isDirectFeedType = isDirectFeed(feedName);
    
        return Object.entries(workspaceCardFeeds).some(([key, workspaceCards]) => {
            if (!workspaceCards) {
                return false;
            }
    
            const feedKey = key.replace(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, '');
            const separatorIndex = feedKey.indexOf('_');
            if (separatorIndex === -1) {
                return false;
            }
    
            const feedDomainID = Number(feedKey.substring(0, separatorIndex));
            const feedBankName = feedKey.substring(separatorIndex + 1);
    
            if (Number.isNaN(feedDomainID) || !feedBankName) {
                return false;
            }
    
            if (isDirectFeedType) {
                if (feedName && feedBankName !== feedName) {
                    return false;
                }
            } else if (feedDomainID !== domainOrWorkspaceAccountID) {
                return false;
            }

    What alternative solutions did you explore? (Optional)

    N/A

    Screen.Recording.2026-02-16.at.21.08.52.mov
  10. twilight2294 commented on Feb 17, 2026

    @twilight2294
    Contributor

    Proposal

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

    A user can assign the same Wells Fargo (or other direct feed) company card to two different workspaces, when this should be blocked. The duplicate-assignment guard at confirmation time silently fails and always permits the assignment.

    What is the root cause of that problem?

    The root cause is in isCardAlreadyAssigned() in src/libs/CardUtils.ts (lines 1109–1134). The function contains a fatal string comparison bug that makes it always return false, completely disabling the duplicate check.

    The Onyx key format is cards_<fundID>_<bankName> (e.g. cards_12345_oauth.chase.com). The function splits the key on _ and then checks cardFeedKeyParts.at(0) !== ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST. However, ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST is "cards_" (with a trailing underscore), while splitting on _ produces "cards" as the first element. Since "cards" !== "cards_" is always true, the early-return guard always fires and the function always returns false.

    https://github.com/Expensify/App/blob/main/src/libs/CardUtils.ts#L1109-L1134

    A second issue compounds this: the feedDomainID !== domainOrWorkspaceAccountID filter on line 1125 would prevent cross-workspace detection even if the parsing were fixed, because each workspace has its own unique account ID. So a card assigned in workspace A would never be flagged when assigning to workspace B. The caller in ConfirmationStep.tsx passes domainOrWorkspaceAccountID which further scopes the check to only the current workspace.

    https://github.com/Expensify/App/blob/main/src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx#L107-L113

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

    Fix isCardAlreadyAssigned() in src/libs/CardUtils.ts with two changes:

    1. Replace the broken split('_')[0] !== ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST check with key.startsWith(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST) to correctly validate Onyx keys.
    2. Remove the domainOrWorkspaceAccountID filter entirely so the function scans all workspace card feeds, enabling cross-workspace duplicate detection.

    The simplified function would look like:

    function isCardAlreadyAssigned(cardNumberToCheck: string, workspaceCardFeeds: OnyxCollection<WorkspaceCardsList>): boolean {
        if (!cardNumberToCheck || !workspaceCardFeeds) {
            return false;
        }
        return Object.entries(workspaceCardFeeds).some(([key, workspaceCards]) => {
            if (!workspaceCards || !key.startsWith(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST)) {
                return false;
            }
            const {cardList, ...assignedCards} = workspaceCards;
            return Object.values(assignedCards).some(
                (card) => card && card.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && isMatchingCard(card, cardNumberToCheck, cardNumberToCheck),
            );
        });
    }

    Remove the domainOrWorkspaceAccountID argument from the call site in ConfirmationStep.tsx (line 110) to match the updated signature.

    What alternative solutions did you explore? (Optional)

    An alternative is to keep the domain-scoped filter but add a shouldCheckAcrossAllWorkspaces flag (as proposed by ubaidsk/HiepPP), only bypassing the domain filter for direct feeds. This is more conservative but adds complexity. Since the simplest correct behavior is to check all workspaces globally (matching how getFilteredCardList() already works at the selection step), removing the filter entirely is the cleaner fix.

  11. yatin-italy commented on Feb 17, 2026

    @yatin-italy

    Proposal

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

    A Plaid Wells Fargo direct-feed credit card can be assigned to more than one workspace because when the same card is already assigned in Workspace A, the app still allows assigning it again in Workspace B instead of blocking the second assignment and showing an error.

    What is the root cause of that problem?

    In this implementation, submit() in src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx assumes one identifier is enough when calling CardUtils.isCardAlreadyAssigned, but the same physical Plaid card can be represented in different workspaces by different fields (encryptedCardNumber in one feed and cardName in another), so passing only cardToAssign?.encryptedCardNumber ?? cardToAssign?.cardName can miss the existing assignment and fail to enforce the “already assigned in any workspace” rule implemented in src/libs/CardUtils.ts in isCardAlreadyAssigned.

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

    Pass both encryptedCardNumber and cardName into the existing helper so the same card is detected in any workspace regardless of which field is stored there, by extending the utility to accept multiple identifiers while keeping a single call at the call site.

    1. src/libs/CardUtils.ts — isCardAlreadyAssigned
    • Change the first parameter from string to string | string[].
    • Normalize to an array (filter empty); if the array is empty or workspaceCardFeeds is missing, return false.
    • For each workspace feed and each assigned card (excluding pending delete), return true if any of the given identifiers equals card.encryptedCardNumber or card.cardName.
    • Passing a single string remains valid (normalize to a one-element array).
    const identifiers = Array.isArray(cardIdentifiers) ? cardIdentifiers.filter(Boolean) : cardIdentifiers ? [cardIdentifiers] : []
    identifiers.some((id) => card?.encryptedCardNumber === id || card?.cardName === id)
    1. src/pages/workspace/companyCards/assignCard/ConfirmationStep.tsx — submit()
    • Build an array of both identifiers: [cardToAssign?.encryptedCardNumber, cardToAssign?.cardName].filter(Boolean).
    • Call isCardAlreadyAssigned(cardIdentifiers, workspaceCardFeeds). If true, set the existing error workspace.companyCards.cardAlreadyAssignedError and return without calling assignWorkspaceCompanyCard.
    const cardIdentifiers = [cardToAssign?.encryptedCardNumber, cardToAssign?.cardName].filter(Boolean) as string[]
    if (cardIdentifiers.length > 0 && isCardAlreadyAssigned(cardIdentifiers, workspaceCardFeeds)) { setCardError(...); return; }.

    Scope: Two files only. No new Onyx keys, no API changes, no new translation keys. Regression risk is limited to the assign-card confirmation flow; the single existing caller of isCardAlreadyAssigned continues to work when passed a single string.

    What alternative solutions did you explore? (Optional)

    Calling isCardAlreadyAssigned twice in ConfirmationStep (once per identifier): Would work but duplicates the “already assigned” logic at the call site; extending the utility keeps the rule in one place.
    Backend-only enforcement: Does not fix the case where the client already has the other workspace’s data; can be added later as a complement.
    Guard elsewhere (e.g. before navigation): Would duplicate the same rule; the single check at submit with both identifiers is sufficient.
    New selector or Onyx shape: Not needed; WORKSPACE_CARDS_LIST and isCardAlreadyAssigned already support “any workspace”; the fix is to pass both identifiers.

  12. 16 remaining items

  13. suneox commented on Mar 16, 2026

    @suneox
    Contributor

    @CortneyOfstad The PR was deployed to production over a week ago, so this issue is ready for payment.

  14. melvin-bot commented on Mar 20, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @youssef-lr, @CortneyOfstad, @suneox, @paulnjs eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  15. suneox commented on Mar 24, 2026

    @suneox
    Contributor

    @CortneyOfstad This issue is ready for payment

  16. melvin-bot commented on Mar 31, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  17. CortneyOfstad commented on Mar 31, 2026

    @CortneyOfstad
    Contributor

    @paulnjs — I sent you an offer here. Please let me know once you accept and I'll get that paid ASAP.

    Regression test

    Will do a proper payment summary when offer is accepted

  18. paulnjs commented on Apr 1, 2026

    @paulnjs
    Contributor

    @CortneyOfstad I accepted the offer. Thank you!

  19. mallenexpensify commented on Apr 2, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @paulnjs paid $250 via Upwork
    Contributor+: @suneox due $250 via NewDot

    Thx

  20. trjExpensify commented on Apr 2, 2026

    @trjExpensify
    Contributor

    approved $250 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.ExternalAdded to denote the issue can be worked on by a contributorMelvin TriageAutomatic AI Analysis of an issueMonthlyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions