Skip to content

Conversation

@Kriys94
Copy link
Contributor

@Kriys94 Kriys94 commented Oct 10, 2025

Description

This PR adds messenger allowlist support for the TokenBalancesController WebSocket integration introduced in MetaMask/core#6784.

What is the reason for the change?

The updated @metamask/assets-controllers package (v79.0.0+) includes a TokenBalancesController that can optionally receive real-time balance updates via WebSocket events from @metamask/core-backend services. Without updating the messenger allowlist in Engine.ts, the app would throw an error: Event missing from allow list: AccountActivityService:balanceUpdated.

What is the improvement/solution?

This PR makes minimal changes to support the new TokenBalancesController capabilities:

  1. Added dependency: @metamask/core-backend (^1.0.1) for TypeScript type definitions
  2. Updated messenger allowlist in Engine.ts for TokenBalancesController initialization:
    • Added events: AccountActivityService:balanceUpdated, AccountActivityService:statusChanged, BackendWebSocketService:connectionStateChanged
    • Added action: TokenDetectionController:addDetectedTokensViaWs

⚠️ Important - No Behavior Change:

Bumping the @metamask/assets-controllers version changes nothing about TokenBalancesController behavior. The controller will continue to work exactly as it does today using HTTP polling (180s interval).

Why? The WebSocket integration requires BackendWebSocketService and AccountActivityService to be initialized and connected. Since these services are not initialized in this PR, no WebSocket connection is established, and no real-time events are triggered. The TokenBalancesController gracefully detects their absence and continues using the existing HTTP polling mechanism.

This PR only updates the messenger allowlist to prevent validation errors when the controller checks for the optional WebSocket events.

Benefits:

  • ✅ Resolves messenger validation errors
  • Zero behavior change - identical HTTP polling as before
  • ✅ No runtime overhead - services are not initialized, no WebSocket connections
  • ✅ No performance impact - polling intervals unchanged (180s)
  • ✅ Future-ready for real-time balance updates when backend services are added

Changelog

CHANGELOG entry: null

Related issues

Fixes: #[issue number if applicable]

Related:

Manual testing steps

Feature: TokenBalancesController messenger allowlist update

  Scenario: user views wallet with token balances
    Given user has tokens in their wallet
    And the app is running with the updated allowlist

    When user navigates to the wallet view
    Then token balances load correctly
    And no console errors appear related to messenger allowlist
    And token balance polling continues to work at 180s intervals

Screenshots/Recordings

N/A - Internal infrastructure change with no UI or behavioral changes. TokenBalancesController continues to use HTTP polling exactly as before.

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@socket-security
Copy link

socket-security bot commented Oct 10, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​metamask/​core-backend@​1.0.17710010090100
Updatednpm/​@​metamask/​profile-sync-controller@​25.1.0 ⏵ 25.1.1991008797 +1100

View full report

@socket-security
Copy link

socket-security bot commented Oct 10, 2025

Caution

MetaMask internal reviewing guidelines:

  • Do not ignore-all
  • Each alert has instructions on how to review if you don't know what it means. If lost, ask your Security Liaison or the supply-chain group
  • Copy-paste ignore lines for specific packages or a group of one kind with a note on what research you did to deem it safe.
    @SocketSecurity ignore npm/PACKAGE@VERSION
Action Severity Alert  (click "▶" to expand/collapse)
Block Medium
npm/@metamask/[email protected] has Network access.

Module: globalThis["fetch"]

Location: Package overview

From: package.jsonnpm/@metamask/[email protected]

ℹ Read more on: This package | This alert | What is network access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@metamask/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
npm/@metamask/[email protected] is a AI-detected potential code anomaly.

Notes: The code implements a guarded, cache-accelerated path to sign a message via an external SnapController. No explicit malware indicators detected. Primary risks relate to API design and cache semantics: entropySourceId is currently unused in the cache key, which could cause mismatches between the signing policy and cached signatures; potential replay/reuse concerns if identical messages are signed for different intents without provenance. Recommended improvements: validate message format and provenance, incorporate entropySourceId into cache keys or policy checks, add audit logging, and implement cache eviction/invalidation rules to prevent stale signatures.

Confidence: 0.75

Severity: 0.55

From: package.jsonnpm/@metamask/[email protected]

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@metamask/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@Kriys94 Kriys94 force-pushed the feature/bump-assets-controller branch from 8bc6386 to 0199b1f Compare October 12, 2025 20:02
@sonarqubecloud
Copy link

@Kriys94 Kriys94 closed this Oct 16, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant