Skip to content

fix(accounts-controller): guard undefined scopes in multichain listing - #9877

Open
rajanpanth wants to merge 1 commit into
MetaMask:mainfrom
rajanpanth:fix/accounts-controller-scopes-guard
Open

fix(accounts-controller): guard undefined scopes in multichain listing#9877
rajanpanth wants to merge 1 commit into
MetaMask:mainfrom
rajanpanth:fix/accounts-controller-scopes-guard

Conversation

@rajanpanth

@rajanpanth rajanpanth commented Aug 14, 2026

Copy link
Copy Markdown

Summary

Adds a guard for undefined scopes when listing multichain accounts in the accounts controller flow.

Why

Undefined scope payloads can surface in edge cases and currently trigger avoidable runtime failures.


Note

Low Risk
Narrow defensive change to account listing; well-formed accounts behave as before, with legacy entries silently excluded from chain-filtered lists.

Overview
Fixes a TypeError when listMultichainAccounts(chainId) runs against persisted internal accounts that lack a scopes array (legacy or partial migration).

Chain filtering now requires Array.isArray(account.scopes) before isScopeEqualToAny. Accounts with missing scopes are omitted from scoped results instead of crashing the call. A regression test and changelog entry document the behavior (#41962).

Reviewed by Cursor Bugbot for commit 43bdbf6. Bugbot is set up for automated code reviews on this repo. Configure here.

…ltichainAccounts`

`listMultichainAccounts(chainId)` filters accounts with
`isScopeEqualToAny(chainId, account.scopes)`, which calls `scopes.some(...)`.
`InternalAccount.scopes` is typed as required, but a legacy or partially
migrated account can be persisted without it, so `account.scopes` can be
`undefined` at runtime and throws a `TypeError`.

Guard the filter with `Array.isArray(account.scopes)` before matching. An
account without a valid `scopes` array declares no chain and is excluded from
chain-filtered results instead of throwing; unfiltered `listMultichainAccounts()`
is unchanged.
@rajanpanth
rajanpanth requested review from a team as code owners August 14, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant