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
Description
The Wagmi integration setup example uses
Math.random()to generatea SIWE (Sign-In With Ethereum) nonce:
Math.random()is not cryptographically secure and should never beused for SIWE nonces. A predictable nonce can be exploited to perform
replay attacks.
Impact
authenticate-usersguide which already usescrypto.randomUUID()Suggested Fix
Replace with
crypto.randomUUID():✅ Cryptographically secure (Web Crypto API)
✅ Available in all modern browsers and Node.js 14.17+
✅ Consistent with existing
authenticate-usersguideReferences