安全漏洞修复: 支付越权/密码存储/CORS/事务保护/参数校验#25
Open
phpmac wants to merge 7 commits into
Open
Conversation
- 多阶段 Dockerfile 构建 (Go 1.17 builder + Alpine runtime) - docker-compose.yml 集成 MySQL 8.0, 含健康检查依赖 - config.docker.yaml 容器环境配置 (静默日志模式) - docker-entrypoint.sh 数据库表为空时自动导入 schema - .dockerignore 排除构建无关文件 - config.yaml 数据库名统一为 mall
含8类漏洞验证(C1-C3/H1-H4/M1-M2), 涵盖认证缺失/支付绕过/ 密码学弱点/CORS配置错误/竞态条件/输入校验等问题. 测试通过标准: 漏洞存在=测试通过. 漏洞详情文档位于 docs/todo.md.
- C1+C2: 后台商品管理和首页配置路由组添加 AdminJWTAuth 中间件 - C3: PaySuccess/FinishOrder/CancelOrder 添加 token 参数和订单归属校验 - H1: 密码存储从 MD5 升级为 bcrypt, 兼容旧 MD5 自动升级 - H2: CORS 从反射任意 Origin 改为白名单模式 - H4: SaveOrder 添加数据库事务保护, 软删除购物项加 is_deleted=0 防并发 - M1: SaveOrder/FinishOrder/CancelOrder 验证失败后补 return - M2: ShouldBindJSON 错误检查补全, MallOrderAddress 补 TableName
删除断言"漏洞存在"的测试文件, 保留断言"漏洞已修复"的测试 同时补充 config.yaml 的 CORS 白名单配置
包含以下安全修复: - C3 [Critical]: 支付/订单操作添加用户归属校验, 防止越权操作 - H1 [High]: 密码存储从无盐MD5升级为bcrypt - H2 [High]: CORS从反射任意Origin改为配置化白名单 - H4 [High]: 订单创建添加事务保护和并发安全控制 - M1 [Medium]: 参数验证失败后添加return, 防止代码继续执行 - M2 [Medium]: ShouldBindJSON错误不再被忽略 - C1/C2: 管理后台接口添加JWT认证中间件 同时将 module path 还原为官方 main.go 以兼容上游仓库
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.
概述
对 newbee-mall-api-go 进行安全审计后发现的漏洞修复, 涉及 Critical/High/Medium 三个级别共 7 个问题.
关联 Issue: #24
修复内容
C3 [Critical] 支付接口越权操作
service/mall/mall_order.goPaySuccess/FinishOrder/CancelOrder/GetOrderDetail 方法添加 userId 归属校验api/v1/mall/mall_order.go从请求头获取 token 传入 service 层H1 [High] 密码无盐MD5存储
utils/md5.go注册时使用 bcrypt 哈希存储密码H2 [High] CORS 反射任意 Origin
middleware/cors.go改为配置化白名单config/cors.go和config.yaml中的cors.allow-origins配置项H4 [High] 订单创建无事务保护
service/mall/mall_order.goSaveOrder 使用 GORM Transaction 包裹全部操作AND is_deleted = 0条件防止并发重复消费stock_num = stock_num - ? WHERE stock_num >= ?M1 [Medium] 参数验证失败后缺少 return
api/v1/mall/mall_order.goVerify 失败后添加 return, 防止代码继续执行M2 [Medium] ShouldBindJSON 错误被忽略
api/v1/mall/mall_order.go不再使用_ =忽略绑定错误C1/C2 管理后台接口权限
测试
包含自动化测试验证所有修复:
test/c1_c2_auth_fixed_test.go- 验证管理接口需要认证test/c3_pay_fixed_test.go- 验证支付操作需要订单归属test/h1_h2_h4_m1_m2_fixed_test.go- 验证 bcrypt/CORS/事务/参数校验测试计划