Medium severityPHPCryptographyMEDIUM confidence
Insecure Random Token
rand()/mt_rand()/uniqid()/lcg_value() are 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 mt_rand();Passes - the safe pattern
return bin2hex(random_bytes(32));Why it matters & how to fix it
rand()/mt_rand()/uniqid()/lcg_value() are not cryptographically secure and must not be used to generate tokens, passwords, salts, or session identifiers (CWE-330/CWE-338). Use random_bytes() or random_int() (or bin2hex(random_bytes(32)) for tokens).
References
Rule ID integsec-php-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 - CryptographyInsecure Random Token
- Python - CryptographyWeak Cipher DES ECB
- Python - CryptographyWeak Hash MD5 SHA1