Skip to content

fix: validate the authority of Siwe.isUri URIs that have a path - #695

Open
gomesalexandre wants to merge 1 commit into
wevm:mainfrom
gomesalexandre:fix_siwe_isuri_authority_with_path
Open

gomesalexandre wants to merge 1 commit into
wevm:mainfrom
gomesalexandre:fix_siwe_isuri_authority_with_path

Conversation

@gomesalexandre

Copy link
Copy Markdown
Contributor

Siwe.isUri only checks the authority when the path is empty, so an authority it rejects on its own gets through as soon as a path follows it:

uri://[::300.0.0.0]              false
uri://[::300.0.0.0]/p/path       "uri://[::300.0.0.0]/p/path"
https://example.com:bad          false   (already pinned as invalid in Siwe.test.ts)
https://example.com:bad/login    "https://example.com:bad/login"
https://[::1/login               "https://[::1/login"

createMessage runs isUri on uri and on every resource, so on main it emits a message with URI: uri://[::300.0.0.0]/p/path, while the same URI without the path throws InvalidMessageFieldError.

I found this by running the official spruceid/siwe test vectors (https://github.com/spruceid/siwe/tree/main/test) against Siwe. Two cases in invalid_uris.json fail on main (IPv4 bad octets: uri://[::0.0.0.256]/p/path and uri://[::300.0.0.0]/p/path), and the same two fail in invalid_resources.json. With this change all 17 + 16 pass. valid_uris.json stays at 34 of 36 before and after: the two that fail are uri://[::000.000.010.001] and uri://[::001.099.200.255], which have leading zeros in the embedded IPv4. RFC 3986's dec-octet doesn't allow those, so ox is right to reject them.

The path.length === 0 guard came from #434 (mine), which added isAuthority only for the empty-path case it newly allowed. The path does not change what a valid authority is: splitUri already cuts the authority at the first /, ? or #. So the fix drops the guard, and isAuthority now runs whenever there is an authority. Everything that becomes rejected with a path was already rejected without one (a@b@c, h:80:90, [], [::1]x). That includes IPv6 zone ids like [fe80::1%25eth0], which RFC 3986 doesn't have (they come from RFC 6874).

Tests: invalid authorities with a path (the two vector URIs, https://example.com:bad/login, https://[:::]/login, https://[::1/login) and valid ones with a path (IPv6, userinfo + port, IPvFuture). The invalid cases fail on main.

🤖 Generated with Claude Code

`isUri` only ran `isAuthority` when the path was empty, so an authority it
rejects on its own (`uri://[::300.0.0.0]`, `https://example.com:bad`) was
accepted as soon as a path followed it, and `createMessage` emitted such
URIs. Two cases in the official spruceid/siwe `invalid_uris.json` vectors
fail this way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

@gomesalexandre is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant