Repository navigation
fix: validate the authority of Siwe.isUri URIs that have a path - #695
Merged
jxom merged 1 commit intoNov 19, 2026
Merged
Conversation
`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>
|
@gomesalexandre is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
Merged
jxom
added a commit
that referenced
this pull request
Nov 19, 2026
…l domains (#705) (#709) * fix(siwe): isUri rejects authority-only URIs with an empty path (#434) * fix(siwe): isUri rejects authority-only URIs with an empty path Siwe.isUri required scheme?.length && path && path.length >= 0 - the `path &&` guard short-circuited before the tautological length check ever ran, so any URI with an empty path (e.g. a bare origin like https://example.com) was rejected. The comment directly above states the opposite intent: "scheme and path are required, though the path can be empty". Per RFC 3986 an authority-only URI legitimately has an empty path component, and this is also the single most common SIWE uri value - Siwe.createMessage threw for https://login.xyz, the EIP-4361 reference example, and for any pathless entry in resources. viem's identical sibling function (utils/siwe/utils.ts) never had this guard and has always accepted these URIs correctly. Fix: drop the redundant `path &&`, matching viem exactly. path can never be undefined here - splitUri's third capture group is a mandatory (non-optional) regex group, always at least an empty string. Also corrects an existing pinned test ('behavior: invalid resources') that was unknowingly asserting the bug: with resources set to ['https://example.com', 'foo'], the old code rejected the FIRST entry (a legitimate bare-origin URI) instead of the actually-invalid second one. Fixed code correctly flags 'foo'. * fix(siwe): validate pathless URI authorities --------- Co-authored-by: jxom <7336481+jxom@users.noreply.github.com> (cherry picked from commit 633388e) * fix: validate the authority of `Siwe.isUri` URIs that have a path (#695) `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> (cherry picked from commit ccbb1af) * fix(0.x): accept ip literal `domain` in `Siwe` messages Ports the IP literal domain part of #705 (from #696). Bracketed literals exclude `@` and `[` so a userinfo authority such as `[evil.com@[::1]` cannot pass as a literal. Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1f5cc-eb3a-72b3-bdda-0480feddb7f9 Co-authored-by: jxom <jake@tempo.xyz> --------- Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: jxom <jake@tempo.xyz>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Siwe.isUrionly 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:createMessagerunsisUrionuriand on every resource, so on main it emits a message withURI: uri://[::300.0.0.0]/p/path, while the same URI without the path throwsInvalidMessageFieldError.I found this by running the official spruceid/siwe test vectors (https://github.com/spruceid/siwe/tree/main/test) against
Siwe. Two cases ininvalid_uris.jsonfail on main (IPv4 bad octets: uri://[::0.0.0.256]/p/pathanduri://[::300.0.0.0]/p/path), and the same two fail ininvalid_resources.json. With this change all 17 + 16 pass.valid_uris.jsonstays at 34 of 36 before and after: the two that fail areuri://[::000.000.010.001]anduri://[::001.099.200.255], which have leading zeros in the embedded IPv4. RFC 3986'sdec-octetdoesn't allow those, so ox is right to reject them.The
path.length === 0guard came from #434 (mine), which addedisAuthorityonly for the empty-path case it newly allowed. The path does not change what a valid authority is:splitUrialready cuts the authority at the first/,?or#. So the fix drops the guard, andisAuthoritynow 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