Skip to content

🐛 Bugfix: Keep current session after password change; stop false-success account deletion - #4549

Merged
jeffwu-1999 merged 5 commits into
developfrom
fix/password-change-session-continuity
Dec 3, 2026
Merged

jeffwu-1999 merged 5 commits into
developfrom
fix/password-change-session-continuity

Conversation

@jeffwu-1999

@jeffwu-1999 jeffwu-1999 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

问题

两个独立缺陷:

  1. 改密码后当前会话被杀但前端无感知:change_password 使 token_version+1 吊销所有会话(含当前),前端只报"密码更新成功"留在原页,后续操作全部 401。
  2. 自助注销假成功:authService.revoke 用裸 fetch 绕过 401 拦截器,catch 只打日志、finally 无条件清本地会话、永远返回 {error:null} → 删除账号失败(401/500/网络断)时 UI 谎报"注销成功",账号实际未删。

复现边界(实测确认)

  • 缺陷 2 仅在普通用户自助注销路径(个人设置页"删除账号"→ POST /api/user/revoke)触发;管理员在资源管理页删他人走 DELETE /api/users/{id}(fetchWithAuth,错误处理正常),不受影响。
  • ADMIN/SU 的自助注销按钮被角色守卫禁用,复现须用 USER 账号:登录→改自己密码→不重登→点个人设置页"删除账号"→假报成功但新密码仍可登录。

修复(产品决策:保留当前会话、吊销其它会话,GitHub/Google 式)

后端

  • update_password 成功后:revoke_local_sessions_by_user 吊销全部旧会话行(含当前,杜绝旧会话残留可刷新)→ build_token_response(user_id, token_version+1) 签发唯一新会话;其它设备因 ver 不匹配自然失效。错误分支(弱密码/同密码/旧密码错/CAS 并发)不吊销不签发。
  • update_password_endpoint 成功响应 {message, data:{session}},对齐 signin 信封。

server.js

  • /api/user/password 加入 AUTH_INTERCEPT_ENDPOINTS,原 scope 内替换 HttpOnly cookie(不轮换 scope);PUT body 原样透传;响应 sanitized,token 不进浏览器 JS。

前端

  • updatePassword 成功用返回 expires_at 刷新本地会话存储,不登出。
  • revoke 改用 fetchWithAuth(401 走统一会话失效流程),失败返回 {error};removeSessionFromStorage 只在真成功时执行;useAuthenticationState.revoke 失败上抛;handleDeleteAccount 失败提示 revokeFailed 留在本页,成功才跳转。

验证(全部实跑)

套件 结果
test_native_authentication + test_local_session_renewal + test_user_management_app 132 passed(含换发顺序/版本+1/错误分支不轮换/按 user 吊销 SQL/端点信封断言)
vitest authPasswordSession + userProfileDeleteAccount 10 passed(会话持久化/兼容/错误分支;revoke 401 不清理不报成功/网络失败/scope 接管;删除失败提示不跳转/ADMIN 拦截)
node --test authPasswordCookie 4 passed(白名单/body 透传/原 scope cookie 注入+sanitize/401 不替换 cookie)
既有 authCookieTransport/nativeTokenRefresh/apiProxyRouting 46 passed
tsc --noEmit / copyright 干净 / 13 文件 OK

基线区分:resourceKnowledgeAuthorization 3 例失败已在干净 develop HEAD 复跑确认属既有问题,与本 PR 无关。

20261203-171138

改动规模

13 文件 +657/-24(产品代码 7 文件,测试 6 文件)。不动 deploy/sql、workflows。

…op reporting rejected account deletion as success
@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jeffwu-1999
jeffwu-1999 merged commit 3e13265 into develop Dec 3, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants