security: 实施 HttpOnly Cookie 鉴权方案
## 后端修改 - 新增 /api/logout 接口清除认证 Cookie ## 前端修改 - 移除 localStorage 存储 token/refreshToken(防止 XSS 窃取) - 移除所有手动 Authorization 头(共36处) - checkLoginStatus 改为直接调用 API 验证(Cookie 自动携带) - logout 改为调用后端接口清除 Cookie - 简化 token 刷新逻辑 ## 安全性提升 - Token 从 localStorage 迁移到 HttpOnly Cookie - XSS 攻击无法通过 JS 读取 token - 配合 SameSite 属性防御 CSRF 攻击 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1731,6 +1731,13 @@ app.post('/api/refresh-token', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// 登出(清除Cookie)
|
||||
app.post('/api/logout', (req, res) => {
|
||||
// 清除认证Cookie
|
||||
res.clearCookie('token', { path: '/' });
|
||||
res.json({ success: true, message: '已登出' });
|
||||
});
|
||||
|
||||
// ===== 需要认证的API =====
|
||||
|
||||
// 获取当前用户信息
|
||||
|
||||
Reference in New Issue
Block a user