fix(security): replace math/rand with crypto/rand in 3 daemon files (PILOT-417)#283
Merged
Merged
Conversation
…PILOT-417) Replace insecure math/rand usage with crypto/rand equivalents across three files in pkg/daemon/: - pkg/daemon/managed.go: rand.Shuffle -> cryptoShuffle (Fisher-Yates with rejection-sampled crypto/rand indices) - pkg/daemon/routing/discovery.go: rand.Int63n -> crypto/rand.Int for beacon refresh jitter - pkg/daemon/zz_diag_hook_diaglog.go: rand.Intn(1000) -> crypto/rand.Int for diagnostic frame sampling The cryptoShuffle helper uses rejection sampling to avoid modulo bias and falls back gracefully on crypto read failures. Closes PILOT-417
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
Security audit finding PILOT-37 Category A: three files in
pkg/daemon/usemath/randinstead ofcrypto/randfor operations that affect security-sensitive behavior (peer candidate selection, beacon jitter, diagnostic frame sampling).Changes
pkg/daemon/managed.gomath/rand.ShufflecryptoShuffle— Fisher-Yates with rejection-sampledcrypto/randpkg/daemon/routing/discovery.gomath/rand.Int63ncrypto/rand.Intwithbig.Intpkg/daemon/zz_diag_hook_diaglog.gomath/rand.Intn(1000)crypto/rand.Intwithbig.IntThe
cryptoShufflehelper (inmanaged.go) uses rejection sampling to avoid modulo bias and falls back gracefully on crypto read errors.Verification
go build ./...— cleango vet ./...— cleango test ./pkg/daemon/...— all packages pass (including routing)Risk
Minimal. These are mechanical replacements from deterministic PRNG to CSPRNG. No behavioral change in the algorithm logic — same shuffle, same jitter range, same drop-rate check, just cryptographically secure.
Closes PILOT-417