Skip to content

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

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

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.

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