Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V5904. OWASP. A cryptographically...
menu mobile close menu
Analyzing projects
Additional information
toggle menu Contents

V5904. OWASP. A cryptographically weak pseudo-random number generator is used in security-sensitive code. Consider using a stronger alternative.

Nov 26 2026

The analyzer has detected the use of a cryptographically weak pseudorandom number generator (PRNG) in the security-sensitive code.

Vulnerabilities related to the use of predictable PRNG can be classified under the following categories in the OWASP Top 10 Application Security Risks 2025:

The example:

import (
  ....
  "math/rand"
  ....
)

func ResetPassword(...., r *http.Request) {
  ....
  token := fmt.Sprintf("%d", rand.Int())
  userEmail := r.URL.Query().Get("email")

  _, err := DB.Exec("INSERT INTO password_resets " +
                    "(email, token) VALUES (?, ?)",
                    userEmail, 
                    token)  
  ....
}

In the example, the function from the math/rand package is used to generate the password reset token. The algorithms in this package are deterministic and predictable, which allows an attacker to generate or guess the token.

To generate secret keys, session tokens, passwords, and other sensitive data, it would be recommended to use a cryptographically secure random number generator from the crypto/rand package:

import (
  ....
  secrand "crypto/rand"
  "math/big"
  ....
)
....
func ResetPassword(....) {
  ....
  randVal, _ := secrand.Int(secrand.Reader, ....)
  token := fmt.Sprintf("%d", randVal.Int64())
  ....
}

For more security recommendations, see the OWASP Cheat Sheet Series:

This diagnostic rule is classified as: