fix(review): 代码审查 6 项修复(M2/M3/m1/m2/m3/m5)

集中修复 T8/T9/T11/T15 已实现代码的审查问题:
- M2 令牌桶 Lua 改用 Redis TIME(消除多节点时钟偏斜)
- M3 after 跨租户标记复查授权 + 无授权告警兜底
- m1 before 审计 MsgSeq/MsgRandom null 防御
- m2 HealthService 加 forceDown 开关,实测 DOWN 真返 503
- m3 countByStatus 排除 done(WHERE status IN (0,1,3))
- m5 配额查询异常不缓存(下次重试)
- 附带 app.yml console charset GBK→UTF-8
M1 限流审计/事务收窄暂缓。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yixiong
2026-07-09 09:52:13 +08:00
co-authored by Claude
parent 8e2c66b363
commit b4c6652f66
6 changed files with 45 additions and 16 deletions
@@ -96,12 +96,18 @@ public class CallbackServiceImpl implements CallbackService {
ImMessage msg = parseMessage(callbackCommand, node, tenantId);
if (msg != null) {
msgKey = msg.getMsgKey();
// 跨租户标记:能到达 after 的跨租户 C2C 消息必经 before 放行(有授权)
// 未授权的已被 before 拦截(腾讯不投递、不触发 after),故 after 见到跨租户即标记
// 跨租户标记:复查授权确认(before 已拦截未授权)
// before 未开启/失效,未授权消息会漏到 after,此处查不到授权即告警(兜底发现隔离异常)
if (msg.getConvType() != null && msg.getConvType() == 1) {
String toTenant = parsePrefix(msg.getConvId());
if (toTenant != null && !toTenant.equals(tenantId)) {
msg.setIsCrossTenant(true);
if (crossTenantService.checkSendMsgGrant(
tenantId, msg.getFromAccount(), toTenant, msg.getConvId()) != null) {
msg.setIsCrossTenant(true);
} else {
log.warn("疑似未授权跨租户消息到达 after(before 可能未开启/失效)from={} to={}",
msg.getFromAccount(), msg.getConvId());
}
}
}
long exists = imMessageMapper.selectCount(Wrappers.<ImMessage>lambdaQuery()
@@ -150,9 +156,15 @@ public class CallbackServiceImpl implements CallbackService {
return fail();
}
// 命中授权:放行 + 写审计(before 阶段记录放行决策,msgKey 便于追溯)
long msgSeq = node.get("MsgSeq").getLong();
long msgRandom = node.get("MsgRandom").getLong();
String msgKey = MsgKeys.build(from, to, msgSeq, msgRandom);
// MsgSeq/MsgRandom 缺失时审计 msgKey 留空,不影响拦截决策(授权检查已完成)
String msgKey = null;
try {
long msgSeq = node.get("MsgSeq").getLong();
long msgRandom = node.get("MsgRandom").getLong();
msgKey = MsgKeys.build(from, to, msgSeq, msgRandom);
} catch (Exception ignore) {
// 回调体缺字段无法算 msgKey,审计仍写(msgKey=null
}
crossTenantService.audit(grantId, msgKey, from, to);
log.info("跨租户授权放行 from={} to={} grant={}", from, to, grantId);
return ok();