Repository navigation
fix(0.x): port Siwe authority validation (#434, #695) and ip literal domains (#705) - #709
Merged
Merged
Conversation
* 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)
`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)
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review Summary: ✅ CompletedThis 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. |
Merged
This branch was successfully deployed
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.
Ports main's
Siweauthority validation to 0.x and adds IP-literaldomainsupport on top. This finishes the 0.x side of #705 and ports #695, both of which #706 had to leave out.isUri, URIs with an empty path): 0.x still had thepath && …guard, soisUrirejected bare origins such ashttps://login.xyz(the EIP-4361 example). This makescreateMessagethrow for them as aurior resource. The port drops that guard and addsisAuthority, which validates the authority of pathless URIs. The regexes are hoisted the same way as main perf: hoist per-call regular expressions in hot validation paths #569.Siwe.isUriURIs that have a path #695 (isUri, URIs with a path): the authority is now validated even when the URI has a path. For example,https://example.com:bad/loginanduri://[::300.0.0.0]/p/pathare rejected.domaininSiwemessages #696):createMessageandparseMessageaccept a bracketed IPv6 or IPvFuturedomainwith an optional port, such as[::1]:3000. Brackets exclude@and[, so a userinfo authority such as[evil.com@[::1]can't pass as a literal.Not included: main's unrelated
Siwechanges, which are RFC 3339 date-time parsing (#398) and the stricterchainIdcheck.0.x adaptation: 0.x's vitest doesn't allow inline snapshots inside
test.each, so those two assertions use.toBe(false).Local results:
Siwe.test.tspasses, 129/129.Siwe.ts, the new tests fail at each step: 9 for fix(siwe): isUri rejects authority-only URIs with an empty path #434, 5 for fix: validate the authority ofSiwe.isUriURIs that have a path #695, 5 for the IP-literal part. Without the@[exclusion, the[evil.com@[::1]and[a@[::1]cases fail.tsc --noEmitand biome pass.