Medium severityPythonCryptographyMEDIUM confidence
Insecure Random Token
The random module is not cryptographically secure and must not be used to generate tokens, passwords, salts, or session identifiers (CWE-330/CWE-338).
Standards mapping
Vulnerable vs. safe
Flagged by this check
return random.choice("abcdef0123456789")Passes - the safe pattern
return secrets.choice("abcdef0123456789")Why it matters & how to fix it
The random module is not cryptographically secure and must not be used to generate tokens, passwords, salts, or session identifiers (CWE-330/CWE-338). Use the secrets module (secrets.token_hex, secrets.token_urlsafe, secrets.choice) instead.
References
Rule ID integsec-python-insecure-random-token - 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 - CryptographyWeak Cipher DES ECB
- Python - CryptographyWeak Hash MD5 SHA1
- Java - CryptographyHardcoded Crypto Key IV