Skip to content

Commit 004835f

Browse files
hxy91819CopilotSebTardifclawsweeper[bot]
authored
fix(plugins): block untrusted workspace setup-only channel loads (#86953)
Summary: - This PR blocks disabled workspace-origin channel plugins from setup-only scoped imports, rejects their channel registrations at registry assembly, documents the trust rule, and adds regression coverage. - PR surface: Source +46, Tests +610, Docs +13. Total +669 across 22 files. - Reproducibility: yes. source inspection gives a high-confidence reproduction path: current main's setup-only ... ce channel plugin can be imported before this PR. I did not run the repro locally in this read-only review. Automerge notes: - PR branch already contained follow-up commit before automerge: test(plugins): cover workspace channel registry guard - PR branch already contained follow-up commit before automerge: fix(plugins): isolate setup channel registration errors - PR branch already contained follow-up commit before automerge: fix(channels): mark raw catalog listing internal - PR branch already contained follow-up commit before automerge: test(channels): cover trusted catalog filtering - PR branch already contained follow-up commit before automerge: test(channels): mock raw catalog helper - PR branch already contained follow-up commit before automerge: docs(changelog): credit setup channel hardening Validation: - ClawSweeper review passed for head 11438bc. - Required merge gates passed before the squash merge. Prepared head SHA: 11438bc Review: #86953 (comment) Co-authored-by: masonxhuang <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Mason Huang <[email protected]> Co-authored-by: Sebastien Tardif <[email protected]> Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com> Co-authored-by: clawsweeper[bot] <274271284+clawsweeper[bot]@users.noreply.github.com> Approved-by: hxy91819 Co-authored-by: hxy91819 <[email protected]>
1 parent 97d373f commit 004835f

22 files changed

Lines changed: 698 additions & 29 deletions

‎docs/cli/plugins.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,19 @@ openclaw plugins install -l ./my-plugin
329329
Standalone plugin files must be listed in `plugins.load.paths` rather than placed directly in `~/.openclaw/extensions` or `<workspace>/.openclaw/extensions`. Those auto-discovered roots load plugin package or bundle directories, while top-level script files are treated as local helpers and skipped.
330330

331331
<Note>
332+
Workspace-origin plugins discovered from a workspace extensions root are not
333+
imported or executed until they are explicitly enabled. For local development,
334+
run `openclaw plugins enable <plugin-id>` or set
335+
`plugins.entries.<plugin-id>.enabled: true`; if your config uses
336+
`plugins.allow`, include the same plugin id there too. This fail-closed rule
337+
also applies when channel setup explicitly targets a workspace-origin plugin for
338+
setup-only loading, so local channel plugin setup code will not run while that
339+
workspace plugin remains disabled or excluded from the allowlist. Linked installs
340+
and explicit `plugins.load.paths` entries follow the normal policy for their
341+
resolved plugin origin. See
342+
[Configure plugin policy](/tools/plugin#configure-plugin-policy)
343+
and [Configuration reference](/gateway/configuration-reference#plugins).
344+
332345
`--force` is not supported with `--link` because linked installs reuse the source path instead of copying over a managed install target.
333346

334347
Use `--pin` on npm installs to save the resolved exact spec (`name@version`) in the managed plugin index while keeping the default behavior unpinned.

‎src/channels/plugins/catalog.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,16 @@ export function buildChannelUiCatalog(
418418
return { entries, order, labels, detailLabels, systemImages, byId };
419419
}
420420

421-
export function listChannelPluginCatalogEntries(
421+
/**
422+
* Raw catalog primitive. This may include untrusted workspace entries and
423+
* workspace shadows. Security-sensitive or execution-facing callers should
424+
* prefer `listTrustedChannelPluginCatalogEntries`; use this primitive only when
425+
* the caller immediately applies trust filtering or explicitly excludes
426+
* workspace entries.
427+
*
428+
* @internal
429+
*/
430+
export function listRawChannelPluginCatalogEntries(
422431
options: CatalogOptions = {},
423432
): ChannelPluginCatalogEntry[] {
424433
const manifestEntries = listChannelCatalogEntries({
@@ -485,6 +494,17 @@ export function listChannelPluginCatalogEntries(
485494
});
486495
}
487496

497+
/**
498+
* @deprecated Use `listTrustedChannelPluginCatalogEntries` for execution-facing
499+
* paths, or `listRawChannelPluginCatalogEntries` for internal plumbing
500+
* that applies its own trust filtering.
501+
*/
502+
export function listChannelPluginCatalogEntries(
503+
options: CatalogOptions = {},
504+
): ChannelPluginCatalogEntry[] {
505+
return listRawChannelPluginCatalogEntries(options);
506+
}
507+
488508
export function getChannelPluginCatalogEntry(
489509
id: string,
490510
options: CatalogOptions = {},
@@ -493,5 +513,5 @@ export function getChannelPluginCatalogEntry(
493513
if (!trimmed) {
494514
return undefined;
495515
}
496-
return listChannelPluginCatalogEntries(options).find((entry) => entry.id === trimmed);
516+
return listRawChannelPluginCatalogEntries(options).find((entry) => entry.id === trimmed);
497517
}

‎src/cli/channel-auth.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ vi.mock("../agents/agent-scope.js", () => ({
3333
vi.mock("../channels/plugins/catalog.js", () => ({
3434
getChannelPluginCatalogEntry: mocks.getChannelPluginCatalogEntry,
3535
listChannelPluginCatalogEntries: mocks.listChannelPluginCatalogEntries,
36+
listRawChannelPluginCatalogEntries: mocks.listChannelPluginCatalogEntries,
3637
}));
3738

3839
vi.mock("../channels/plugins/helpers.js", () => ({

‎src/commands/channel-setup/channel-plugin-resolution.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ vi.mock("../../agents/agent-scope.js", () => ({
2020

2121
vi.mock("../../channels/plugins/catalog.js", () => ({
2222
listChannelPluginCatalogEntries: mocks.listChannelPluginCatalogEntries,
23+
listRawChannelPluginCatalogEntries: mocks.listChannelPluginCatalogEntries,
2324
getChannelPluginCatalogEntry: mocks.getChannelPluginCatalogEntry,
2425
}));
2526

‎src/commands/channel-setup/channel-plugin-resolution.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
22
import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../../agents/agent-scope.js";
33
import {
4-
listChannelPluginCatalogEntries,
4+
listRawChannelPluginCatalogEntries,
55
type ChannelPluginCatalogEntry,
66
} from "../../channels/plugins/catalog.js";
77
import { getChannelPlugin, normalizeChannelId } from "../../channels/plugins/index.js";
@@ -63,7 +63,7 @@ function resolveCatalogChannelEntry(raw: string, cfg: OpenClawConfig | null) {
6363
cfg,
6464
workspaceDir: resolveWorkspaceDir(cfg),
6565
})
66-
: listChannelPluginCatalogEntries({ excludeWorkspace: true });
66+
: listRawChannelPluginCatalogEntries({ excludeWorkspace: true });
6767
return entries.find((entry) => {
6868
if (normalizeOptionalLowercaseString(entry.id) === trimmed) {
6969
return true;

‎src/commands/channel-setup/discovery.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ vi.mock("../../config/plugin-auto-enable.js", () => ({
3030

3131
vi.mock("../../channels/plugins/catalog.js", () => ({
3232
listChannelPluginCatalogEntries: (_args?: unknown) => listChannelPluginCatalogEntries(),
33+
listRawChannelPluginCatalogEntries: (_args?: unknown) => listChannelPluginCatalogEntries(),
3334
}));
3435

3536
vi.mock("../../channels/chat-meta.js", () => ({

‎src/commands/channel-setup/plugin-install.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ vi.mock("../../channels/plugins/catalog.js", () => {
4848
getChannelPluginCatalogEntry: (...args: unknown[]) => getChannelPluginCatalogEntry(...args),
4949
listChannelPluginCatalogEntries: (...args: unknown[]) =>
5050
listChannelPluginCatalogEntries(...args),
51+
listRawChannelPluginCatalogEntries: (...args: unknown[]) =>
52+
listChannelPluginCatalogEntries(...args),
5153
};
5254
});
5355

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
import type { ChannelPluginCatalogEntry } from "../../channels/plugins/catalog.js";
3+
4+
const listRawChannelPluginCatalogEntries = vi.hoisted(() =>
5+
vi.fn((_opts?: unknown): ChannelPluginCatalogEntry[] => []),
6+
);
7+
const getChannelPluginCatalogEntry = vi.hoisted(() =>
8+
vi.fn((_id?: unknown, _opts?: unknown): ChannelPluginCatalogEntry | undefined => undefined),
9+
);
10+
const applyPluginAutoEnable = vi.hoisted(() =>
11+
vi.fn(({ config }: { config: unknown }) => ({
12+
config: config as never,
13+
changes: [] as string[],
14+
autoEnabledReasons: {},
15+
})),
16+
);
17+
18+
vi.mock("../../channels/plugins/catalog.js", () => ({
19+
listRawChannelPluginCatalogEntries: (opts?: unknown) => listRawChannelPluginCatalogEntries(opts),
20+
getChannelPluginCatalogEntry: (id?: unknown, opts?: unknown) =>
21+
getChannelPluginCatalogEntry(id, opts),
22+
}));
23+
24+
vi.mock("../../config/plugin-auto-enable.js", () => ({
25+
applyPluginAutoEnable: (args: unknown) =>
26+
applyPluginAutoEnable(args as { config: unknown; env?: NodeJS.ProcessEnv }),
27+
}));
28+
29+
import {
30+
getTrustedChannelPluginCatalogEntry,
31+
listSetupDiscoveryChannelPluginCatalogEntries,
32+
listTrustedChannelPluginCatalogEntries,
33+
} from "./trusted-catalog.js";
34+
35+
function createCatalogEntry(params: {
36+
id: string;
37+
pluginId: string;
38+
origin?: "workspace" | "bundled";
39+
}): ChannelPluginCatalogEntry {
40+
return {
41+
id: params.id,
42+
pluginId: params.pluginId,
43+
origin: params.origin,
44+
meta: {
45+
id: params.id,
46+
label: params.id,
47+
selectionLabel: params.id,
48+
docsPath: `/channels/${params.id}`,
49+
blurb: `${params.id} channel`,
50+
},
51+
install: {
52+
npmSpec: params.pluginId,
53+
},
54+
};
55+
}
56+
57+
describe("trusted catalog helpers", () => {
58+
beforeEach(() => {
59+
vi.clearAllMocks();
60+
applyPluginAutoEnable.mockImplementation(({ config }: { config: unknown }) => ({
61+
config: config as never,
62+
changes: [] as string[],
63+
autoEnabledReasons: {},
64+
}));
65+
});
66+
67+
it("falls back to the bundled entry for an untrusted workspace shadow", () => {
68+
const workspaceEntry = createCatalogEntry({
69+
id: "telegram",
70+
pluginId: "evil-telegram-shadow",
71+
origin: "workspace",
72+
});
73+
const bundledEntry = createCatalogEntry({
74+
id: "telegram",
75+
pluginId: "telegram",
76+
origin: "bundled",
77+
});
78+
getChannelPluginCatalogEntry
79+
.mockReturnValueOnce(workspaceEntry)
80+
.mockReturnValueOnce(bundledEntry);
81+
82+
const result = getTrustedChannelPluginCatalogEntry("telegram", {
83+
cfg: {} as never,
84+
workspaceDir: "/tmp/workspace",
85+
env: process.env,
86+
});
87+
88+
expect(result?.pluginId).toBe("telegram");
89+
expect(getChannelPluginCatalogEntry).toHaveBeenNthCalledWith(1, "telegram", {
90+
workspaceDir: "/tmp/workspace",
91+
});
92+
expect(getChannelPluginCatalogEntry).toHaveBeenNthCalledWith(2, "telegram", {
93+
workspaceDir: "/tmp/workspace",
94+
excludeWorkspace: true,
95+
});
96+
});
97+
98+
it("keeps trusted workspace overrides eligible", () => {
99+
const workspaceEntry = createCatalogEntry({
100+
id: "telegram",
101+
pluginId: "trusted-telegram-shadow",
102+
origin: "workspace",
103+
});
104+
getChannelPluginCatalogEntry.mockReturnValue(workspaceEntry);
105+
106+
const result = getTrustedChannelPluginCatalogEntry("telegram", {
107+
cfg: {
108+
plugins: {
109+
enabled: true,
110+
allow: ["trusted-telegram-shadow"],
111+
},
112+
} as never,
113+
workspaceDir: "/tmp/workspace",
114+
env: process.env,
115+
});
116+
117+
expect(result?.pluginId).toBe("trusted-telegram-shadow");
118+
expect(getChannelPluginCatalogEntry).toHaveBeenCalledTimes(1);
119+
});
120+
121+
it("omits untrusted workspace-only entries from the trusted list", () => {
122+
const workspaceOnlyEntry = createCatalogEntry({
123+
id: "my-cool-plugin",
124+
pluginId: "my-cool-plugin",
125+
origin: "workspace",
126+
});
127+
listRawChannelPluginCatalogEntries.mockImplementation((opts?: unknown) =>
128+
(opts as { excludeWorkspace?: boolean } | undefined)?.excludeWorkspace
129+
? []
130+
: [workspaceOnlyEntry],
131+
);
132+
133+
const result = listTrustedChannelPluginCatalogEntries({
134+
cfg: {} as never,
135+
workspaceDir: "/tmp/workspace",
136+
env: process.env,
137+
});
138+
139+
expect(result).toEqual([]);
140+
});
141+
142+
it("keeps workspace-only install candidates visible in discovery", () => {
143+
const workspaceOnlyEntry = createCatalogEntry({
144+
id: "my-cool-plugin",
145+
pluginId: "my-cool-plugin",
146+
origin: "workspace",
147+
});
148+
listRawChannelPluginCatalogEntries.mockImplementation((opts?: unknown) =>
149+
(opts as { excludeWorkspace?: boolean } | undefined)?.excludeWorkspace
150+
? []
151+
: [workspaceOnlyEntry],
152+
);
153+
154+
const result = listSetupDiscoveryChannelPluginCatalogEntries({
155+
cfg: {} as never,
156+
workspaceDir: "/tmp/workspace",
157+
env: process.env,
158+
});
159+
160+
expect(result.map((entry) => entry.pluginId)).toEqual(["my-cool-plugin"]);
161+
});
162+
163+
it("treats auto-enabled workspace plugins as trusted", () => {
164+
const workspaceEntry = createCatalogEntry({
165+
id: "telegram",
166+
pluginId: "trusted-telegram-shadow",
167+
origin: "workspace",
168+
});
169+
getChannelPluginCatalogEntry.mockReturnValue(workspaceEntry);
170+
applyPluginAutoEnable.mockImplementation(({ config }: { config: unknown }) => ({
171+
config: {
172+
...(config as Record<string, unknown>),
173+
plugins: {
174+
enabled: true,
175+
allow: ["trusted-telegram-shadow"],
176+
},
177+
} as never,
178+
changes: ["trusted-telegram-shadow"] as string[],
179+
autoEnabledReasons: {
180+
"trusted-telegram-shadow": ["channel configured"],
181+
},
182+
}));
183+
184+
const result = getTrustedChannelPluginCatalogEntry("telegram", {
185+
cfg: {
186+
channels: {
187+
telegram: { token: "existing-token" },
188+
},
189+
} as never,
190+
workspaceDir: "/tmp/workspace",
191+
env: process.env,
192+
});
193+
194+
expect(result?.pluginId).toBe("trusted-telegram-shadow");
195+
expect(getChannelPluginCatalogEntry).toHaveBeenCalledTimes(1);
196+
});
197+
});

‎src/commands/channel-setup/trusted-catalog.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
getChannelPluginCatalogEntry,
3-
listChannelPluginCatalogEntries,
3+
listRawChannelPluginCatalogEntries,
44
type ChannelPluginCatalogEntry,
55
} from "../../channels/plugins/catalog.js";
66
import { applyPluginAutoEnable } from "../../config/plugin-auto-enable.js";
@@ -61,11 +61,11 @@ function listChannelPluginCatalogEntriesWithTrustedFallback(
6161
},
6262
onMissingFallback: (entry: ChannelPluginCatalogEntry) => ChannelPluginCatalogEntry[],
6363
): ChannelPluginCatalogEntry[] {
64-
const unfiltered = listChannelPluginCatalogEntries({
64+
const unfiltered = listRawChannelPluginCatalogEntries({
6565
workspaceDir: params.workspaceDir,
6666
});
6767
const fallbackById = new Map(
68-
listChannelPluginCatalogEntries({
68+
listRawChannelPluginCatalogEntries({
6969
workspaceDir: params.workspaceDir,
7070
excludeWorkspace: true,
7171
}).map((entry) => [entry.id, entry]),

‎src/commands/channel-setup/workspace-shadow-bypass.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const getChannelPluginCatalogEntry = vi.hoisted(() => vi.fn());
3131

3232
vi.mock("../../channels/plugins/catalog.js", () => ({
3333
listChannelPluginCatalogEntries: (opts?: unknown) => listChannelPluginCatalogEntries(opts),
34+
listRawChannelPluginCatalogEntries: (opts?: unknown) => listChannelPluginCatalogEntries(opts),
3435
getChannelPluginCatalogEntry: (...args: unknown[]) =>
3536
getChannelPluginCatalogEntry(...(args as [string, Record<string, unknown>])),
3637
}));

0 commit comments

Comments
 (0)