Skip to content

fix: use pairingTopic for permission revocation in removeSession()#27945

Merged
adonesky1 merged 2 commits into
mainfrom
ad/WAPI-1361/fix-removesession-permission-key
Mar 25, 2026
Merged

fix: use pairingTopic for permission revocation in removeSession()#27945
adonesky1 merged 2 commits into
mainfrom
ad/WAPI-1361/fix-removesession-permission-key

Conversation

@adonesky1

@adonesky1 adonesky1 commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Description

removeSession() calls permissionsController.revokeAllPermissions(session.topic), but permissions are stored under session.pairingTopic (used as channelId / origin when requestPermissions is called in _handleSessionProposal — lines 468, 581).

Since topic and pairingTopic are always different values, the revocation was targeting a non-existent subject and silently failing (caught by the surrounding try/catch). Stale permission entries accumulated in the PermissionController for every disconnected WC session.

This changes the revocation key to session.pairingTopic to match how permissions are created.

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/WAPI-1361

Changelog

CHANGELOG entry: Fixed - Fixed removeSession() using session.topic instead of session.pairingTopic when revoking WalletConnect permissions, which caused stale permission entries to persist in the PermissionController (#27945)

Manual testing steps

  1. Connect a dapp via WalletConnect
  2. Inspect PermissionController.state.subjects — the dapp's entry should be keyed by pairingTopic
  3. Disconnect the session (long-press in Settings > Experimental > WC Sessions)
  4. Inspect PermissionController.state.subjects — the entry should now be removed

Pre-merge author checklist


Note

Medium Risk
Changes how WalletConnect v2 session teardown revokes permissions, which impacts permission state cleanup and could affect disconnect behavior if the wrong identifier is used elsewhere. Scope is small and covered by an updated unit test.

Overview
Fixes WC2Manager.removeSession() to revoke permissions using session.pairingTopic (and logs that identifier) instead of session.topic, preventing stale PermissionController subjects from accumulating after disconnects.

Updates the WalletConnectV2 unit test to assert revokeAllPermissions is called with the pairing topic.

Written by Cursor Bugbot for commit 8ba16c9. This will update automatically on new commits. Configure here.

@adonesky1 adonesky1 requested a review from a team as a code owner March 25, 2026 19:38
@github-actions

Copy link
Copy Markdown
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.

@metamaskbot metamaskbot added the team-wallet-integrations Wallet Integrations team label Mar 25, 2026
@github-actions github-actions Bot added size-S risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 25, 2026
jiexi
jiexi previously approved these changes Mar 25, 2026
Permissions are created with origin = pairingTopic (channelId) in
_handleSessionProposal, but removeSession() was revoking using
session.topic — a different value. The revocation was silently
failing (caught by try/catch), leaving stale permission entries.

Fixes: https://consensyssoftware.atlassian.net/browse/WAPI-1361
@adonesky1 adonesky1 force-pushed the ad/WAPI-1361/fix-removesession-permission-key branch from a6e6748 to da94ec8 Compare March 25, 2026 21:23
@github-actions github-actions Bot added size-XS risk-medium Moderate testing recommended · Possible bug introduction risk and removed size-S risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 25, 2026
@adonesky1 adonesky1 added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label Mar 25, 2026
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 25, 2026
@adonesky1 adonesky1 force-pushed the ad/WAPI-1361/fix-removesession-permission-key branch from 9627828 to da94ec8 Compare March 25, 2026 22:07
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeNetworkAbstractions, SmokeMultiChainAPI, SmokeNetworkExpansion
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 78%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are a targeted bug fix in WalletConnectV2.ts: revokeAllPermissions was being called with session.topic (the session-specific topic) instead of session.pairingTopic (the pairing-level topic). This is a correctness fix for permission revocation when a WalletConnect V2 session is removed/disconnected.

Impact areas:

  • SmokeNetworkAbstractions: Directly relevant — this tag covers the chain permission system for dApps, including granting/revoking chain access. The fix ensures permissions are properly revoked when a WalletConnect session ends.
  • SmokeMultiChainAPI: Relevant — covers wallet_revokeSession and session management. The fix affects how sessions are cleaned up, which is core to CAIP-25 session lifecycle.
  • SmokeNetworkExpansion: Relevant — covers dApp connect/disconnect flows and multi-chain provider architecture. WalletConnect V2 is a primary dApp connection mechanism.

Why not broader tags: The change is isolated to WalletConnect V2 session removal logic. It doesn't affect swap/bridge flows, account management, confirmations (directly), or other wallet features. No UI changes, no performance impact.

Confidence note: Moderate confidence because there are no dedicated WalletConnect E2E tests found in the test directories, so the selected tags represent the closest coverage for dApp connection/permission flows that WalletConnect V2 supports.

Performance Test Selection:
The change is a pure logic bug fix (using pairingTopic instead of topic for permission revocation). There are no UI rendering changes, no data loading changes, no state management architecture changes, and no impact on app startup or critical user flow performance. No performance tests are warranted.

View GitHub Actions results

@adonesky1 adonesky1 enabled auto-merge March 25, 2026 22:22
@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@adonesky1 adonesky1 added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit 98e65ea Mar 25, 2026
110 checks passed
@adonesky1 adonesky1 deleted the ad/WAPI-1361/fix-removesession-permission-key branch March 25, 2026 23:09
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 25, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-XS team-wallet-integrations Wallet Integrations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants