Skip to content

fix: 全仓库深度安全审查与优化修复(30 文件,Critical/High/Medium 级缺陷) - #16

Merged
ClassTechStar merged 35 commits into
Project-MethodBox:mainfrom
ClassTechStar:fix/comprehensive-bugfix-and-optimization
Aug 9, 2026
Merged

fix: 全仓库深度安全审查与优化修复(30 文件,Critical/High/Medium 级缺陷)#16
ClassTechStar merged 35 commits into
Project-MethodBox:mainfrom
ClassTechStar:fix/comprehensive-bugfix-and-optimization

Conversation

@ClassTechStar

@ClassTechStar ClassTechStar commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

概述

本 PR 对 GalReview 仓库进行了全面的代码审查与深度优化,覆盖 8 个微服务、网关、前端和部署配置,共修复 30+ 个文件中的 Critical / High / Medium 级缺陷。

修复分类

Critical(安全漏洞)

# 文件 缺陷 修复
C-1 GalGameService/Program.cs 后台 Task catch 块中 TryTransitionJob 调用未隔离,MongoDB 不可达时 job 永久卡死 独立 try-catch 包裹
C-2 gateway/src/config.ts trust proxy 硬编码为 1,匿名限流可被 X-Forwarded-For 绕过 改为可配置 TRUST_PROXY,默认不采信
C-3 frontend/server.mjs 静态文件回退对所有 404 返回 200 + index.html,CSS/JS/图片缺失被伪装为 HTML 按扩展名分流:SPA 路由回退,其余返回 404
C-4 AuthService/FileService/OCRService Dockerfile 容器以 root 运行 添加 USER $APP_UIDUSER ocruser
C-5 AuthService appsettings.Development.json 提交了可用的 SMTP 账号与授权码 替换为 CHANGE_ME 占位

High(安全/可用性)

# 文件 缺陷 修复
H-1 GalGameService/Program.cs ex.Message 直接返回给客户端,泄露内部异常细节 替换为稳定描述
H-2 GalGameService/CreditBillingClient.cs 无限制读取响应体,恶意上游可 OOM 新增 ReadBoundedAsync(64KB 上限)
H-3 gateway/src/config.ts 空字符串环境变量使 ?? 失效 env() 改用 v.length > 0 检查
H-4 gateway/src/index.ts 无优雅关闭、无 EADDRINUSE 处理 添加 SIGTERM/SIGINT graceful shutdown
H-5 gateway/src/routes/health.ts clearTimeout 在 try 体内,异常路径定时器泄漏 移到 finally 块
H-6 gateway/src/middleware/errorHandler.ts headersSent 时静默吞掉错误 改为 next(err) 委托 Express
H-7 gateway/package.json @types/express: ^5.0.0 与运行时 express v4 不匹配 降级到 ^4.17.21
H-8 frontend/src/lib/poll.ts 轮询无 AbortSignal,组件卸载后继续请求 新增 signal?: AbortSignal 参数
H-9 frontend/src/lib/workflow.ts localStorage 写入溢出无降级 try-catch 降级为最小状态
H-10 frontend/src/pages/KnowledgePointsPage.tsx null nextReviewAt 被 new Date() 解析为 Invalid Date 空值守卫 + Number.isFinite 校验

Medium/Low(性能/健壮性)

# 文件 缺陷 修复
M-1 GalGameService/MongoGameStore.cs CountDocuments(Empty) 全表扫描 改为 EstimatedDocumentCount()
L-1 GalGameService/Program.cs 网关密钥 string.Equals 可时序攻击 改用 CryptographicOperations.FixedTimeEquals
L-2 GalGameService/MongoGameStore.cs 默认端口 5253 非 MongoDB 标准 改为 27017
L-3 compose.integration.yaml 默认密码 root/galreview 改为 CHANGE_ME
L-4 compose.integration.yaml 前端绑定 0.0.0.0 改为 127.0.0.1
L-5 .env.windows.production.example MySQL 密码 root、SslMode=Preferred 改为 CHANGE_ME、SslMode=Required
M-2 .github/workflows/ci.yml 缺 NuGet 缓存、缺 3 个测试步骤 添加缓存 + PracticeService/CreditService/RenderService 测试
M-3 deploy/nginx/galreview.conf.example 缺安全 HTTP 头和 gzip 添加 4 个安全头 + gzip 压缩
M-4 GalGameService/appsettings.json AI 功能默认开启,无 API key 时运行时报错 Enabled 改为 false
M-5 PracticeService/ReciteQuestionGenerator.cs 空字符串处理不健壮 添加空值守卫

部署配置优化

  • 所有 Dockerfile 添加 HEALTHCHECK 和 curl
  • PracticeService Dockerfile 添加 --chown 确保文件属主正确
  • KnowledgeService Dockerfile 添加 ASPNETCORE_URLS=http://+:8080
  • CreditService Dockerfile 添加 HEALTHCHECK 和 non-root user
  • compose.integration.yaml 添加 gateway/frontend 日志轮转(10m/3 份)
  • ci.yml 添加 NuGet 缓存和 5 个新测试步骤

测试

  • CI 流程已更新,覆盖 .NET 8/10 双 SDK + Node 22
  • 所有修改保持原接口、请求响应结构与业务语义不变
  • GalGameService 测试断言字符串(5 个)完整保留

文件清单(30 文件)

Gateway(5): config.ts, index.ts, errorHandler.ts, health.ts, package.json
Frontend(4): poll.ts, workflow.ts, KnowledgePointsPage.tsx, server.mjs
GalGameService(4): Program.cs, CreditBillingClient.cs, MongoGameStore.cs, appsettings.json
PracticeService(3): ReciteQuestionGenerator.cs, SharedPracticePackageStore.cs, ModelScoring.cs
RenderService(2): adapter.ts, sessions.ts
FileService(1): Program.cs
CreditService(1): Program.cs
OCRService(1): app.py
Dockerfile(6): AuthService, FileService, OCRService, CreditService, PracticeService, KnowledgeService
配置/CI/部署(7): compose.integration.yaml, ci.yml, nginx.conf, .env.windows.production.example, gateway/.env.example, appsettings.Development.json, deploy env

@ClassTechStar ClassTechStar changed the title Fix/comprehensive bugfix and optimization fix: 全仓库深度安全审查与优化修复(30 文件,Critical/High/Medium 级缺陷) Aug 9, 2026
@ClassTechStar
ClassTechStar force-pushed the fix/comprehensive-bugfix-and-optimization branch from 800dff8 to 7d73cf2 Compare August 9, 2026 12:16
@ClassTechStar
ClassTechStar force-pushed the fix/comprehensive-bugfix-and-optimization branch from 7d73cf2 to 05e51b3 Compare August 9, 2026 12:21
- ci.yml: Remove redundant working-directory from RenderService step
  to prevent path nesting error (cd + working-directory conflict)
- gateway/package.json: Revert @types/express to ^5.0.0 to match
  the generated package-lock.json, fixing npm ci failure
- FileService/Program.cs: Add explicit null-check for values[0]
  in GatewayUser to fix CS8602 compiler warning
@ClassTechStar
ClassTechStar merged commit 0ba2bec into Project-MethodBox:main Aug 9, 2026
3 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.

1 participant