Skip to content

fix(siwe): reject a short nonce and a version other than 1 in parseSiweMessage - #5433

Closed
shlee1223 wants to merge 1 commit into
wevm:mainfrom
shlee1223:fix-siwe-parse-nonce-version
Closed

shlee1223 wants to merge 1 commit into
wevm:mainfrom
shlee1223:fix-siwe-parse-nonce-version

Conversation

@shlee1223

Copy link
Copy Markdown
Contributor

Summary

parseSiweMessage accepts two values that the EIP-4361 ABNF does not allow:

  • nonce = 8*( ALPHA / DIGIT ), but the suffix regex uses [a-zA-Z0-9]+, so Nonce: foobar parses.
  • version = "1", but the suffix regex uses .+, so Version: 2 parses.

createSiweMessage already enforces both (nonceRegex = /^[a-zA-Z0-9]{8,}$/ and version !== '1'), so the parser accepted messages the creator refuses to produce.

Fix

In suffixRegex, (?<nonce>[a-zA-Z0-9]+) becomes (?<nonce>[a-zA-Z0-9]{8,}) and (?<version>.+) becomes (?<version>1).

input before after
Nonce: foobarbaz, Version: 1 parsed parsed
Nonce: foobar nonce: "foobar" suffix does not match
Version: 2 version: "2" suffix does not match

When the suffix does not match, its fields come back undefined, which is what parseSiweMessage already does for any other malformed suffix.

Tests

Two tests in parseSiweMessage.test.ts, one for a 6-character nonce and one for Version: 2. Both fail without the change. The src/utils/siwe tests pass.

@vercel

vercel Bot commented Nov 6, 2026

Copy link
Copy Markdown

@shlee1223 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 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8ecfb82

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

jxom commented Nov 8, 2026

Copy link
Copy Markdown
Member

Thanks for finding this! Closing in favor of #5440. Tightening the parser regex drops the whole suffix (including expirationTime and notBefore), which made validateSiweMessage accept expired messages, so #5440 rejects the short nonce and non-1 version in validateSiweMessage instead. You're credited as co-author.

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

2 participants