Weak Password Recovery Mechanism for Forgotten Password
The product contains a mechanism for users to recover or change their passwords without knowing the original password, but the mechanism is weak.
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.
この脆弱性の修正方法
3 件の Shoulder 検出ルールに基づく Weak Password Recovery の予防策。
Use crypto/rand with 32+ bytes of entropy for password reset tokens
- func generateResetToken() string { - return fmt.Sprintf("%d", time.Now().Unix()) + import ( + "crypto/rand" + "encoding/hex" + ) + + func generateResetToken() (string, error) { + b := make([]byte, 32) + if _, err := rand.Read(b); err != nil { + return "", err + } + return hex.EncodeToString(b), nil }
Use crypto.randomBytes() instead of Math.random() for security tokens
- user.resetToken = Math.random().toString(36); + const crypto = require('crypto'); + user.resetToken = crypto.randomBytes(32).toString('hex'); await user.save();
Use the secrets module for cryptographically secure token generation
- import random - - def create_reset_token(): - chars = 'abcdef0123456789' - reset_token = ''.join(random.choice(chars) for _ in range(32)) - return reset_token + import secrets + + def create_reset_token(): + return secrets.token_urlsafe(32)
コードの脆弱性を見つける
Shoulderを使用してコードのWeak Password Recovery Mechanism for Forgotten Passwordパターンをスキャンしましょう。 3 ルール.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=640 # Or scan entire project npx @shoulderdev/cli trust .
検出ルール (3)
コードレビューで注目すべき点
これらのパターンはWeak Password Recovery Mechanism for Forgotten Passwordの潜在的な脆弱性を示しています。コードレビューとセキュリティ監査中に探してください。
コードベースをスキャン: Weak Password Recovery Mechanism for Forgotten Password
Shoulder CLI はコードベース全体から脆弱なパターンを見つけます。