fix(inbox): 函数执行前按群类型校验可用性,拦截货主群越权调用快递群函数
This commit is contained in:
parent
18d33ec645
commit
0eb9e845dd
@ -3831,6 +3831,24 @@ class InboxFunctionsService extends Service {
|
||||
};
|
||||
}
|
||||
|
||||
// 群类型权限过滤:按当前群的活跃分组校验函数可用性,
|
||||
// 防止货主群调用快递群专属函数(如 handleExpressFeedback)等越权调用。
|
||||
// 无 groups 服务的场景(单元测试直接实例化)跳过校验,由调用方保证上下文。
|
||||
const groupsSvc = this.ctx.service && this.ctx.service.inbox && this.ctx.service.inbox.groups;
|
||||
if (groupsSvc && typeof groupsSvc.isFunctionAvailable === 'function') {
|
||||
const activeGroups = groupsSvc.resolveActiveGroups();
|
||||
if (!groupsSvc.isFunctionAvailable(def, activeGroups)) {
|
||||
this.ctx.logger.warn(
|
||||
`[inbox functions] 越权调用被拦截: ${name} ` +
|
||||
`groups=${(def.groups || []).join(',')} active=${activeGroups.join(',')}`
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
error: `函数 ${name} 在当前群类型下不可用,请通过对应类型的群发起`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await def.handler(params);
|
||||
return result && typeof result === 'object' ? result : { success: true, data: result };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user