Medium severityC#CryptographyMEDIUM confidence
Insecure Random
System.Random is a non-cryptographic PRNG; using it to generate security values (tokens, OTPs, nonces, salts, keys, session identifiers) yields predictable output (CWE-338).
Standards mapping
- OWASP Top 10
- A02:2021 - Cryptographic Failures
- OWASP ASVS
- V6.3.1 (L2)
Vulnerable vs. safe
Flagged by this check
var otp = rng.Next(100000, 999999);Passes - the safe pattern
var token = RandomNumberGenerator.GetInt32(100000, 999999);Why it matters & how to fix it
System.Random is a non-cryptographic PRNG; using it to generate security values (tokens, OTPs, nonces, salts, keys, session identifiers) yields predictable output (CWE-338). Use System.Security.Cryptography. RandomNumberGenerator (e.g. RandomNumberGenerator.GetBytes / GetInt32) for any security-sensitive randomness.
References
Rule ID integsec.csharp.crypto.insecure-random - engine: Opengrep - license: MIT - Copyright (c) IntegSec Inc.
TurboPentest runs this check automatically
Connect a GitHub repo and this check runs on every white-box pentest - AI-validated and reported with proof, from $99 per target.
Start a pentestRelated checks
- JavaScript / TypeScript - CryptographyInsecure Randomness For Secrets
- JavaScript / TypeScript - CryptographyWeak Cipher Algorithm
- JavaScript / TypeScript - CryptographyWeak Hash Algorithm
- Python - CryptographyInsecure Random Token
- Python - CryptographyWeak Cipher DES ECB
- Python - CryptographyWeak Hash MD5 SHA1