Skip to content

Commit c568621

Browse files
committed
fix: enforce owner tools in skill dispatch
1 parent b907309 commit c568621

4 files changed

Lines changed: 111 additions & 4 deletions

File tree

‎src/auto-reply/reply/get-reply-inline-actions.skip-when-config-empty.test.ts‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ describe("handleInlineActions", () => {
10571057

10581058
expect(result).toEqual({ kind: "reply", reply: { text: "✅ Done." } });
10591059
const toolsArgs = mockObjectArg(createOpenClawToolsMock, "createOpenClawTools");
1060-
expect(toolsArgs).not.toHaveProperty("senderIsOwner");
1060+
expect(toolsArgs.senderIsOwner).toBe(true);
10611061
expect(toolsArgs.nativeChannelId).toBe("oc_native_chat");
10621062
expect(toolsArgs.beforeToolCallHookContext).toMatchObject({
10631063
cwd: "/tmp",
@@ -1350,6 +1350,64 @@ describe("handleInlineActions", () => {
13501350
expect(toolExecute).not.toHaveBeenCalled();
13511351
});
13521352

1353+
it("does not expose owner-only tools to authorized non-owner skill dispatch", async () => {
1354+
const typing = createTypingController();
1355+
const toolExecute = vi.fn(async () => ({ content: "sent" }));
1356+
createOpenClawToolsMock.mockReturnValue([
1357+
{
1358+
name: "conversations_send",
1359+
execute: toolExecute,
1360+
},
1361+
]);
1362+
1363+
const ctx = buildTestCtx({
1364+
Body: "/send_conversation hello",
1365+
CommandBody: "/send_conversation hello",
1366+
});
1367+
const skillCommands: SkillCommandSpec[] = [
1368+
{
1369+
name: "send_conversation",
1370+
skillName: "send-conversation",
1371+
description: "Send a conversation message",
1372+
dispatch: {
1373+
kind: "tool",
1374+
toolName: "conversations_send",
1375+
argMode: "raw",
1376+
},
1377+
sourceFilePath: "/tmp/plugin/commands/send-conversation.md",
1378+
},
1379+
];
1380+
1381+
const result = await handleInlineActions(
1382+
createHandleInlineActionsInput({
1383+
ctx,
1384+
typing,
1385+
cleanedBody: "/send_conversation hello",
1386+
command: {
1387+
isAuthorizedSender: true,
1388+
senderId: "allowed-user",
1389+
senderIsOwner: false,
1390+
abortKey: "allowed-user",
1391+
rawBodyNormalized: "/send_conversation hello",
1392+
commandBodyNormalized: "/send_conversation hello",
1393+
},
1394+
overrides: {
1395+
cfg: { commands: { text: true } },
1396+
allowTextCommands: true,
1397+
skillCommands,
1398+
},
1399+
}),
1400+
);
1401+
1402+
expect(result).toEqual({
1403+
kind: "reply",
1404+
reply: { text: "❌ Tool not available: conversations_send" },
1405+
});
1406+
const toolsArgs = mockObjectArg(createOpenClawToolsMock, "createOpenClawTools");
1407+
expect(toolsArgs.senderIsOwner).toBe(false);
1408+
expect(toolExecute).not.toHaveBeenCalled();
1409+
});
1410+
13531411
it("applies subagent policy to ACP envelope inline dispatch sessions", async () => {
13541412
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-inline-acp-policy-"));
13551413
try {

‎src/auto-reply/reply/get-reply-inline-actions.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ export async function handleInlineActions(params: {
419419
workspaceDir,
420420
provider,
421421
model,
422+
senderIsOwner: command.senderIsOwner,
422423
senderId: command.senderId,
423424
currentChannelId: command.channelId,
424425
groupId: extractExplicitGroupId(ctx.From),

‎src/skills/runtime/tool-dispatch.test.ts‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import { describe, expect, it, vi } from "vitest";
66
import { replaceSessionEntry } from "../../config/sessions/session-accessor.js";
77
import type { SessionEntry } from "../../config/sessions/types.js";
88
import type { OpenClawConfig } from "../../config/types.openclaw.js";
9+
import { GATEWAY_OWNER_ONLY_CORE_TOOLS } from "../../security/dangerous-tools.js";
910

1011
type CreateOpenClawToolsArg = {
1112
beforeToolCallHookContext?: {
1213
skillCommand?: { skillFile?: string };
1314
};
1415
cronCreatorToolAllowlist?: Array<string | { name: string; pluginId?: string }>;
1516
nativeChannelId?: string;
17+
pluginToolDenylist?: string[];
18+
senderIsOwner?: boolean;
1619
};
1720

1821
const hoisted = vi.hoisted(() => {
@@ -29,6 +32,7 @@ const hoisted = vi.hoisted(() => {
2932
makeTool("read"),
3033
makeTool("cron"),
3134
makeTool("exec"),
35+
makeTool("conversations_send"),
3236
]),
3337
};
3438
});
@@ -55,6 +59,7 @@ describe("resolveSkillDispatchTools", () => {
5559
workspaceDir: "/tmp/openclaw-skill-tool-dispatch-test",
5660
provider: "openai",
5761
model: "gpt-5.5",
62+
senderIsOwner: true,
5863
});
5964

6065
const args = hoisted.createOpenClawToolsMock.mock.calls[0]?.[0];
@@ -72,14 +77,16 @@ describe("resolveSkillDispatchTools", () => {
7277
workspaceDir: "/tmp/openclaw-skill-tool-dispatch-test",
7378
provider: "openai",
7479
model: "gpt-5.5",
80+
senderIsOwner: true,
7581
});
7682

7783
const args = hoisted.createOpenClawToolsMock.mock.calls.at(-1)?.[0];
78-
expect(tools.map((tool) => tool.name)).toEqual(["read", "cron", "exec"]);
84+
expect(tools.map((tool) => tool.name)).toEqual(["read", "cron", "exec", "conversations_send"]);
7985
expect(args?.cronCreatorToolAllowlist).toEqual([
8086
{ name: "read" },
8187
{ name: "automations" },
8288
{ name: "exec" },
89+
{ name: "conversations_send" },
8390
]);
8491
});
8592

@@ -92,6 +99,7 @@ describe("resolveSkillDispatchTools", () => {
9299
workspaceDir: "/tmp/openclaw-skill-tool-dispatch-test",
93100
provider: "openai",
94101
model: "gpt-5.5",
102+
senderIsOwner: true,
95103
skillCommand: {
96104
name: "daily-brief",
97105
skillFile: "/workspace/skills/daily-brief/SKILL.md",
@@ -138,11 +146,44 @@ describe("resolveSkillDispatchTools", () => {
138146
workspaceDir: "/tmp/openclaw-skill-tool-dispatch-test",
139147
provider: "openai",
140148
model: "gpt-5.5",
149+
senderIsOwner: true,
141150
});
142151

143152
expect(tools.map((tool) => tool.name)).toEqual(expect.arrayContaining(["read", "exec"]));
144153
} finally {
145154
fs.rmSync(tempDir, { recursive: true, force: true });
146155
}
147156
});
157+
158+
it("removes owner-only core tools for authorized non-owner dispatch", () => {
159+
const common = {
160+
message: { surface: "telegram", senderId: "allowed-user" },
161+
cfg: {} as OpenClawConfig,
162+
agentId: "main",
163+
sessionKey: "agent:main:telegram:direct:allowed-user",
164+
workspaceDir: "/tmp/openclaw-skill-tool-dispatch-test",
165+
provider: "openai",
166+
model: "gpt-5.5",
167+
};
168+
169+
const nonOwnerTools = resolveSkillDispatchTools({
170+
...common,
171+
senderIsOwner: false,
172+
});
173+
const nonOwnerArgs = hoisted.createOpenClawToolsMock.mock.calls.at(-1)?.[0];
174+
expect(nonOwnerTools.map((tool) => tool.name)).not.toContain("conversations_send");
175+
expect(nonOwnerArgs?.senderIsOwner).toBe(false);
176+
expect(nonOwnerArgs?.pluginToolDenylist).toEqual(
177+
expect.arrayContaining([...GATEWAY_OWNER_ONLY_CORE_TOOLS]),
178+
);
179+
180+
const ownerTools = resolveSkillDispatchTools({
181+
...common,
182+
senderIsOwner: true,
183+
});
184+
const ownerArgs = hoisted.createOpenClawToolsMock.mock.calls.at(-1)?.[0];
185+
expect(ownerTools.map((tool) => tool.name)).toContain("conversations_send");
186+
expect(ownerArgs?.senderIsOwner).toBe(true);
187+
expect(ownerArgs?.pluginToolDenylist).not.toContain("conversations_send");
188+
});
148189
});

‎src/skills/runtime/tool-dispatch.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type { SessionEntry } from "../../config/sessions.js";
2525
import type { OpenClawConfig } from "../../config/types.openclaw.js";
2626
import { logVerbose } from "../../globals.js";
2727
import { getPluginToolMeta } from "../../plugins/tools.js";
28+
import { GATEWAY_OWNER_ONLY_CORE_TOOLS } from "../../security/dangerous-tools.js";
2829
import { resolveGatewayMessageChannel } from "../../utils/message-channel.js";
2930
import type { SkillCommandSpec } from "../types.js";
3031

@@ -45,8 +46,8 @@ type SkillDispatchMessageContext = {
4546

4647
/**
4748
* Policy-enforcement seam for skill `command-dispatch: tool` invocations.
48-
* Keep this aligned with the normal tool surfaces so GHSA-mhm4-93fw-4qr2
49-
* stays closed across allow/deny, group, sandbox, and subagent policy layers.
49+
* Keep this aligned with normal tool surfaces across sender, group, sandbox,
50+
* and subagent policy layers.
5051
*/
5152
export function resolveSkillDispatchTools(params: {
5253
message: SkillDispatchMessageContext;
@@ -58,6 +59,7 @@ export function resolveSkillDispatchTools(params: {
5859
workspaceDir: string;
5960
provider: string;
6061
model: string;
62+
senderIsOwner: boolean;
6163
senderId?: string;
6264
currentChannelId?: string;
6365
skillCommand?: Pick<SkillCommandSpec, "name" | "skillFile" | "skillName" | "skillSource"> & {
@@ -116,6 +118,8 @@ export function resolveSkillDispatchTools(params: {
116118
sessionKey: params.sessionKey,
117119
});
118120
const sandboxPolicy = sandboxRuntime.sandboxed ? sandboxRuntime.toolPolicy : undefined;
121+
const ownerOnlyCoreToolPolicy =
122+
params.senderIsOwner === false ? { deny: [...GATEWAY_OWNER_ONLY_CORE_TOOLS] } : undefined;
119123
const explicitPolicyList = [
120124
profilePolicy,
121125
providerProfilePolicy,
@@ -128,6 +132,7 @@ export function resolveSkillDispatchTools(params: {
128132
sandboxPolicy,
129133
subagentPolicy,
130134
inheritedToolPolicy,
135+
ownerOnlyCoreToolPolicy,
131136
];
132137
const explicitDenylist = collectExplicitDenylist(explicitPolicyList);
133138
const inheritedToolAllowlist: string[] = [];
@@ -166,6 +171,7 @@ export function resolveSkillDispatchTools(params: {
166171
sandboxed: sandboxRuntime.sandboxed,
167172
requesterAgentIdOverride: params.agentId,
168173
requesterSenderId: params.senderId,
174+
senderIsOwner: params.senderIsOwner,
169175
sessionId: params.sessionEntry?.sessionId,
170176
currentChannelId: params.currentChannelId,
171177
...(beforeToolCallHookContext ? { beforeToolCallHookContext } : {}),
@@ -200,6 +206,7 @@ export function resolveSkillDispatchTools(params: {
200206
{ policy: sandboxPolicy, label: "sandbox tools.allow" },
201207
{ policy: subagentPolicy, label: "subagent tools.allow" },
202208
{ policy: inheritedToolPolicy, label: "inherited tools" },
209+
{ policy: ownerOnlyCoreToolPolicy, label: "gateway sender owner-only tools" },
203210
],
204211
declaredToolAllowlist: buildDeclaredToolAllowlistContext({
205212
config: params.cfg,

0 commit comments

Comments
 (0)