Skip to content

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

@zakaziko86

Description

@zakaziko86

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions