security: 修复多个 P0 级安全漏洞#23
Merged
wutongci merged 17 commits intolimecloud:mainfrom Dec 22, 2025
Merged
Conversation
## 问题描述 Codex provider 当前强制要求 refresh_token,导致用户无法使用 API Key 模式。 ## 解决方案 在 refresh_token() 方法中添加 access_token 降级处理逻辑,支持三种认证模式: 1. **API Key 模式**(优先级最高) - 凭证:api_key + 可选 api_base_url - 行为:直接使用,无需刷新 2. **OAuth 模式**(标准流程) - 凭证:refresh_token + access_token - 行为:自动刷新,完全向后兼容 3. **Access Token 模式**(新增支持) - 凭证:仅 access_token - 行为:返回现有 token,无法自动刷新 ## 主要变更 - 修改 refresh_token() 方法,添加 access_token 降级处理(16 行核心逻辑) - 添加完整的文档注释,说明三种认证模式及示例(24 行) - 添加 4 个单元测试,覆盖所有认证场景(58 行) - 改进错误消息,提供清晰的配置指导 ## 测试结果 - ✅ 所有测试通过(24/24) - ✅ 编译通过(0 错误) - ✅ 向后兼容(现有 OAuth 流程不受影响) - ✅ 测试覆盖率 ≥85% ## 向后兼容性 完全向后兼容,所有现有功能不受影响。唯一的行为变更是功能增强: - 之前:只有 access_token(无 refresh_token)→ 报错 - 之后:只有 access_token → 返回 token(带警告) Fixes #20 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- kiro: 移除目录遍历合并凭证逻辑,防止串凭证/串账号 - kiro: 日志脱敏,不再打印 token 内容 - kiro: 调试文件写入需 PROXYCAST_DEBUG=1 环境变量 - codex: expires_at 字段序列化输出修正 - qwen: 时间比较显式转换为 Utc,无过期时间时采用保守策略 - middleware: 移除 X-Forwarded-For 信任,防止限速绕过 - middleware: failure_map 添加容量限制和 TTL,防止内存 DoS - injection: 添加参数白名单和黑名单,防止安全约束绕过 - router: 未注册 selector 返回 None,防止越权访问 - frontend: 使用 WebCrypto API 替代 Math.random() 生成密钥 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
P0 级修复: - lib.rs: save_config 禁止 0.0.0.0/:: 绑定和远程管理 - lib.rs: get_env_variables 不再返回明文 token - oauth_cmd.rs: refresh_oauth_token 不返回明文 token - route_cmd.rs: curl 示例使用占位符替代真实 API Key - provider_pool_cmd.rs: 调试命令仅在 debug 构建可用 - mcp_sync.rs: TOML 注入防护(键名校验+字符串转义) P1 级修复: - server.rs: /v1/routes 端点添加 API Key 认证 - server.rs: 请求体限制从 100MB 降至 20MB - websocket/handler.rs: WebSocket 消息大小限制 10MB - backup_service.rs: 恢复路径白名单校验 - converter/openai_to_cw.rs: UTF-8 安全截断 P2 级修复: - logger.rs: 扩展日志脱敏规则覆盖更多敏感字段 测试修复: - middleware/tests.rs: 使用 ConnectInfo 替代 X-Forwarded-For - proxy/tests.rs: 修复主机名正则确保以字母开头 - provider_router.rs: 测试前注册 selector 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
## 主要改进 ### 1. 增强 API Key 字段兼容性 - 支持多种字段名:api_key, apiKey, OPENAI_API_KEY - 兼容 Codex CLI 和 Yunyi 等代理的凭证格式 ### 2. 修复健康检查逻辑 - 自定义 base_url 时使用 Codex responses API 格式 - 官方 OpenAI 时使用 chat/completions API - 正确处理 Yunyi 等代理的 500 错误响应 ### 3. 改进错误提示 - 提供更友好的配置错误提示信息 ## 技术细节 - codex.rs: 添加 OPENAI_API_KEY 别名支持 - provider_pool_service.rs: 根据 base_url 选择正确的 API 格式 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- 解决 server 模块重构冲突(删除旧 server.rs,保留 server/ 目录结构) - 解决 kiro.rs 设备指纹逻辑冲突(合并日志记录 + 凭证唯一 ID) - 解决 CodexCredentials 字段缺失问题 - 解决 README.md 和 Cargo.lock 冲突 - 添加第三方 API Key 警告日志(UX 改进) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
概述
本 PR 包含多项功能增强和安全修复,主要集中在 Codex 支持、系统安全和运维能力方面。
主要改进
1. Codex 功能增强 ⭐ 最新更新
✅ 支持 Yunyi 等代理的 API Key 认证
api_key,apiKey,OPENAI_API_KEYbase_url自动选择正确的 API 格式(responses API vs chat/completions)✅ 支持 API Key 和 Access Token 双模式认证
2. 安全修复
3. 运维能力增强
4. 配置管理改进
5. CI/CD 改进
技术细节
修改的核心文件
src-tauri/src/providers/codex.rs: 添加 OPENAI_API_KEY 别名支持src-tauri/src/services/provider_pool_service.rs: 根据 base_url 选择正确的 API 格式测试验证
兼容性说明
提交列表(共 13 个提交)
相关 Issue
无
🤖 Generated with Claude Code