Skip to content

fix: accept ip literal domain in Siwe messages - #696

Closed
gomesalexandre wants to merge 1 commit into
wevm:mainfrom
gomesalexandre:fix_siwe_ip_literal_domain
Closed

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

Conversation

@gomesalexandre

Copy link
Copy Markdown
Contributor

EIP-4361 defines domain = authority (RFC 3986), so a dapp served from http://[::1]:3000 signs in with domain [::1]:3000. Siwe.createMessage only accepts DNS names, IPv4 and localhost and throws on it, and Siwe.parseMessage returns {} for the resulting message because prefixRegex can't match [/]:

main:
[::cafe]           createMessage THREW Invalid Sign-In with Ethereum message field "domain".
[::1]:3000         createMessage THREW Invalid Sign-In with Ethereum message field "domain".
parseMessage("http://[::1]:3000 wants you to sign in ...")  -> {}

branch:
[::cafe]           create OK; parse domain="[::cafe]", parse -> create round-trips
[::1]:3000         create OK; parse domain="[::1]:3000", parse -> create round-trips
parseMessage(...)  -> { scheme: "http", domain: "[::1]:3000", ... }, validateMessage({ domain: "[::1]:3000", scheme: "http" }) -> true

I found this by running the official spruceid/siwe vectors (https://github.com/spruceid/siwe/tree/main/test) against Siwe: the domain ipv6 case in parsing_positive.json fails on main for both parse and create.

The change:

  • createMessage also accepts [literal] with an optional port. The literal can't contain whitespace and is checked by the existing isAuthority, which is what isUri already uses for IPv6 and IPvFuture hosts, so [zzz], [::1, [::300.0.0.0] and [::\t1] still throw.
  • prefixRegex gets a bracketed alternative for the domain group, so parseMessage reads the domain back. It is as lenient as the existing domain group: parse doesn't validate the domain, createMessage does, and validateMessage compares it exactly. A 100k-char [ input still parses in under a millisecond. I dropped the regexr.com/80gdj link 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, so legit.com@attacker.com wants you to sign in has 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 in createMessage, plus a parse -> create round trip of the vector message. The valid cases fail on main.

🤖 Generated with Claude Code

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

jxom commented Nov 19, 2026

Copy link
Copy Markdown
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 [evil.com@[::1] (new URL reads [evil.com as userinfo), so the literal regexes now exclude @ and [. Closing in favor of #705.

@jxom jxom closed this 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>
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.

2 participants