1. 13 Feb, 2026 1 commit
  2. 07 Feb, 2026 4 commits
    • yangjianbo's avatar
      fix(audit): 第二批审计修复 — P0 生产 Bug、安全加固、性能优化、缓存一致性、代码质量 · 2588fa6a
      yangjianbo authored
      
      
      基于 backend-code-audit 审计报告,修复剩余 P0/P1/P2 共 34 项问题:
      
      P0 生产 Bug:
      - 修复 time.Since(time.Now()) 计时逻辑错误 (P0-03)
      - generateRandomID 改用 crypto/rand 替代固定索引 (P0-04)
      - IncrementQuotaUsed 重写为 Ent 原子操作消除 TOCTOU 竞态 (P0-05)
      
      安全加固:
      - gateway/openai handler 错误响应替换为泛化消息,防止内部信息泄露 (P1-14)
      - usage_log_repo dateFormat 参数改用白名单映射,防止 SQL 注入 (P1-16)
      - 默认配置安全加固:sslmode=prefer、response_headers=true、mode=release (P1-18/19, P2-15)
      
      性能优化:
      - gateway handler 循环内 defer 替换为显式 releaseWait 闭包 (P1-02)
      - group_repo/promo_code_repo Count 前 Clone 查询避免状态污染 (P1-03)
      - usage_log_repo 四个查询添加 LIMIT 10000 防止 OOM (P1-07)
      - GetBatchUsageStats 添加时间范围参数,默认最近 30 天 (P1-10)
      - ip.go CIDR 预编译为包级变量 (P1-11)
      - BatchUpdateCredentials 重构为先验证后更新 (P1-13)
      
      缓存一致性:
      - billing_cache 添加 jitteredTTL 防止缓存雪崩 (P2-10)
      - DeductUserBalance/UpdateSubscriptionUsage 错误传播修复 (P2-12)
      - UserService.UpdateBalance 成功后异步失效 billingCache (P2-13)
      
      代码质量:
      - search 截断改为按 rune 处理,支持多字节字符 (P2-01)
      - TLS Handshake 改为 HandshakeContext 支持 context 取消 (P2-07)
      - CORS 预检添加 Access-Control-Max-Age: 86400 (P2-16)
      
      测试覆盖:
      - 新增 user_service_test.go(UpdateBalance 缓存失效 6 个用例)
      - 新增 batch_update_credentials_test.go(fail-fast + 类型验证 7 个用例)
      - 新增 response_transformer_test.go、ip_test.go、usage_log_repo_unit_test.go、search_truncate_test.go
      - 集成测试:IncrementQuotaUsed 并发测试、billing_cache 错误传播测试
      - config_test.go 补充 server.mode/sslmode 默认值断言
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      2588fa6a
    • yangjianbo's avatar
      fix(security): 修复密码重置链接 Host Header 注入漏洞 (P0-07) · e75d3e35
      yangjianbo authored
      
      
      ForgotPassword 原来从 c.Request.Host 构建重置链接基础 URL,攻击者
      可伪造 Host 头将重置链接指向恶意域名窃取 token。
      
      修复方案:
      - ServerConfig 新增 frontend_url 配置项
      - auth_handler 改为从配置读取前端 URL,未配置时拒绝请求
      - Validate() 校验 frontend_url 必须为绝对 HTTP(S) URL
      - 新增 TestValidateServerFrontendURL 单元测试
      - config.example.yaml 添加配置说明
      Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
      e75d3e35
    • yangjianbo's avatar
      feat:增加端口 · fc104dfb
      yangjianbo authored
      fc104dfb
    • yangjianbo's avatar
      feat(gateway): 支持强制 Codex CLI 模式并伪装 UA · ce764bf2
      yangjianbo authored
      - Codex CLI 请求仅使用内置 instructions,不再读取 opencode 缓存/回源\n- 新增 gateway.force_codex_cli(环境变量 GATEWAY_FORCE_CODEX_CLI)\n- ForceCodexCLI=true 时转发上游强制 User-Agent=codex_cli_rs/0.0.0\n- 更新 deploy 示例配置
      ce764bf2
  3. 06 Feb, 2026 5 commits
  4. 05 Feb, 2026 1 commit
  5. 04 Feb, 2026 1 commit
  6. 02 Feb, 2026 2 commits
    • song's avatar
      merge upstream main · 0170d19f
      song authored
      0170d19f
    • shaw's avatar
      feat(deploy): 优化 Docker 部署体验,新增一键部署脚本 · 5cda9792
      shaw authored
      ## 新增功能
      
      - 新增 docker-compose.local.yml:使用本地目录存储数据,便于迁移和备份
      - 新增 docker-deploy.sh:一键部署脚本,自动生成安全密钥(JWT_SECRET、TOTP_ENCRYPTION_KEY、POSTGRES_PASSWORD)
      - 新增 deploy/.gitignore:忽略运行时数据目录
      
      ## 优化改进
      
      - docker-compose.local.yml 包含 PGDATA 环境变量修复,解决 PostgreSQL 18 Alpine 数据丢失问题
      - 脚本自动设置 .env 文件权限为 600,增强安全性
      - 脚本显示生成的凭证,方便用户记录
      
      ## 文档更新
      
      - 更新 README.md(英文版):新增"快速开始"章节,添加部署版本对比表
      - 更新 README_CN.md(中文版):同步英文版更新
      - 更新 deploy/README.md:详细说明两种部署方式和迁移方法
      
      ## 使用方式
      
      一键部署:
      ```bash
      curl -sSL https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/deploy/docker-deploy.sh | bash
      docker-compose -f docker-compose.local.yml up -d
      ```
      
      轻松迁移:
      ```bash
      tar czf sub2api-complete.tar.gz deploy/
      # 传输到新服务器后直接解压启动即可
      ```
      5cda9792
  7. 30 Jan, 2026 1 commit
  8. 26 Jan, 2026 1 commit
    • shaw's avatar
      feat(auth): 实现 TOTP 双因素认证功能 · 1245f07a
      shaw authored
      新增功能:
      - 支持 Google Authenticator 等应用进行 TOTP 二次验证
      - 用户可在个人设置中启用/禁用 2FA
      - 登录时支持 TOTP 验证流程
      - 管理后台可全局开关 TOTP 功能
      
      安全增强:
      - TOTP 密钥使用 AES-256-GCM 加密存储
      - 添加 TOTP_ENCRYPTION_KEY 配置项,必须手动配置才能启用功能
      - 防止服务重启导致加密密钥变更使用户无法登录
      - 验证失败次数限制,防止暴力破解
      
      配置说明:
      - Docker 部署:在 .env 中设置 TOTP_ENCRYPTION_KEY
      - 非 Docker 部署:在 config.yaml 中设置 totp.encryption_key
      - 生成密钥命令:openssl rand -hex 32
      1245f07a
  9. 20 Jan, 2026 2 commits
  10. 18 Jan, 2026 2 commits
  11. 16 Jan, 2026 2 commits
    • yangjianbo's avatar
      perf(Caddy): 添加静态资源长期缓存配置 · 74a3c745
      yangjianbo authored
      
      
      - 为 /assets/* 设置 1 年缓存 + immutable 标记
      - 包含 logo.png 和 favicon.ico
      - 移除可能干扰缓存的 Pragma/Expires 头
      
      效果:
      - 浏览器缓存命中后不再发送请求
      - Cloudflare CDN 可正确缓存静态资源
      - 重复访问页面秒开
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      74a3c745
    • yangjianbo's avatar
      feat(安全): 实现 CSP nonce 支持解决内联脚本安全问题 · c9f79dee
      yangjianbo authored
      
      
      - 添加 GenerateNonce() 生成加密安全的随机 nonce
      - SecurityHeaders 中间件为每个请求生成唯一 nonce
      - CSP 策略支持 __CSP_NONCE__ 占位符动态替换
      - embed_on.go 注入的内联脚本添加 nonce 属性
      - 添加 Cloudflare Insights 域名到 CSP 允许列表
      - 添加完整单元测试,覆盖率达到 89.8%
      
      解决的问题:
      - 内联脚本违反 CSP script-src 指令
      - Cloudflare Insights beacon.min.js 加载被阻止
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      c9f79dee
  12. 15 Jan, 2026 1 commit
    • yangjianbo's avatar
      fix(认证): OAuth 401 直接标记错误状态 · a458e684
      yangjianbo authored
      - OAuth 401 清理缓存并设置错误状态
      
      - 移除 oauth_401_cooldown_minutes 配置及示例
      
      - 更新 401 相关单测
      
      破坏性变更: OAuth 401 不再临时不可调度,需手动恢复
      a458e684
  13. 14 Jan, 2026 1 commit
  14. 12 Jan, 2026 2 commits
  15. 11 Jan, 2026 6 commits
  16. 10 Jan, 2026 1 commit
  17. 09 Jan, 2026 7 commits
    • Song Siyu's avatar
      feat: antigravity 配额域限流 + SSE 上限 (#222) · 7d1fe818
      Song Siyu authored
      * fix: 添加 gemini-3-flash 前缀映射支持 gemini-3-flash-preview
      
      * feat(antigravity): 增强请求参数和注入 Antigravity 身份 system prompt
      
      * feat: antigravity 配额域限流
      
      * chore: 调整 SSE 单行上限到 25MB
      
      * chore: 提升 SSE 单行上限到 40MB
      7d1fe818
    • Edric.Li's avatar
      feat(api-key): 添加 IP 白名单/黑名单限制功能 (#221) · 0a4641c2
      Edric.Li authored
      * feat(api-key): add IP whitelist/blacklist restriction and usage log IP tracking
      
      - Add IP restriction feature for API keys (whitelist/blacklist with CIDR support)
      - Add IP address logging to usage logs (admin-only visibility)
      - Remove billing_type column from usage logs UI (redundant)
      - Use generic "Access denied" error message for security
      
      Backend:
      - New ip package with IP/CIDR validation and matching utilities
      - Database migrations for ip_whitelist, ip_blacklist (api_keys) and ip_address (usage_logs)
      - Middleware IP restriction check after API key validation
      - Input validation for IP/CIDR patterns on create/update
      
      Frontend:
      - API key form with enable toggle for IP restriction
      - Shield icon indicator in table for keys with IP restriction
      - Removed billing_type filter and column from usage views
      
      * fix: update API contract tests for ip_whitelist/ip_blacklist fields
      
      Add ip_whitelist and ip_blacklist fields to expected JSON responses
      in API contract tests to match the new API key schema.
      0a4641c2
    • Edric Li's avatar
      fix: update API contract tests for ip_whitelist/ip_blacklist fields · e83f644c
      Edric Li authored
      Add ip_whitelist and ip_blacklist fields to expected JSON responses
      in API contract tests to match the new API key schema.
      e83f644c
    • song's avatar
      chore: 提升 SSE 单行上限到 40MB · c2a6ca8d
      song authored
      c2a6ca8d
    • song's avatar
      chore: 调整 SSE 单行上限到 25MB · 7b1cf2c4
      song authored
      7b1cf2c4
    • admin's avatar
      feat(auth): 添加 Linux DO Connect OAuth 登录支持 · 152d0cde
      admin authored
      - 新增 Linux DO OAuth 配置项和环境变量支持
      - 实现 OAuth 授权流程和回调处理
      - 前端添加 Linux DO 登录按钮和回调页面
      - 支持通过 Linux DO 账号注册/登录
      - 添加相关国际化文本
      
      🤖 Generated with [Claude Code](https://claude.com/claude-code
      
      )
      Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
      152d0cde
    • shaw's avatar
      27291f2e