Skip to content

fix(siwe): reject line breaks in SIWE statements - #5609

Merged
jxom merged 6 commits into
mainfrom
fix/siwe-statement-line-breaks
Nov 19, 2026
Merged

jxom merged 6 commits into
mainfrom
fix/siwe-statement-line-breaks

Conversation

@jxom

@jxom jxom commented Nov 19, 2026

Copy link
Copy Markdown
Member

Supersedes #5608 by @gomesalexandre, keeping their commits.

parseSiweMessage reads 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.

  • parseSiweMessage now returns {} when the text between the blank line after the address and the suffix contains a line break, after removing the blank line before URI:. fix: reject line breaks in SIWE statements #5608 checked only up to the next \n\nURI: , so a statement such as foo\u2028URI: https://evil.example followed by a single LF before the real suffix still parsed. That case is now rejected.
  • createSiweMessage rejected only LF in the statement. It now also rejects CR, U+2028, and U+2029, so it cannot build a message that parseSiweMessage rejects.

Messages with no statement (two or three LFs after the address), a one-line statement, and createSiweMessage output 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).

gomesalexandre and others added 4 commits November 19, 2026 19:32
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]>
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]>
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Error Error Nov 19, 2026 7:17pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a3ec9b8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T19:14:48.395814Z a3ec9b8 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread src/utils/siwe/parseSiweMessage.ts Fixed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ampagent and others added 2 commits November 19, 2026 19:12
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]>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Published [email protected] under the pr-5609 dist-tag, which follows this pull request until it closes.

pnpm add viem@pr-5609
pnpm add [email protected]

@jxom
jxom merged commit c1f59af into main Nov 19, 2026
39 of 40 checks passed
@jxom
jxom deleted the fix/siwe-statement-line-breaks branch November 19, 2026 19:48
@github-actions github-actions Bot mentioned this pull request Nov 19, 2026

This branch had an error being deployed

1 failed deployment
Preview — a3ec9b8a Deployed Nov 19, 2026 by vercel[bot]
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.

4 participants