fix: normalize shared approval target channels

This commit is contained in:
Gustavo Madeira Santana
2026-04-01 11:59:35 -04:00
parent ed5d108c9b
commit 4d1cfb983e
2 changed files with 23 additions and 1 deletions

View File

@@ -40,6 +40,27 @@ describe("isChannelExecApprovalTargetRecipient", () => {
}),
).toBe(false);
});
it("normalizes the requested channel id before matching targets", () => {
const cfg: OpenClawConfig = {
approvals: {
exec: {
enabled: true,
mode: "targets",
targets: [{ channel: "matrix", to: "user:@owner:example.org" }],
},
},
};
expect(
isChannelExecApprovalTargetRecipient({
cfg,
senderId: "@owner:example.org",
channel: " Matrix ",
matchTarget: ({ target, normalizedSenderId }) => target.to === `user:${normalizedSenderId}`,
}),
).toBe(true);
});
});
describe("createChannelExecApprovalProfile", () => {

View File

@@ -49,6 +49,7 @@ export function isChannelExecApprovalTargetRecipient(params: {
}): boolean {
const normalizeSenderId = params.normalizeSenderId ?? defaultNormalizeSenderId;
const normalizedSenderId = params.senderId ? normalizeSenderId(params.senderId) : undefined;
const normalizedChannel = params.channel.trim().toLowerCase();
if (!normalizedSenderId || !isApprovalTargetsMode(params.cfg)) {
return false;
}
@@ -58,7 +59,7 @@ export function isChannelExecApprovalTargetRecipient(params: {
}
const normalizedAccountId = params.accountId ? normalizeAccountId(params.accountId) : undefined;
return targets.some((target) => {
if (target.channel?.trim().toLowerCase() !== params.channel) {
if (target.channel?.trim().toLowerCase() !== normalizedChannel) {
return false;
}
if (