From 6b38696eece0325ac95ed7cf8bf4d5cf40147f3b Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Thu, 27 Nov 2025 20:35:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(security):=20=E4=BF=AE=E5=A4=8D=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E9=AA=8C=E8=AF=81=E7=BB=95=E8=BF=87=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前的迁移脚本会在每次服务启动时将所有 is_verified=0 的用户 自动设为已验证,导致攻击者可以用假邮箱注册后等待服务重启绕过验证。 修复方案:仅将 is_verified IS NULL 且 verification_token IS NULL 的 用户设为已验证(这些是邮箱验证功能上线前注册的老用户)。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- backend/database.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/database.js b/backend/database.js index 49b97d8..4bf88dc 100644 --- a/backend/database.js +++ b/backend/database.js @@ -123,8 +123,10 @@ function initDatabase() { 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) { console.error('数据库迁移(邮箱验证)失败:', error); }