Skip to content

fix(siwe): reject a line break in createSiweMessage requestId - #5559

Closed
pucedoteth wants to merge 1 commit into
wevm:mainfrom
pucedoteth:fix/siwe-request-id-newline
Closed

pucedoteth wants to merge 1 commit into
wevm:mainfrom
pucedoteth:fix/siwe-request-id-newline

Conversation

@pucedoteth

Copy link
Copy Markdown
Contributor

createSiweMessage validates every field except requestId. A line break in it starts a new field, so a request ID can append lines to the message the user signs:

createSiweMessage({ ...message, requestId: 'foo\nResources:\n- https://example.com/admin' })

produces

...
Issued At: 2023-02-01T00:00:00.000Z
Request ID: foo
Resources:
- https://example.com/admin

and parseSiweMessage reads it back as { requestId: 'foo', resources: ['https://example.com/admin'] }. No resources were passed, so the injected one also skips the isUri check that resources entries get.

EIP-4361 defines request-id as *pchar, which excludes line breaks. This rejects a \n in requestId with SiweInvalidMessageFieldError, the same way statement is handled. It affects apps that put caller-controlled text in requestId; an app-generated ID such as a UUID is unaffected.

  • Added behavior: invalid requestId. It fails without this change and passes with it.
  • All src/utils/siwe tests pass (91), and biome and tsc are clean.
  • Added a patch changeset.

`createSiweMessage` validated every field except `requestId`. A line
break in it started a new field, so a request ID could append lines
such as a `Resources` section to the message the user signs, and
`parseSiweMessage` read them back as resources. Reject it like a line
break in `statement`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01L75E8Ap183JW1mDfv8arqR
@vercel

vercel Bot commented Nov 18, 2026

Copy link
Copy Markdown

@pucedoteth is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e8c7d42

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

@erkancamli

Copy link
Copy Markdown
Contributor

The \n case is closed by this, but parseSiweMessage matches the request ID with .*, and . in a JS regex also stops at \r, U+2028 and U+2029. With any of those in requestId, createSiweMessage still succeeds and the parsed message loses fields. On 2.58.0, with resources: ['https://example.com/a']:

requestId parsed requestId parsed resources validateSiweMessage
"foo" "foo" ["https://example.com/a"] true
"foo\rbar" "foo" undefined true
"foo\u2028bar" "foo" undefined true
"foo\u2029bar" "foo" undefined true

So the text the user signs and what a verifier reads back still differ. ox's Siwe.createMessage already rejects /[\n\r]/ in requestId. Checking /[\n\r\u2028\u2029]/ here would cover all of them. statement has the same gap: with "hel\rlo" or "hel\u2028lo" it parses back as undefined.

jxom commented Nov 18, 2026

Copy link
Copy Markdown
Member

Thanks @pucedoteth! We carried this forward in #5580 with your commit intact, adding a check for a lone \r and a one-sentence changeset.

@jxom jxom closed this Nov 18, 2026
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.

3 participants