From 60d33637d9e6e513b65f20796eb4f456bccf203b Mon Sep 17 00:00:00 2001 From: Sid Date: Fri, 6 Mar 2026 06:32:42 +0800 Subject: [PATCH] fix(auth): grant senderIsOwner for internal channels with operator.admin scope (openclaw#35704) Verified: - pnpm install --frozen-lockfile - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: Naylenv <45486779+Naylenv@users.noreply.github.com> Co-authored-by: Octane0411 <88922959+Octane0411@users.noreply.github.com> Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> --- CHANGELOG.md | 1 + src/auto-reply/command-auth.ts | 13 ++++++-- src/auto-reply/command-control.test.ts | 46 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d853a3e0ff..e324a5460b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,6 +141,7 @@ Docs: https://docs.openclaw.ai - Agents/failover cooldown classification: stop treating generic `cooling down` text as provider `rate_limit` so healthy models no longer show false global cooldown/rate-limit warnings while explicit `model_cooldown` markers still trigger failover. (#32972) thanks @stakeswky. - Agents/failover service-unavailable handling: stop treating bare proxy/CDN `service unavailable` errors as provider overload while keeping them retryable via the timeout/failover path, so transient outages no longer show false rate-limit warnings or block fallback. (#36646) thanks @jnMetaCode. - Agents/current-time UTC anchor: append a machine-readable UTC suffix alongside local `Current time:` lines in shared cron-style prompt contexts so agents can compare UTC-stamped workspace timestamps without doing timezone math. (#32423) thanks @jriff. +- TUI/webchat command-owner scope alignment: treat internal-channel gateway sessions with `operator.admin` as owner-authorized in command auth, restoring cron/gateway/connector tool access for affected TUI/webchat sessions while keeping external channels on identity-based owner checks. (from #35666, #35673, #35704) Thanks @Naylenv, @Octane0411, and @Sid-Qin. ## 2026.3.2 diff --git a/src/auto-reply/command-auth.ts b/src/auto-reply/command-auth.ts index 8f0a68c7256..ed37427d50b 100644 --- a/src/auto-reply/command-auth.ts +++ b/src/auto-reply/command-auth.ts @@ -3,7 +3,11 @@ import { getChannelDock, listChannelDocks } from "../channels/dock.js"; import type { ChannelId } from "../channels/plugins/types.js"; import { normalizeAnyChannelId } from "../channels/registry.js"; import type { OpenClawConfig } from "../config/config.js"; -import { INTERNAL_MESSAGE_CHANNEL, normalizeMessageChannel } from "../utils/message-channel.js"; +import { + INTERNAL_MESSAGE_CHANNEL, + isInternalMessageChannel, + normalizeMessageChannel, +} from "../utils/message-channel.js"; import type { MsgContext } from "./templating.js"; export type CommandAuthorization = { @@ -341,7 +345,12 @@ export function resolveCommandAuthorization(params: { const senderId = matchedSender ?? senderCandidates[0]; const enforceOwner = Boolean(dock?.commands?.enforceOwnerForCommands); - const senderIsOwner = Boolean(matchedSender); + const senderIsOwnerByIdentity = Boolean(matchedSender); + const senderIsOwnerByScope = + isInternalMessageChannel(ctx.Provider) && + Array.isArray(ctx.GatewayClientScopes) && + ctx.GatewayClientScopes.includes("operator.admin"); + const senderIsOwner = senderIsOwnerByIdentity || senderIsOwnerByScope; const ownerAllowlistConfigured = ownerAllowAll || explicitOwners.length > 0; const requireOwner = enforceOwner || ownerAllowlistConfigured; const isOwnerForCommands = !requireOwner diff --git a/src/auto-reply/command-control.test.ts b/src/auto-reply/command-control.test.ts index 76a12398801..cb829871b10 100644 --- a/src/auto-reply/command-control.test.ts +++ b/src/auto-reply/command-control.test.ts @@ -458,6 +458,52 @@ describe("resolveCommandAuthorization", () => { expect(deniedAuth.isAuthorizedSender).toBe(false); }); }); + + it("grants senderIsOwner for internal channel with operator.admin scope", () => { + const cfg = {} as OpenClawConfig; + const ctx = { + Provider: "webchat", + Surface: "webchat", + GatewayClientScopes: ["operator.admin"], + } as MsgContext; + const auth = resolveCommandAuthorization({ + ctx, + cfg, + commandAuthorized: true, + }); + expect(auth.senderIsOwner).toBe(true); + }); + + it("does not grant senderIsOwner for internal channel without admin scope", () => { + const cfg = {} as OpenClawConfig; + const ctx = { + Provider: "webchat", + Surface: "webchat", + GatewayClientScopes: ["operator.approvals"], + } as MsgContext; + const auth = resolveCommandAuthorization({ + ctx, + cfg, + commandAuthorized: true, + }); + expect(auth.senderIsOwner).toBe(false); + }); + + it("does not grant senderIsOwner for external channel even with admin scope", () => { + const cfg = {} as OpenClawConfig; + const ctx = { + Provider: "telegram", + Surface: "telegram", + From: "telegram:12345", + GatewayClientScopes: ["operator.admin"], + } as MsgContext; + const auth = resolveCommandAuthorization({ + ctx, + cfg, + commandAuthorized: true, + }); + expect(auth.senderIsOwner).toBe(false); + }); }); describe("control command parsing", () => {