Merged
Conversation
## 问题描述 普通用户(非管理员令牌)登录 Web UI 后,可以通过"仪表盘" → "活跃 Session" 查看到其他用户 5 分钟内的请求内容和响应内容,造成严重的数据泄露。 ## 安全影响 - **数据泄露风险**: 用户可以查看其他用户的敏感请求和响应 - **隐私侵犯**: 违反用户数据隔离原则 - **合规风险**: 可能违反数据保护法规(如 GDPR) ## 修复方案 在所有 Session 相关 API 中添加用户权限检查: 1. **getActiveSessions()** - 列表过滤 - 管理员:可查看所有用户的 Session - 普通用户:只能查看自己的 Session 2. **getAllSessions()** - 列表过滤 - 同上,支持活跃和非活跃 Session 3. **getSessionDetails()** - 详情访问控制 - 检查 Session 所有权 - 非所有者尝试访问时记录安全日志并拒绝 4. **getSessionMessages()** - 消息访问控制 - 检查 Session 所有权 - 记录越权访问尝试 5. **getSessionResponse()** - 响应体访问控制 - 检查 Session 所有权 - 记录越权访问尝试 ## 技术实现 - 使用 `getSession()` 获取当前登录用户 - 通过 `aggregateSessionStats()` 查询 Session 的 userId - 比对 `sessionStats.userId` 与 `currentUserId` - 所有越权访问尝试都会记录安全日志 ## 测试建议 1. 创建两个普通用户(user1, user2) 2. user1 发起 API 请求产生 Session 3. user2 登录 Web UI 尝试查看 user1 的 Session 4. 预期结果:user2 只能看到自己的 Session,无法看到 user1 的 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Owner
|
@claude 审核一下 |
Contributor
Author
代码审查结果 ✅我已经完成对此 PR 的安全审查,总体评价:修复方案正确且完善,可以安全合并。 🔐 安全修复评估1. 修复完整性 ✅PR 正确修复了所有 5 个存在越权风险的函数:
发现问题: 2. 权限模型正确性 ✅
3. 安全日志记录 ✅
4. 性能优化 ✅权限过滤在缓存读取后进行,避免缓存失效。 🐛 发现的安全问题严重:
|
| 维度 | 修复前 | 修复后 |
|---|---|---|
| 数据泄露风险 | 🔴 高危(任意用户可查看所有 Session) | 🟢 已修复 |
| 隐私合规 | 🔴 不合规(违反数据隔离) | 🟢 合规 |
| 审计能力 | 🟡 无安全日志 | 🟢 记录越权尝试 |
| 性能影响 | - | 🟢 无负面影响 |
✅ 合并建议
- 必须:补充
getSessionDetails()的权限检查(严重安全问题) - 可选:代码重构(提取权限检查工具函数)
- 可选:添加单元测试(覆盖权限隔离逻辑)
修复后即可合并到 dev 分支(请勿直接合并到 main)。
📚 参考
- OWASP A01:2021 - Broken Access Control
- 越权访问修复最佳实践:在业务逻辑层统一进行身份验证和授权检查
Contributor
Author
更正:所有函数均已修复 ✅我之前的评论有误,重新审查后发现 ✅ 修复完整性(已全部修复)
所有 5 个函数均已正确添加权限检查,修复完整。 🎯 修复方案一致性验证检查了所有函数的权限检查逻辑,均遵循相同的安全模式:
🔍 深度审查结果1. 缓存安全性 ✅// getActiveSessions() 和 getAllSessions()
const cached = getActiveSessionsCache();
if (cached) {
// ✅ 正确:先读缓存,再根据用户角色过滤
const filteredData = isAdmin
? cached
: cached.filter(s => s.userId === currentUserId);
return filteredData;
}
2. 数据库查询安全性 ✅// getSessionMessages(), getSessionDetails(), getSessionResponse()
const sessionStats = await aggregateSessionStats(sessionId);
// ✅ 先检查 Session 是否存在
if (\!sessionStats) {
return { ok: false, error: "Session 不存在" };
}
// ✅ 再检查用户权限
if (\!isAdmin && sessionStats.userId \!== currentUserId) {
logger.warn(`[Security] Unauthorized access attempt...`);
return { ok: false, error: "无权访问该 Session" };
}
3. 错误处理一致性 ✅所有函数的错误处理均遵循相同模式:
🧪 建议测试场景场景 1:列表过滤测试(
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #51
问题描述
普通用户(非管理员令牌)登录 Web UI 后,可以通过以下路径查看到其他用户 5 分钟内的请求内容和响应内容:
这是一个严重的数据泄露漏洞,违反了用户数据隔离原则。
安全影响
修复方案
在所有 Session 相关 API 中添加用户权限检查,实现数据隔离:
所有越权访问尝试都会记录安全日志。
测试建议
修改的文件