# Weak Password Recovery Mechanism for Forgotten Password (CWE-640) The product contains a mechanism for users to recover or change their passwords without knowing the original password, but the mechanism is weak. **Stack:** Go - Prevalence: High Frequently exploited - Impact: High 3 high-severity rules - Prevention: Documented 3 fix examples **OWASP:** Identification and Authentication Failures (A07:2021-Identification and Authentication Failures) - #7 ## Description Weak password recovery mechanisms can be exploited to take over user accounts. Common issues include predictable reset tokens, security questions with easily guessable answers, or lack of verification. ## Prevention Prevention strategies for Weak Password Recovery based on 1 Shoulder detection rules. ### Go Use crypto/rand with 32+ bytes of entropy for password reset tokens ## Consequences - Gain Privileges - Bypass Protection Mechanism ## Mitigations - Use strong, random tokens for password reset links - Implement token expiration (e.g., 1 hour) - Require additional verification like email or SMS - Never expose the reset token in URLs that could be logged ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **Weak Password Reset Token** [HIGH]: Password reset token uses predictable values like timestamps or math/rand. - Remediation: Generate reset tokens using crypto/rand with at least 32 bytes of entropy. ```go import "crypto/rand" func generateResetToken() (string, error) { b := make([]byte, 32) if _, err := rand.Read(b); err != nil { return "", err } return hex.EncodeToString(b), nil } ``` Learn more: https://shoulder.dev/learn/go/cwe-640/weak-password-reset-token