fix(regression): preserve external command auth context

This commit is contained in:
Tak Hoffman
2026-03-27 20:03:45 -05:00
parent d604ce9950
commit d2e25b03fe
2 changed files with 29 additions and 5 deletions

View File

@@ -34,11 +34,13 @@ function resolveProviderFromContext(
ctx: MsgContext,
cfg: OpenClawConfig,
): { providerId: ChannelId | undefined; hadResolutionError: boolean } {
const explicitMessageChannel =
normalizeMessageChannel(ctx.Provider) ??
normalizeMessageChannel(ctx.Surface) ??
normalizeMessageChannel(ctx.OriginatingChannel);
if (explicitMessageChannel === INTERNAL_MESSAGE_CHANNEL) {
const explicitMessageChannels = [ctx.Surface, ctx.OriginatingChannel, ctx.Provider]
.map((value) => normalizeMessageChannel(value))
.filter((value): value is string => Boolean(value));
const explicitMessageChannel = explicitMessageChannels.find(
(value) => value !== INTERNAL_MESSAGE_CHANNEL,
);
if (!explicitMessageChannel && explicitMessageChannels.includes(INTERNAL_MESSAGE_CHANNEL)) {
return { providerId: undefined, hadResolutionError: false };
}
const direct =

View File

@@ -216,6 +216,28 @@ describe("resolveCommandAuthorization", () => {
expect(auth.isAuthorizedSender).toBe(true);
});
it("preserves external channel command auth in mixed webchat contexts", () => {
const cfg = {
commands: { allowFrom: { whatsapp: ["+15551234567"] } },
channels: { whatsapp: { allowFrom: ["+15551234567"] } },
} as OpenClawConfig;
const auth = resolveCommandAuthorization({
ctx: {
Provider: "webchat",
Surface: "whatsapp",
OriginatingChannel: "whatsapp",
From: "whatsapp:+19995551234",
SenderE164: "+19995551234",
} as MsgContext,
cfg,
commandAuthorized: true,
});
expect(auth.providerId).toBe("whatsapp");
expect(auth.isAuthorizedSender).toBe(false);
});
it("falls back to channel allowFrom when provider allowlist resolution throws", () => {
registerAllowFromPlugins(
createThrowingAllowFromPlugin("telegram", "channels.telegram.botToken: unresolved SecretRef"),