Skip to content
This repository was archived by the owner on Jul 31, 2026. It is now read-only.

fix: handle non-url origins - #340

Open
0xEdouardEth wants to merge 1 commit into
mainfrom
fix/validate-origin-url
Open

fix: handle non-url origins#340
0xEdouardEth wants to merge 1 commit into
mainfrom
fix/validate-origin-url

Conversation

@0xEdouardEth

@0xEdouardEth 0xEdouardEth commented Jun 24, 2026

Copy link
Copy Markdown

Explanation

This PR updates the Tron Snap origin formatter to handle the stable wallet-connect origin used by MetaMask Mobile WalletConnect multichain requests.

The change is intentionally limited to display formatting:

  • metamask is displayed as MetaMask;
  • wallet-connect is displayed as WalletConnect;
  • valid HTTP(S) URL origins are displayed as hostnames;
  • unknown invalid origins, such as WalletConnect channel IDs, format to an empty string so confirmation UI can avoid showing meaningless identifiers.

This PR no longer changes the Security Alerts / Blockaid request payload or transaction scan flow. Existing scan behavior, including the existing MetaMask origin URL mapping, is preserved.

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
    • N/A - no package changelog update needed for this internal behavior fix.
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them
    • N/A - this does not introduce a breaking API change.

Validation

yarn workspace @metamask/tron-wallet-snap jest packages/snap/src/utils/formatOrigin.test.ts --runInBand --coverage=false

Result: 1 test suite passed, 6 tests passed.

yarn eslint packages/snap/src/utils/formatOrigin.ts packages/snap/src/utils/formatOrigin.test.ts

Result: passed.


Note

Low Risk
Display-only formatting in confirmation UI with no changes to signing, scanning, or security payloads.

Overview
Updates formatOrigin so confirmation UIs can show stable Mobile/WalletConnect origins without surfacing raw channel IDs or invalid strings.

metamask and wallet-connect now resolve to MetaMask and WalletConnect via a case-insensitive lookup table. Valid http(s) URLs still show the hostname; other values (bare hostnames, parse failures, non-http schemes) return '' so {origin ? …} guards omit the origin row instead of echoing meaningless text.

Tests and an Unreleased changelog entry document the new behavior.

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 548af0c. Configure here.

// If not a valid URL, return the original value
// This shouldn't happen if validation is working correctly
return origin;
return '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unknown origin shows blank label

Medium Severity

Sign-transaction confirmation sets missing origins to the literal 'Unknown', then runs formatOrigin on that value. After this change, formatOrigin returns an empty string for non-URL strings, so the origin row still renders (the prop is truthy) but the value is blank instead of Unknown.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 548af0c. Configure here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant