Repository navigation
fix(siwe): accept punycode top-level domains in createSiweMessage - #5299
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S1gnnWorzm4HFb366BK3sn
🦋 Changeset detectedLatest commit: 12e6ef2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01715f0cd0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| const domainRegex = | ||
| /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/ | ||
| /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+([a-zA-Z]{2,63}|[xX][nN]--[a-zA-Z0-9-]{0,58}[a-zA-Z0-9])(:[0-9]{1,5})?$/ |
There was a problem hiding this comment.
Validate the Punycode payload before accepting it
When callers supply an xn-- label that has the right ASCII shape but is not valid Punycode, this branch accepts it as a domain. For example, example.xn--a, example.xn--0, and even the new maximum-length all-a fixture match this regex, although standard URL/IDNA processing rejects each of those A-labels. Consequently createSiweMessage now emits SIWE messages for malformed internationalized hostnames instead of throwing SiweInvalidMessageFieldError; validate the A-label by decoding or canonicalizing it rather than checking only its prefix and characters.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed that example.xn--a and example.xn--0 don't decode: WHATWG new URL() rejects them. I'm not adding a decoder here, for these reasons:
- It isn't new: lower labels already work this way on
main.xn--zz.comis accepted today, andnew URLrejects it as well. - Nothing can be injected: the pattern only lets through LDH characters, so an undecodable A-label can't carry a scheme, userinfo, path, whitespace or newline into the message.
- The spec doesn't require it: EIP-4361 asks for an RFC 3986 authority, which these are.
- Cost: decoding means either a Punycode implementation in
createSiweMessageor switching tonew URL, which would change validation for every domain, not only punycode TLDs.
I'm leaving this thread open for a maintainer to decide.
Generated by Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S1gnnWorzm4HFb366BK3sn
* fix: accept punycode top-level domains in `Siwe.createMessage` Ports wevm/viem#5299. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: preserve EIP-7702 authorization `yParity` above 1 in `Authorization` Ports wevm/viem#5304. EIP-7702 permits any `y_parity` below 2**8 in an authorization tuple. `Authorization.fromRpc`, `Authorization.fromTuple`, and `Authorization.toTuple` now read and encode it as is. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: bound authorization `yParity` to one byte and keep it in `Authorization.toRpc` `Authorization.fromRpc` and `Authorization.fromTuple` reject a `yParity` of 2**8 or more, which EIP-7702 forbids, with the same `Hex.IntegerOutOfRangeError` as `Authorization.toTuple`. `Authorization.toRpc` encodes `yParity` as is instead of through `Signature.toRpc`, which writes 0 or 1. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: keep the port in group 3 of `Siwe.domainRegex` The top-level domain alternation is non-capturing, so the capture groups of the exported regex stay as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: use a line comment for the private `assertYParity` helper `check:tsdoc` requires an `@example` in every JSDoc block, and the helper is not part of the public API. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * docs: name `Authorization.toRpc` in the authorization `yParity` changeset Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: bound authorization `yParity` to one byte in `Authorization.toRpc` `Authorization.toRpc` now rejects a `yParity` of 2**8 or more with the same `Hex.IntegerOutOfRangeError` as the other `Authorization` codecs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: check authorization `yParity` in `Authorization.toTuple` `Authorization.toTuple` encoded a `NaN` `yParity` as the zero parity. It now rejects any `yParity` that is not an integer from 0 to 255, like the other `Authorization` codecs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM --------- Co-authored-by: Claude <[email protected]>
* fix: accept punycode top-level domains in `Siwe.createMessage` Ports wevm/viem#5299. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: preserve EIP-7702 authorization `yParity` above 1 in `Authorization` Ports wevm/viem#5304. EIP-7702 permits any `y_parity` below 2**8 in an authorization tuple. `Authorization.fromRpc`, `Authorization.fromTuple`, and `Authorization.toTuple` now read and encode it as is, and the zod `Authorization` schemas accept an 8-bit `yParity`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: bound authorization `yParity` to one byte in `Authorization.fromRpc` and `Authorization.fromTuple` Both now reject a `yParity` of 2**8 or more, which EIP-7702 forbids, with the same `Hex.IntegerOutOfRangeError` as `Authorization.toTuple`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: keep the port in group 3 of `Siwe.domainRegex` The top-level domain alternation is non-capturing, so the capture groups of the exported regex stay as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: bound authorization `yParity` to one byte in `Authorization.toRpc` `Authorization.toRpc` now rejects a `yParity` of 2**8 or more with the same `Hex.IntegerOutOfRangeError` as the other `Authorization` codecs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM * fix: check authorization `yParity` in `Authorization.toTuple` `Authorization.toTuple` encoded a `NaN` `yParity` as the zero parity. It now rejects any `yParity` that is not an integer from 0 to 255, like the other `Authorization` codecs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VLjvB9RWejr3jdFDh3WjiM --------- Co-authored-by: Claude <[email protected]>
Supersedes #5291 and carries @mortezashojaei's two commits unchanged, so they keep authorship.
createSiweMessagerejected any domain whose top-level label was a punycode A-label (example.xn--p1aifor.рф), even though it is a valid RFC 3986 authority andparseSiweMessagealready parses it. The last label may now be letters (as before) orxn--followed by letters, digits or hyphens, matched case-insensitively, at most 63 characters and not ending in a hyphen.On top of that, the letter-only TLD branch is now capped at 63 characters (
[a-zA-Z]{2,63}), matching the new branch and the DNS label limit. Before,example.followed by 64 letters was accepted.Verified:
\nURI: …injection, trailing dots, and bare single labels.createSiweMessage→parseSiweMessage→validateSiweMessageround-trips for punycode domains (fails onmain).create/parse/validate/utilstests pass, and Biome andtscare clean.The changeset is updated to cover both changes.
Generated by Claude Code