You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The UrlStruct move is clean: Solana and Tron now share one export, the security suite still covers the original reject cases, and dropping the hostname/port checks does not weaken validation. CI is green.
A few cheap follow-ups before merge:
Add the #174 link on the snap-networks-utils changelog entry
Delete the duplicate UrlStruct tests still in Tron (Solana already did this)
Remove Solana’s unused refine import and drop the matching eslint suppression count
Pin the decodeURIComponent URIError path with a test
Stellar still has its own copy; that is out of this PR’s stated scope and is better as a follow-up.
Review: move UrlStruct to @metamask/snap-networks-utils
The extraction is sound: Solana and Tron now import a single named export, the shared suite still exercises the XSS / SQLi / traversal / pollution / CRLF / open-redirect cases, and the follow-up commit that dropped hostname-character and port checks does not look like a security regression. Those checks were redundant with the WHATWG URL parser plus the remaining pollution checks.
CI is green. Ready to merge with a few small fixes.
Important
1. Changelog entry is missing a PR link
packages/snap-networks-utils/CHANGELOG.md
- Add a `UrlStruct` utility for validating safe HTTP, HTTPS, and WebSocket URLs.
Repo convention requires ([#174](...)) on consumer-facing entries. changelog:validate will not catch this. Solana/Tron changelogs do not need entries — UrlStruct was never part of those snaps’ published surface.
2. Duplicate UrlStruct tests still live in Tron
Solana deleted its suite; Tron only switched the import:
packages/tron-wallet-snap/src/validation/structs.test.ts (the describe('UrlStruct', …) block)
That copy is already stale (it lacks the parser-input / hostname-pollution cases added in 2a7a3a31). Canonical tests belong in snap-networks-utils. Drop the Tron describe block.
3. Unused refine import in Solana
packages/solana-wallet-snap/src/core/validation/structs.ts still imports refine after UrlStruct moved. Tron cleaned this up. Lint still passes only because @typescript-eslint/no-unused-vars is suppressed at count 2 for that file. Remove refine and drop the suppression count to 1 (or fix the other unused symbol and prune the suppression).
4. decodeURIComponent URIError path is untested
In urlStruct.ts, malformed percent-encoding (https://example.com/%, %ZZ) throws inside the shared try/catch and is reported as Invalid URL format: URI malformed. Fail-closed, so not a bypass — but a later edit that moves decode out of the try would throw out of the struct. Pin this with a couple of cases.
Minor
JSDoc still lists the removed “Invalid hostname characters” check. Update it to match the simplified implementation.
Several clients split value/type imports from @metamask/snap-networks-utils. Prefer import { UrlStruct, type Logger } from '...' (ConfigProvider already combines value imports).
Drive-by export type Env → type Env in both ConfigProviders is unrelated but unused-export cleanup looks fine.
Out of scope / follow-up
Stellar still has a third copy in packages/stellar-wallet-snap/src/api/url.ts and does not depend on snap-networks-utils. Worth a follow-up so the copies do not drift (it still has the checks this PR removed).
Pre-existing denylist quirks (not introduced here, but this is now the shared primitive for API base URLs and token iconUrls):
Traversal is checked on the raw string, so encodings like %2e%2e%2f can slip past.
Any @ in the URL (including ?email=foo@bar.com) is rejected as protocol pollution.
ws: is rejected; only http:, https:, wss: are allowed. Solana validates RPC_WEB_SOCKET_URL_* with this struct. Product decision if localnet needs ws:.
Verdict: Approve with the four Important items above. None of them are merge-blockers for correctness, but 1–3 are cheap and should land in this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Move UrlStruct to the shared lib.
Refactor imports for Solana and Tron snaps.
References
Checklist