furniture-3d-system-Wu/docs/solutions/security-issues/hole-match-access-throttle-20260215.md

1.5 KiB
Raw Blame History

title, date, module, problem_type, severity, symptoms, root_cause, resolution_type, status, confidence, tags, related_patterns
title date module problem_type severity symptoms root_cause resolution_type status confidence tags related_patterns
holes/match 权限与滥用防护收口 2026-02-15 hole-match security_issue critical
autoSave=true 仅校验登录态,未校验产品编辑权限
autoSave=false 可匿名读取非公开产品匹配结果
匿名高频调用会触发大规模匹配计算
匹配链路缺少产品级权限判断与接口级节流,且计算规模没有上限 code_fix active high
security
permission
rate-limit
holes
match
SEC-HOLE-PERM-001

现象与影响

/api/holes/match 存在“已登录即可写任意产品”和“匿名可读非公开产品”的边界缺口,同时高频请求会放大 CPU/DB 消耗。

修复动作

  1. 在 src/server/services/hole.service.ts 的 matchHardware 增加产品解析与权限判断:
    • 保存结果:canEditProduct
    • 预览结果:canViewProduct
    • 匿名访问:仅允许 PUBLIC 产品
  2. 增加匹配规模上限(匿名/登录/保存分级)和五金库查询上限(1500)。
  3. 在 src/app/api/holes/match/route.ts 增加按用户/IP 的窗口限流。

验证

  • npm run type-check -- --pretty false 通过
  • npm test -- tests/lib/cad-panel-linking.test.ts --runInBand 通过
  • npm test -- tests/api/auth-me.test.ts --runInBand 通过

预防策略

  • 任何“预览 + 保存”双模式接口都要在 Service 层拆分权限模型,而不是只在 Route 判断登录态。
  • 计算型接口默认要有“节流 + 规模上限”双保险。