Skip to content

fix(tron): report the MetaMask origin as lowercase - #392

Merged
Battambang merged 5 commits into
mainfrom
fix/tron-metamask-origin-casing
Sep 30, 2026
Merged

Battambang merged 5 commits into
mainfrom
fix/tron-metamask-origin-casing

Conversation

@Battambang

Copy link
Copy Markdown
Contributor

Explanation

MetaMask-initiated operations in the Tron snap reported their origin as the literal string MetaMask. That value is wrong in two ways. First, the keyring methods are actually granted to metamask (via DEFAULT_METAMASK_ORIGIN), so onKeyringRequest always receives the lowercase origin, and the other non-EVM snaps (Bitcoin, Solana, Stellar) consistently use metamask as well. Second, TransactionScanService only maps the lowercase metamask to https://metamask.io before calling the security alerts API, so Tron's MetaMask fell through that normalization and was sent verbatim, misattributing every MetaMask-initiated Tron scan.

The fix introduces a single METAMASK_ORIGIN = 'metamask' constant and uses it for every MetaMask-initiated origin: the unified send flow's Transaction Submitted tracking, the confirmation context passed to confirmTransactionRequest, the confirmSignTransaction context, and the Transaction Finalized event emitted by the background tracker. SendService.signAndSendTransaction's default parameter now uses the same constant. TransactionScanService imports the constant instead of declaring its own private copy, so the normalization it already performed now actually applies to these call sites.

The confirmation UI keeps displaying MetaMask to the user: ConfirmTransactionRequest now renders the origin through the existing case-insensitive formatOrigin helper, so the stored and reported value is the lowercase canonical origin while the displayed label is unchanged. ConfirmSignTransaction already used formatOrigin.

The result is that MetaMask-initiated Tron scans are correctly attributed to https://metamask.io, the analytics origin matches the value used by the other non-EVM snaps, and the user-facing confirmation is unaffected.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

MetaMask-initiated operations reported their origin as `MetaMask`, while the
keyring methods are granted to `metamask` and the other non-EVM snaps use the
lowercase value. Because `TransactionScanService` only maps `metamask` to
`https://metamask.io`, Tron transaction scan requests were sent with the
literal `MetaMask` origin instead.

- Add a `METAMASK_ORIGIN` constant and use it for every MetaMask-initiated
  origin (unified send, confirmations, submitted/finalized tracking).
- Reuse the constant in `TransactionScanService` so the normalization applies.
- Keep displaying `MetaMask` in the confirmation UI via `formatOrigin`.
@Battambang
Battambang force-pushed the fix/tron-metamask-origin-casing branch from e95b77b to 5669b46 Compare September 30, 2026 14:36
Reformat the files touched by the previous commit so `yarn lint:misc:check`
passes: reorder the `formatOrigin` import and unwrap two `expect` calls.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The confirmation handler converts the lowercase origin back to MetaMask before the security scan, leaving the reported scan origin incorrect.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Canonicalizes MetaMask-initiated Tron operations to the lowercase metamask origin.

Changes:

  • Adds and applies a shared METAMASK_ORIGIN constant.
  • Preserves the user-facing MetaMask label via formatOrigin.
  • Adds normalization tests and updates the changelog and bundle checksum.
File Description
packages/​tron-wallet-snap/​src/​constants/​index.ts Defines the canonical origin.
packages/​tron-wallet-snap/​src/​handlers/​clientRequest/​clientRequest.ts Updates unified-send origins.
packages/​tron-wallet-snap/​src/​handlers/​clientRequest/​clientRequest.test.ts Updates unified-send expectations.
packages/​tron-wallet-snap/​src/​handlers/​cronjob/​cronjob.tsx Updates finalized-event origin.
packages/​tron-wallet-snap/​src/​handlers/​cronjob/​cronjob.test.tsx Updates cron expectations.
packages/​tron-wallet-snap/​src/​services/​confirmation/​ConfirmationHandler.ts Updates claim confirmation origin.
packages/​tron-wallet-snap/​src/​services/​confirmation/​ConfirmationHandler.test.ts Updates confirmation expectations.
packages/​tron-wallet-snap/​src/​services/​send/​SendService.ts Changes the default send origin.
packages/​tron-wallet-snap/​src/​services/​send/​SendService.test.ts Updates send analytics expectations.
packages/​tron-wallet-snap/​src/​services/​transaction-scan/​TransactionScanService.ts Reuses the shared origin constant.
packages/​tron-wallet-snap/​src/​services/​transaction-scan/​TransactionScanService.test.ts Tests origin normalization.
packages/​tron-wallet-snap/​src/​ui/​confirmation/​views/​ConfirmTransactionRequest/​render.tsx Updates default confirmation context.
packages/​tron-wallet-snap/​src/​ui/​confirmation/​views/​ConfirmTransactionRequest/​render.test.tsx Updates render expectations.
packages/​tron-wallet-snap/​src/​ui/​confirmation/​views/​ConfirmTransactionRequest/​ConfirmTransactionRequest.tsx Formats the displayed origin.
packages/​tron-wallet-snap/​src/​ui/​confirmation/​views/​ConfirmTransactionRequest/​ConfirmTransactionRequest.test.tsx Uses the canonical test origin.
packages/​tron-wallet-snap/​snap.manifest.json Updates the bundle checksum.
packages/​tron-wallet-snap/​CHANGELOG.md Documents the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

`confirmTransactionRequest` formatted the origin before handing it to the
confirmation view, and the view passes the stored origin straight to the
transaction scan. The scan normalizes only the lowercase `metamask` to
`https://metamask.io`, so every MetaMask-initiated scan was sent the literal
`MetaMask` and never resolved to the MetaMask URL, both on the initial scan
and on each background refresh.

Keep the raw origin in the interface context and format it only at the display
leaf, matching `ConfirmSignTransaction` and `ConfirmSignMessage`.
`ConfirmTransactionRequest` already renders `formatOrigin(origin)`, so the
user-facing label is unchanged.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The canonical origin now flows consistently through scans, analytics, and confirmations with focused regression coverage.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@Battambang

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@Battambang
Battambang marked this pull request as ready for review September 30, 2026 15:50
@Battambang
Battambang requested a review from a team as a code owner September 30, 2026 15:50
@Battambang
Battambang deployed to default-branch September 30, 2026 15:50 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/bitcoin-wallet-snap@3.1.0-preview-757ad9e
@metamask-previews/snap-networks-utils@1.0.0-preview-757ad9e
@metamask-previews/solana-wallet-snap@7.0.0-preview-757ad9e
@metamask-previews/stellar-wallet-snap@1.1.0-preview-757ad9e
@metamask-previews/tron-wallet-snap@4.0.0-preview-757ad9e

Comment thread packages/tron-wallet-snap/snap.manifest.json Outdated
Comment thread packages/tron-wallet-snap/src/constants/index.ts
taran-a
taran-a previously approved these changes Sep 30, 2026

@taran-a taran-a left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, GG. just couple tiny comments/questions.

`mm-snap build` regenerates `source.shasum`, and CI already ignores
shasum-only drift: require-clean-working-directory skips it and
require-correct-shasum only enforces it on release PRs. Drop the
restamped value so this fix does not carry a build artifact.

Ratchet the coverage thresholds.
@sonarqubecloud

Copy link
Copy Markdown

@Battambang
Battambang added this pull request to the merge queue Sep 30, 2026
Merged via the queue into main with commit 4a0f284 Sep 30, 2026
56 checks passed
@Battambang
Battambang deleted the fix/tron-metamask-origin-casing branch September 30, 2026 16:43
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.

3 participants