Repository navigation
fix: accept ip literal domain in Siwe messages - #696
Closed
gomesalexandre wants to merge 1 commit into
Closed
gomesalexandre wants to merge 1 commit into
gomesalexandre wants to merge 1 commit into
Conversation
EIP-4361 defines `domain` as an RFC 3986 authority, so a dapp served
from `http://[::1]:3000` has domain `[::1]:3000`. `createMessage` only
allowed DNS names, IPv4 and localhost and threw on it, and `parseMessage`
returned `{}` for the message. The `domain ipv6` case of the official
spruceid/siwe `parsing_positive.json` vectors fails this way.
Userinfo authorities are left out on purpose: page origins never carry
userinfo, and `a.com@b.com wants you to sign in` only helps phishing.
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. |
Member
|
Thanks @gomesalexandre! We opened #705 combining this with #698 and #699 (they conflicted), crediting you as co-author. One fix on top: the IP literal check accepted |
This was referenced Nov 19, 2026
jxom
added a commit
that referenced
this pull request
Nov 19, 2026
#705) Rejects a comma in `scheme`, rejects `\r`, U+2028 and U+2029 in `statement`, and accepts IP literal `domain` values without letting a userinfo authority such as `[evil.com@[::1]` through. Supersedes #696, #698, and #699. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f5cc-eb3a-72b3-bdda-0480feddb7f9 Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com> Co-authored-by: jxom <jake@tempo.xyz>
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.
EIP-4361 defines
domain = authority(RFC 3986), so a dapp served fromhttp://[::1]:3000signs in with domain[::1]:3000.Siwe.createMessageonly accepts DNS names, IPv4 andlocalhostand throws on it, andSiwe.parseMessagereturns{}for the resulting message becauseprefixRegexcan't match[/]:I found this by running the official spruceid/siwe vectors (https://github.com/spruceid/siwe/tree/main/test) against
Siwe: thedomain ipv6case inparsing_positive.jsonfails on main for both parse and create.The change:
createMessagealso accepts[literal]with an optional port. The literal can't contain whitespace and is checked by the existingisAuthority, which is whatisUrialready uses for IPv6 and IPvFuture hosts, so[zzz],[::1,[::300.0.0.0]and[::\t1]still throw.prefixRegexgets a bracketed alternative for the domain group, soparseMessagereads the domain back. It is as lenient as the existing domain group: parse doesn't validate the domain,createMessagedoes, andvalidateMessagecompares it exactly. A 100k-char[input still parses in under a millisecond. I dropped theregexr.com/80gdjlink above it because it pointed at the old regex.I left userinfo authorities (
test@127.0.0.1, also in the vectors) out on purpose. A page origin never carries userinfo, solegit.com@attacker.com wants you to sign inhas no real producer and only helps phishing.Tests: valid
[::cafe],[::1]:3000,[2001:db8::1]:443,[v1.fe]and invalid[::1,[zzz],[::300.0.0.0],[::1]:123456,user@[::1],[::\t1]domains increateMessage, plus a parse -> create round trip of the vector message. The valid cases fail on main.🤖 Generated with Claude Code