# Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG) (CWE-338) The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong. **Stack:** Go - Prevalence: 高 頻繁に悪用される - Impact: ハイ 2 件の重大度ハイのルール - Prevention: 文書化済み 4 件の修正例 **OWASP:** Cryptographic Failures (A02:2021-Cryptographic Failures) - #2 ## Description When a non-cryptographic PRNG is used in a security context (such as generating session tokens or cryptographic keys), an attacker may be able to predict its output and compromise the security mechanism. ## Prevention 1 件の Shoulder 検出ルールに基づく Weak PRNG の予防策。 ### Go Use crypto/rand instead of math/rand for security-sensitive values ## Warning Signs - [HIGH] math/rand used for security-sensitive random values ## Consequences - 保護メカニズムの回避 - 権限の取得 ## Mitigations - 暗号学的に安全な乱数生成器 (CSPRNG) を使用する - JavaScript では crypto.getRandomValues() または crypto.randomUUID() を使用する - Python では random ではなく secrets モジュールを使用する ## Detection - Total rules: 4 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **Weak Random Number Generation for Security** [HIGH]: Uses math/rand for security tokens, keys, or session IDs instead of crypto/rand. - Remediation: Use crypto/rand for all security-sensitive random values. ```go import "crypto/rand" token := make([]byte, 32) if _, err := rand.Read(token); err != nil { return err } ``` Learn more: https://shoulder.dev/learn/go/cwe-338/weak-random