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는 전체 코드베이스에서 취약한 패턴을 찾아냅니다.