[Bug] Math.random() used for SIWE nonce in Wagmi setup example — not cryptographically secure

Open Beginner friendly
#1,477 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript

Research direction

Find the Wagmi integration setup example containing the two Math.random() calls and compare it with the authenticate-users guide referenced in the issue. Replace the nonce generation with crypto.randomUUID(), then verify the example uses the secure approach consistently with that guide.

Written by the indexing model from the issue text.

Description

Description

The Wagmi integration setup example uses Math.random() to generate
a SIWE (Sign-In With Ethereum) nonce:

const clientNonce =
  Math.random().toString(36).substring(2, 15) +
  Math.random().toString(36).substring(2, 15);

Math.random() is not cryptographically secure and should never be
used for SIWE nonces. A predictable nonce can be exploited to perform
replay attacks.

Impact

  • Developers copying this example will implement insecure SIWE flows
  • Predictable nonces can be exploited for replay attacks
  • Contradicts the authenticate-users guide which already uses
    crypto.randomUUID()

Suggested Fix

Replace with crypto.randomUUID():

const clientNonce = crypto.randomUUID();

✅ Cryptographically secure (Web Crypto API)
✅ Available in all modern browsers and Node.js 14.17+
✅ Consistent with existing authenticate-users guide

References

Dominant language
JavaScript
Stars
337
Forks
798
Avg merge
7h 24m
Merged PRs (30d)
51

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from base/docs

All issues in base/docs

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.