fix(批次D): 口令哈希升级 + 假签名放行 + 找回密码防枚举 + 告警按收件人
- 用户口令:hash_password 改 pbkdf2(加盐、260k 迭代);新增 verify_password 兼容旧的无盐 sha256 且恒定时间比较;登录成功后自动升级旧哈希(用户无感) - _verify_upstream_token:没有 access_token 时直接放行(假签名必被上游 102001 拒绝,原先把 102001 当「凭据失效」,导致只填 token_id 的合法用户注册被 400 拦、 /verify_token 永远 invalid) - 找回密码防枚举:未注册邮箱也占 60 秒冷却(email_verify.record_cooldown, 不发信),否则「第二次请求是否 429」就成了判断邮箱是否注册的预言机 - 凭据告警:_send_alert 改为按收件人统计,返回成功数;只要有一人收到就落库, 不再因为某个收件人失败导致「每 15 分钟给全员重发一遍」 测试:167 pytest(新增口令哈希 3 条)+ 32 node 全绿
This commit is contained in:
@@ -53,6 +53,23 @@ def _cleanup_locked(now: float):
|
||||
_codes.pop(email, None)
|
||||
|
||||
|
||||
def record_cooldown(email: str) -> None:
|
||||
"""只登记「刚发过」,不真正发信。
|
||||
|
||||
用于找回密码的防枚举:未注册邮箱也要占住 60 秒冷却,否则
|
||||
「第二次请求是否 429」就成了判断邮箱有没有注册的预言机。
|
||||
"""
|
||||
email = (email or "").strip().lower()
|
||||
if not email:
|
||||
return
|
||||
now = _now()
|
||||
with _lock:
|
||||
entry = _codes.get(email) or {"hash": "", "expires": now, "attempts": 0}
|
||||
entry["sent_at"] = now
|
||||
entry["purpose"] = "reset"
|
||||
_codes[email] = entry
|
||||
|
||||
|
||||
def send_code(email: str, purpose: str = "register") -> tuple:
|
||||
"""发送验证码到邮箱。返回 (ok, message)。受 60s 邮箱冷却与每小时 IP 上限约束。"""
|
||||
email = (email or "").strip().lower()
|
||||
|
||||
Reference in New Issue
Block a user