fix(backend): 补齐三处漏洞——暂停租户拦截/金额不符落审计终态/邀请码列表滤失效

P0 暂停租户是空开关:admin 能设 suspended,但 preflight 只查预算+余额、不看
租户 status → 暂停后照样能提交烧积分。加 TenantSuspended 校验(活跃租户 + 分叉时
的计费租户都拦),403 拒绝。

P1 金额不符只刷日志:回调/查单判了不符却没落审计、订单永远卡 pending 被补偿定时器
每轮重扫刷屏。加 disputed 终态 + MarkOrderDisputed(CAS 只挂一次) + 审计(首次写一次);
disputed 不在 pending 扫描内,停止无限重扫。admin /orders?status=disputed 可查。

P1 邀请码列表混入失效码:ListInvites 只按 status=active 过滤,过期/满员的码仍显示为
有效、误导邀请人。有效列表加 expires_at>now 且 used<max 过滤(RedeemInvite 本就会拒,
这里修的是展示一致性)。

三处均带 store 单测(TenantSuspended/MarkOrderDisputed CAS/ListInvites 过滤)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-21 14:20:34 +08:00
parent bd829cfecb
commit ce7cca657e
6 changed files with 151 additions and 3 deletions
@@ -54,9 +54,19 @@ func (h *Handler) preflight(c *gin.Context) (string, bool) {
return "", false
}
}
// 暂停管控:活跃租户(工作区)被暂停 → 拒绝提交。否则「暂停」只是个装了没接线的开关。
if tid := tenantID(c); h.db.TenantSuspended(c.Request.Context(), tid) {
c.JSON(http.StatusForbidden, gin.H{"error": "租户已被暂停,暂无法提交任务"})
return "", false
}
// 计费目标:数据落在活跃租户(工作区),但消耗记到"计费租户"——owner/共享计费→活跃租户,
// 否则→本人个人租户(各付各的)。硬拦截与用量都按计费租户走。
billingTenant := h.db.ResolveBillingTenantID(c.Request.Context(), userID(c), tenantID(c))
// 计费租户与活跃租户不同(共享计费分叉)时,计费租户被暂停也拦——别让暂停的组织被人借道烧积分。
if billingTenant != "" && billingTenant != tenantID(c) && h.db.TenantSuspended(c.Request.Context(), billingTenant) {
c.JSON(http.StatusForbidden, gin.H{"error": "计费租户已被暂停,暂无法提交任务"})
return "", false
}
// 积分硬拦截(默认关;开关 credit_enforce):计费租户积分余额 ≤0 则拒绝,提示充值。
if billingTenant != "" && h.db.CreditEnforceEnabled(c.Request.Context()) {
if h.db.TenantBalance(c.Request.Context(), billingTenant) <= 0 {