← Back to Pull requests

fix: persist iOS SDK deeplink connections only after user approval #2185

Open
unknown opened this pull request with 524 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 06, 2026 19:25 UTC
Author

Summary


Fixes code-scan finding sfind-0b29e37e0223451dbcc47df2e14a6136 (medium): DeeplinkProtocolService saved a new iOS SDK deeplink connection with addDappConnection before asking the user for permission, and never removed it after the user rejected. After an app restart, init() loaded the rejected channel and created a BackgroundBridge for it. handleMessage then sent its RPCs straight to that bridge, without the re-authorization prompt that normally runs when a channel has no bridge.

Changes in app/core/SDKConnect/SDKDeeplinkProtocol/DeeplinkProtocolService.ts:

 handleConnection(params)
-  await SDKConnect.addDappConnection({...})   // before approval
   this.handleConnectionEventAsync({ clientInfo, params })

 handleConnectionEventAsync
+  isConnectionEstablished = !isNewConnection
   try {
     checkPermission() -> setupBridge() -> connections[id] = ... -> addDappConnection()  // only saved after approval
+    isConnectionEstablished = true
   } catch {
+    if (!isConnectionEstablished) await discardUnapprovedConnection(id)
     ...send JSON-RPC error to the dapp (unchanged)
   }

 init()
   for each persisted connection:
+    if (!hasCaip25Permission(id)) skip      // no CAIP-25 permission (or reading it fails) -> no session, no bridge

  • discardUnapprovedConnection(id) clears connections, bridgeByClientId and dappPublicKeyByClientId, then calls SDKConnect.removeChannel({ channelId, sendTerminate: false }). That call also clears SDKConnect/Redux state and revokes any permissions for the channel.

  • If a request fails on a session that was already established, the session is kept. Only new connections that never finished approval are removed.
  • Tests (DeeplinkProtocolService.test.ts, 7 new):

  • init skips persisted connections that have no CAIP-25 permission, or whose permissions can't be read.

  • Nothing is saved before approval.

  • A rejected connection is removed.

  • A connection whose bridge setup fails is removed.

  • An established session survives a later failure.

  • Restart round trip: reject, then restart with a mocked persisted store, then an mmsdk message. The message gets 4100 Unauthorized request and no bridge is created.
  • Local results: jest DeeplinkProtocolService.test.ts passes 27/27. Prettier is clean. tsc shows no errors in SDKConnect files.

    Notes for reviewers:

  • The scan reported this finding against GTM-COG-PHIL/metamask-mobile. The Devin git integration has no access to that repo (403 on push), so the same fix is ported here to the COG-GTM fork, where the same pattern exists (handleConnection called addDappConnection before approval).

  • Earlier SDK deeplink PRs for other findings may overlap with this one. Only one of them should land.
  • Devin-Org: engineering

    Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/268750aef6b34e2eaa77c661a809887e
    Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/268750aef6b34e2eaa77c661a809887e?variant=devin
    <!-- devin-review-badge-staging-begin -->

    ---

    Devin Review


    | Status | Commit |
    |---|---|
    | ⚪ Not started | — |

    Run Devin Review

    Enable auto-review to review your pull requests automatically.

    <a href="https://staging.itsdev.in/review/cog-gtm/metamask-mobile/pull/2185" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-staging-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-staging-light.svg?v=4" alt="Devin Review (Staging)"></picture></a>
    <!-- devin-review-badge-staging-end -->
    <!-- devin-review-badge-begin -->

    ---

    <a href="https://devin-gtm.devinenterprise.com/review/cog-gtm/metamask-mobile/pull/2185" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    Diff: 524 lines (+393 / -131) across 6 files Reviewer: devin-ai-integration[bot] Review duration: 21m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.48) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 524 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.375
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #2185"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.5% · Safe to merge
    25.5%