fix(security): 修复邮箱验证绕过漏洞

之前的迁移脚本会在每次服务启动时将所有 is_verified=0 的用户
自动设为已验证,导致攻击者可以用假邮箱注册后等待服务重启绕过验证。

修复方案:仅将 is_verified IS NULL 且 verification_token IS NULL 的
用户设为已验证(这些是邮箱验证功能上线前注册的老用户)。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-27 20:35:01 +08:00
parent 4f29bbe631
commit 6b38696eec

View File

@@ -123,8 +123,10 @@ function initDatabase() {
db.exec(`ALTER TABLE users ADD COLUMN verification_expires_at DATETIME`); db.exec(`ALTER TABLE users ADD COLUMN verification_expires_at DATETIME`);
} }
// 将现有用户标记为已验证(避免老账号被拦截登录) // 注意:不再自动将未验证用户设为已验证
db.exec(`UPDATE users SET is_verified = 1 WHERE is_verified IS NULL OR is_verified = 0`); // 仅修复 is_verified NULL 的旧数据(添加字段前创建的用户)
// 这些用户没有 verification_token说明是在邮箱验证功能上线前注册的
db.exec(`UPDATE users SET is_verified = 1 WHERE is_verified IS NULL AND verification_token IS NULL`);
} catch (error) { } catch (error) {
console.error('数据库迁移(邮箱验证)失败:', error); console.error('数据库迁移(邮箱验证)失败:', error);
} }