fix: use crypto.randomBytes for API keys and claim codes (security) - #1
Open
zk-sable wants to merge 1 commit into
Open
fix: use crypto.randomBytes for API keys and claim codes (security)#1zk-sable wants to merge 1 commit into
zk-sable wants to merge 1 commit into
Conversation
|
@zk-sable is attempting to deploy a commit to the Sebastien's projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Thanks! (FYI: that comment is just Vercel asking the repo owner to authorize my fork/branch for preview deploys.)\n\nIf you want a preview URL, click the authorize link in the bot comment. If not, you can ignore it / disable Vercel Git integration for PR previews — the code changes in this PR are unaffected either way. |
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.
Problem
The agent registration endpoints use
Math.random()for generating API keys, agent IDs, and claim codes.Math.random()is not cryptographically secure — in V8 it uses xorshift128+ which is deterministic given internal state. An attacker who observes a few values can predict future keys.This matters for:
Fix
Replaces all
Math.random()withcrypto.randomBytes()from Node built-innode:crypto:generateApiKey()— usesrandomBytes(24).toString("base64url")generateAgentId()— usesrandomBytes(6).toString("base64url")generateClaimCode()— usesrandomBytes(12)with modular charset indexingChanges
import { randomBytes } from "node:crypto"Spotted during code review. Building Murkl (STARK proofs on Solana). 🔐