Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Annotate gosec rand generator warning for false positive
Browse files Browse the repository at this point in the history
gosec tool flags math/rand, but using math/rand is okay as long
as the random number does not have to be cyrptographically secure.
In this case, the random numbers are not used as a secret for crytpo
purposes so using math/rand is okay.
  • Loading branch information
shashankram committed Oct 15, 2020
1 parent c9393ef commit f925052
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion demo/cmd/bookstore/bookstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func sellBook(w http.ResponseWriter, r *http.Request) {
// Slow down the responses artificially.
maxNoiseMilliseconds := 750
minNoiseMilliseconds := 150
intNoise := rand.Intn(maxNoiseMilliseconds-minNoiseMilliseconds) + minNoiseMilliseconds
intNoise := rand.Intn(maxNoiseMilliseconds-minNoiseMilliseconds) + minNoiseMilliseconds // #nosec G404
pretendToBeBusy := time.Duration(intNoise) * time.Millisecond
log.Info().Msgf("Sleeping %+v", pretendToBeBusy)
time.Sleep(pretendToBeBusy)
Expand Down
2 changes: 1 addition & 1 deletion demo/cmd/common/books.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func GetBooks(participantName string, meshExpectedResponseCode int, booksCount *

// Create random URLs to test egress
if fetchURL == httpPrefix || fetchURL == httpsPrefix {
index := rand.Intn(len(egressURLs))
index := rand.Intn(len(egressURLs)) // #nosec G404
fetchURL = fmt.Sprintf("%s%s", url, egressURLs[index])
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/certificate/rotor/rotor.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func ShouldRotate(cert certificate.Certificater) bool {
// We want to renew earlier. How much earlier is defined in renewBeforeCertExpires.
// We add a few seconds noise to the early renew period so that certificates that may have been
// created at the same time are not renewed at the exact same time.
intNoise := rand.Intn(maxNoiseSeconds-minNoiseSeconds) + minNoiseSeconds

intNoise := rand.Intn(maxNoiseSeconds-minNoiseSeconds) + minNoiseSeconds /* #nosec G404 */
secondsNoise := time.Duration(intNoise) * time.Second
return time.Until(cert.GetExpiration()) <= (renewBeforeCertExpires + secondsNoise)
}
2 changes: 2 additions & 0 deletions pkg/debugger/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func (ds debugServer) getEnvoyConfig(pod *v1.Pod, cn certificate.CommonName, url

minPort := 16000
maxPort := 18000

// #nosec G404
portFwdRequest := portForward{
Pod: pod,
LocalPort: rand.Intn(maxPort-minPort) + minPort,
Expand Down

0 comments on commit f925052

Please sign in to comment.