# 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:** JavaScript - Prevalence: Wysoka Często wykorzystywana - Impact: Wysoki 3 reguł o wysokim poziomie - Prevention: Udokumentowane 3 przykładów poprawek **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 Strategie zapobiegania dla Weak Password Recovery oparte na 1 regułach detekcji Shoulder. ### JavaScript Use crypto.randomBytes() instead of Math.random() for security tokens ## Warning Signs - [HIGH] predictable random number generation (Math ## Consequences - Uzyskanie uprawnień - Obejście mechanizmu ochrony ## Mitigations - Do linków resetowania hasła używaj mocnych, losowych tokenów - Wdroż wygasanie tokenów (np. po 1 godzinie) - Wymagaj dodatkowej weryfikacji, np. e-mailem lub SMS-em - Nigdy nie umieszczaj tokenu resetowania w URL-ach, które mogą być logowane ## Detection - Total rules: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Javascript (1 rules) - **Weak Password Reset Token** [HIGH]: Detects predictable random number generation (Math.random) used for password reset tokens. - Remediation: Use cryptographically secure random: ```javascript const crypto = require('crypto'); const resetToken = crypto.randomBytes(32).toString('hex'); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-640/weak-password-reset-token ### Typescript (1 rules) - **Weak Password Reset Token** [HIGH]: Detects predictable random number generation (Math.random) used for password reset tokens. - Remediation: Use cryptographically secure random: ```javascript const crypto = require('crypto'); const resetToken = crypto.randomBytes(32).toString('hex'); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-640/weak-password-reset-token