Skip to content

chore: move UrlStruct to shared lib - #174

Merged
ulissesferreira merged 3 commits into
mainfrom
chore/move-urlstruct-to-shared-pkg
Aug 19, 2026
Merged

chore: move UrlStruct to shared lib#174
ulissesferreira merged 3 commits into
mainfrom
chore/move-urlstruct-to-shared-pkg

Conversation

@taran-a

@taran-a taran-a commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Explanation

Move UrlStruct to the shared lib.
Refactor imports for Solana and Tron snaps.

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

@taran-a
taran-a requested a review from a team as a code owner August 19, 2026 15:09
@taran-a
taran-a requested a review from a team as a code owner August 19, 2026 15:09
@taran-a
taran-a deployed to default-branch August 19, 2026 15:09 — with GitHub Actions Active
@taran-a
taran-a force-pushed the chore/move-urlstruct-to-shared-pkg branch from 172e14b to 2a7a3a3 Compare August 19, 2026 15:39
@taran-a

taran-a commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@cursoragent review

@cursor

cursor Bot commented Aug 19, 2026

Copy link
Copy Markdown

Unable to authenticate your request. Please make sure to connect your GitHub account to Cursor. Go to Cursor

@ulissesferreira

Copy link
Copy Markdown
Contributor

@cursoragent review

@cursor

cursor Bot commented Aug 19, 2026

Copy link
Copy Markdown

Reviewed PR #174 and posted the comments there.

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.

Open in Web Open in Cursor 

@cursor

cursor Bot commented Aug 19, 2026

Copy link
Copy Markdown

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 Envtype 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.

@ulissesferreira
ulissesferreira added this pull request to the merge queue Aug 19, 2026
Merged via the queue into main with commit 0f898aa Aug 19, 2026
52 checks passed
@ulissesferreira
ulissesferreira deleted the chore/move-urlstruct-to-shared-pkg branch August 19, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants