security: replace Math.random() with crypto.randomUUID() for SIWE nonces#1560
Open
cryptoasuran wants to merge 2 commits into
Open
security: replace Math.random() with crypto.randomUUID() for SIWE nonces#1560cryptoasuran wants to merge 2 commits into
cryptoasuran wants to merge 2 commits into
Conversation
Fixes cross-domain replay attack vulnerability in authenticate-users guide. ## Problem Backend examples only verified cryptographic signature without validating the SIWE message domain. This allows valid signatures from evil.com to be replayed against yourapp.com's /auth/verify endpoint. ## Changes - Replace `verifyMessage` with `verifySiweMessage` in both examples - Add explicit domain parameter validation - Add comment explaining security rationale - Import `verifySiweMessage` from 'viem/siwe' ## Impact Prevents cross-domain replay attacks as required by EIP-4361 spec. Developers following this guide will now ship secure authentication. Fixes base#1502 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Fixes cryptographic vulnerability in SIWE nonce generation across 4 files.
## Problem
Math.random() is not cryptographically secure and produces predictable
nonces that can be exploited for replay attacks in SIWE authentication.
## Changes
Replaced all Math.random() nonce generation with crypto.randomUUID():
1. wagmi/setup.mdx (line 338-340)
- Before: Math.random().toString(36).substring(2, 15) + ...
- After: crypto.randomUUID().replace(/-/g, '')
2. sign-in-with-base-button.mdx (line 328)
- Before: Math.random().toString(36).substring(7)
- After: crypto.randomUUID().replace(/-/g, '')
3. sign-and-verify-typed-data.mdx (line 193)
- Before: Math.floor(Math.random() * 1000000)
- After: crypto.randomBytes(16).toString('hex')
## Security Impact
- Prevents predictable nonce attacks
- Complies with EIP-4361 security requirements
- Uses Web Crypto API (available in all modern browsers + Node.js 14.17+)
## Consistency
Aligns with authenticate-users guide which already uses crypto.randomUUID().
Fixes base#1477
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
🟡 Heimdall Review Status
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes cryptographic vulnerability in SIWE nonce generation across 4 documentation examples.
Problem (Issue #1477)
Multiple examples use
Math.random()to generate SIWE nonces:Math.random()is not cryptographically secure. It produces predictable values that can be exploited for replay attacks in SIWE authentication flows.Security Impact
Solution
Replace with
crypto.randomUUID()(Web Crypto API):Files Fixed
docs/base-account/framework-integrations/wagmi/setup.mdx(line 338-340)docs/base-account/reference/ui-elements/sign-in-with-base-button.mdx(line 328)docs/base-account/guides/sign-and-verify-typed-data.mdx(line 193)Consistency
This aligns with the
authenticate-usersguide which already usescrypto.randomUUID()correctly.Browser Support
crypto.randomUUID(): All modern browsers + Node.js 14.17+crypto.randomBytes(): Node.js (used in server example)Both are standard Web Crypto API methods.
References
Fixes #1477