fix: replace insecure Math.random() nonces with crypto APIs#1517
Open
clicheman wants to merge 1 commit into
Open
fix: replace insecure Math.random() nonces with crypto APIs#1517clicheman wants to merge 1 commit into
clicheman wants to merge 1 commit into
Conversation
Replace all Math.random() usages for nonce generation with cryptographically secure alternatives: - wagmi/setup.mdx: use crypto.randomUUID() - sign-in-with-base-button.mdx: use crypto.randomUUID() - sign-and-verify-typed-data.mdx: use crypto.randomInt() with import crypto Math.random() is not cryptographically secure and should not be used for SIWE nonces or security-sensitive values. Closes base#1477
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.
What changed? Why?
Replaced all
Math.random()usages for nonce generation with cryptographically secure alternatives across three documentation files.Math.random()is not cryptographically secure and produces predictable output. Using it for SIWE nonces or security-sensitive values exposes developers who copy these examples to replay attacks.Changes
wagmi/setup.mdxMath.random().toString(36).substring(2, 15)crypto.randomUUID()sign-in-with-base-button.mdxMath.random().toString(36).substring(7)crypto.randomUUID()sign-and-verify-typed-data.mdxMath.floor(Math.random() * 1000000)crypto.randomInt(1_000_000)+ addedimport cryptoNotes to reviewers
crypto.randomUUID()is available in all modern browsers and Node.js 19+ (Web Crypto API)crypto.randomInt()is used in the server-side example (Node.jscryptomodule) since the nonce there is a numeric valueauthenticate-usersguide which already usescrypto.randomUUID()Closes #1477