Repository navigation
fix(siwe): reject line breaks in SIWE statements - #5609
Conversation
Reject CR, LF, U+2028, and U+2029 in the statement so parseSiweMessage cannot return suffix fields when a line terminator splits the statement. Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Cursor Grok 4.7 <[email protected]>
The statement check now reads from the blank line after the address to where the suffix regex matched, instead of up to the next blank line before `URI: `. A line break in the statement followed by one LF before the suffix no longer parses, and a two-paragraph statement is still rejected. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f523-a120-74c6-b432-706eb7c8f2b5 Co-authored-by: jxom <[email protected]>
createSiweMessage rejected only LF, so it could build a statement that parseSiweMessage now rejects. Also rewrote the changeset in the past tense. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f523-a120-74c6-b432-706eb7c8f2b5 Co-authored-by: jxom <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: a3ec9b8 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 |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f012f58f6
ℹ️ 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".
| import { expect, test, vi } from 'vitest' | ||
|
|
||
| import { mainnet } from '../../chains/definitions/mainnet.js' | ||
| import { SiweInvalidMessageFieldError } from '../../errors/siwe.js' |
There was a problem hiding this comment.
Import the public SIWE error through the package entrypoint
The new import bypasses the public package entrypoint, contrary to the explicit testing convention in AGENTS.md. SiweInvalidMessageFieldError is exported from src/siwe/index.ts, so import it from viem/siwe instead of the implementation file to keep this public-surface test aligned with the required convention.
AGENTS.md reference: AGENTS.md:L188-L193
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Importing from viem/siwe while createSiweMessage comes from a relative path loaded a second copy of the class, so toThrow(SiweInvalidMessageFieldError) failed its instanceof check. a3ec9b8 drops the import and checks the error message instead, so the test no longer needs the class.
The unanchored suffix regex retried `URI: ` at every position, so a long line of repeated `URI: a` took quadratic time (about 9 s for 40,000 repetitions). Matching only at line starts makes it linear. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f523-a120-74c6-b432-706eb7c8f2b5 Co-authored-by: jxom <[email protected]>
|
Published pnpm add viem@pr-5609
pnpm add [email protected] |
Supersedes #5608 by @gomesalexandre, keeping their commits.
parseSiweMessagereads the statement with an optional regex group, so a statement with CR, LF, U+2028, or U+2029 skipped the group. The parser then dropped the statement and still returned the suffix fields, so the parsed message omitted text the user signed. EIP-4361 limits the statement to one line.parseSiweMessagenow returns{}when the text between the blank line after the address and the suffix contains a line break, after removing the blank line beforeURI:. fix: reject line breaks in SIWE statements #5608 checked only up to the next\n\nURI:, so a statement such asfoo\u2028URI: https://evil.examplefollowed by a single LF before the real suffix still parsed. That case is now rejected.createSiweMessagerejected only LF in the statement. It now also rejects CR, U+2028, and U+2029, so it cannot build a message thatparseSiweMessagerejects.Messages with no statement (two or three LFs after the address), a one-line statement, and
createSiweMessageoutput parse as before. CRLF messages already did not parse on main and are unchanged.Not covered here: the suffix regex is unanchored, so a statement followed by a blank line and a complete second suffix block still parses the first block. The nonce bypass at
parseSiweMessage.ts:80(a nonce with a character outside[a-zA-Z0-9]drops all suffix fields) is also separate.CJS size: 120.99 kB on main, 121.06 kB here (limit 121.5 kB).