Skip to content

Commit 3945231

Browse files
committed
fix(plugins): protect consent provenance and reuse acceptance
1 parent 85a3d09 commit 3945231

9 files changed

Lines changed: 222 additions & 141 deletions

‎docs/plugins/manage-plugins.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ the operator grants that apply to hooks, model access, and subagents.
109109

110110
The review token hashes the exact declared capability surface, not the plugin's
111111
executable files. Acceptance separately records installer-provided artifact
112-
integrity when available. Enabling an installed plugin requires acceptance for
113-
its current surface. Updates of enabled plugins require fresh consent
114-
when the new artifact declares additional capabilities; unchanged or narrower
112+
integrity when available. Re-enabling an installed plugin reuses acceptance
113+
when its declared surface and recorded integrity are unchanged. Updates of
114+
enabled plugins require fresh consent when the new artifact declares additional
115+
capabilities; unchanged or narrower
115116
surfaces can refresh an existing valid acceptance. Updating a disabled
116117
plugin preserves disablement and defers any required consent until enablement.
117118
Reinstalling through `plugins install` activates the plugin and must satisfy
@@ -163,8 +164,8 @@ with `--accept-capabilities`:
163164
Bundled plugins are exempt because they ship with the OpenClaw release rather
164165
than arriving as separately installed artifacts. Plugins discovered directly
165166
in a workspace or through `plugins.load.paths`, without a managed install
166-
record, cannot persist capability acceptance. The Control UI can still present
167-
their declared capabilities before enabling them.
167+
record, cannot persist capability acceptance. Their details in the Control UI
168+
still show declared capabilities.
168169

169170
`openclaw plugins install --link <path>` creates a managed install record and
170171
requires capability consent even though it loads the plugin from its source

‎src/plugins/capability-consent.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
PluginInstallRecord,
77
} from "../config/types.plugins.js";
88
import {
9+
buildPluginCapabilityConsentReview,
910
computeDeclaredSurfaceHash,
1011
createManagedPluginArtifactConsentHandler,
1112
diffDeclaredSurfaceWidening,
@@ -390,6 +391,26 @@ describe("plugin capability consent", () => {
390391
expect(resolveAcceptedSurfaceCurrent(installRecord, surface)).toBe(current);
391392
});
392393

394+
it("redacts source credentials before a capability review reaches a prompt or pending inspection", () => {
395+
const url = new URL("https://example.invalid/plugins/demo.git");
396+
url.username = "fixture-user";
397+
url.password = "fixture-password";
398+
url.searchParams.set("token", "fixture-token");
399+
const record: PluginInstallRecord = { source: "git", spec: `git:${url.href}` };
400+
401+
const review = buildPluginCapabilityConsentReview({
402+
pluginId: "plugin",
403+
manifest: {},
404+
config: {},
405+
record,
406+
});
407+
408+
expect(review.source?.spec).toBe(
409+
"git:https://***:***@example.invalid/plugins/demo.git?token=***",
410+
);
411+
expect(record.spec).toBe(`git:${url.href}`);
412+
});
413+
393414
it("selects the canonical installed artifact integrity in precedence order", () => {
394415
expect(
395416
resolvePluginInstallRecordIntegrity({

‎src/plugins/capability-consent.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createHash } from "node:crypto";
22
import fs from "node:fs";
33
import path from "node:path";
4+
import { redactSensitiveUrlLikeString } from "@openclaw/net-policy/redact-sensitive-url";
45
import { PLUGIN_DECLARED_SURFACE_GROUPS } from "../../packages/gateway-protocol/src/schema/plugin-declared-surface-groups.js";
56
import type {
67
PluginInspectSource,
@@ -353,7 +354,8 @@ export function buildPluginCapabilityConsentReview(params: {
353354
reviewToken: computeDeclaredSurfaceHash(declared),
354355
source: {
355356
kind: record.source,
356-
...(spec ? { spec } : {}),
357+
// Keep operational specs in install records; prompts and RPCs receive display-safe copies.
358+
...(spec ? { spec: redactSensitiveUrlLikeString(spec) } : {}),
357359
...(packageName ? { packageName } : {}),
358360
...resolvePluginInstallRecordIntegrity(record),
359361
},

‎src/plugins/management-service.inspect.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,36 @@ describe("managed plugin inspection", () => {
159159
});
160160
});
161161

162+
it.each(["spec", "resolvedSpec"] as const)(
163+
"redacts credentials from the persisted %s without changing the install record",
164+
async (field) => {
165+
const url = new URL("https://example.invalid/plugins/demo.git");
166+
url.username = "fixture-user";
167+
url.password = "fixture-password";
168+
url.searchParams.set("token", "fixture-token");
169+
url.searchParams.set("ref", "stable");
170+
const spec = `git:${url.href}`;
171+
const metadata = metadataSnapshot({
172+
id: "community-plugin",
173+
origin: "global",
174+
enabled: false,
175+
installRecord: { source: "git", installPath: "/tmp/community-plugin", [field]: spec },
176+
});
177+
mocks.metadata.mockReturnValue(metadata);
178+
179+
const inspection = await inspectManagedPlugin({
180+
config: {},
181+
env: {},
182+
pluginId: "community-plugin",
183+
});
184+
185+
expect(inspection.source?.spec).toBe(
186+
"git:https://***:***@example.invalid/plugins/demo.git?token=***&ref=stable",
187+
);
188+
expect(metadata.index.installRecords["community-plugin"]?.[field]).toBe(spec);
189+
},
190+
);
191+
162192
it("inspects official catalog manifests and their actual pinned install candidate", async () => {
163193
mocks.metadata.mockReturnValue(emptyMetadataSnapshot());
164194
mocks.officialCatalog.mockResolvedValue({ source: "hosted", entries: [hostedFeedDiffsEntry] });

‎src/plugins/management-service.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Structured plugin catalog and lifecycle operations shared by Gateway-facing surfaces.
2+
import { redactSensitiveUrlLikeString } from "@openclaw/net-policy/redact-sensitive-url";
23
import { asSafeIntegerInRange } from "@openclaw/normalization-core/number-coercion";
34
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
45
import { uniqueStrings } from "@openclaw/normalization-core/string-normalization";
@@ -1064,7 +1065,7 @@ export async function inspectManagedPlugin(params: {
10641065
const source: PluginInspectSource | undefined = installRecord
10651066
? {
10661067
kind: installRecord.source,
1067-
...(spec ? { spec } : {}),
1068+
...(spec ? { spec: redactSensitiveUrlLikeString(spec) } : {}),
10681069
...(packageName ? { packageName } : {}),
10691070
...resolvePluginInstallRecordIntegrity(installRecord),
10701071
}
@@ -1138,7 +1139,7 @@ export async function inspectManagedPlugin(params: {
11381139
},
11391140
source: {
11401141
kind: "official-catalog",
1141-
...(spec ? { spec } : {}),
1142+
...(spec ? { spec: redactSensitiveUrlLikeString(spec) } : {}),
11421143
...(packageName ? { packageName } : {}),
11431144
...(install?.expectedIntegrity
11441145
? {

‎ui/src/e2e/plugins-config-mutation.e2e.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const workboardDisabled = {
5252
id: "workboard",
5353
name: "Workboard",
5454
description: "Plan and track work",
55-
origin: "bundled",
55+
origin: "global",
5656
installed: true,
5757
enabled: false,
5858
state: "disabled",
@@ -67,7 +67,7 @@ const workboardEnabled = {
6767
};
6868

6969
suite.define(() => {
70-
it("drains a pending draft before enabling a plugin and refreshes the result", async () => {
70+
it("drains a pending draft before re-enabling an accepted external plugin without review", async () => {
7171
await suite.withPage(
7272
{
7373
colorScheme: "dark",
@@ -146,6 +146,8 @@ suite.define(() => {
146146
});
147147

148148
await workboardRow.getByRole("button", { name: "Disable", exact: true }).waitFor();
149+
expect(await gateway.getRequests("plugins.inspect")).toHaveLength(0);
150+
expect(await page.locator("[data-plugin-consent]").count()).toBe(0);
149151
await expect
150152
.poll(async () => (await gateway.getRequests("config.get")).length)
151153
.toBeGreaterThanOrEqual(2);

‎ui/src/pages/plugins/consent-dialog.test.ts‎

Lines changed: 100 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -50,97 +50,115 @@ describe("renderPluginConsentDialog", () => {
5050
vi.restoreAllMocks();
5151
});
5252

53-
it("presents manifest capabilities, effective grants, provenance, and the trust verdict before install", () => {
54-
const inspection = createInspectResult({
55-
plugin: {
56-
id: "calendar-runtime",
57-
name: "Calendar Plus",
58-
version: "2.0.0",
59-
origin: "global",
60-
installed: false,
61-
enabled: false,
62-
},
53+
it.each([
54+
{
6355
source: {
6456
kind: "clawhub",
6557
packageName: "@openclaw/calendar-plus",
6658
integrity: "sha256-0123456789abcdefghijklmnop",
6759
integrityKind: "ssri",
6860
},
69-
declared: {
70-
channels: ["calendar-channel"],
71-
providers: ["calendar-provider"],
72-
tools: ["calendar_create"],
73-
contracts: ["gatewayMethodDispatch: calendar.dispatch"],
74-
hooks: ["before_prompt_build"],
75-
mcpServers: ["calendar-mcp"],
76-
cliCommands: ["calendar"],
77-
cliBackends: ["calendar-cli"],
78-
skills: ["schedule"],
79-
dangerousConfigFlags: ["calendar.allowShell"],
61+
provenance: "ClawHub · @openclaw/calendar-plus",
62+
integrityLabel: "Integrity: sha256-0123456789abc…",
63+
},
64+
{
65+
source: {
66+
kind: "git",
67+
spec: "https://***:***@example.com/calendar.git?token=***#main",
68+
integrity: "0123456789abcdef0123456789abcdef01234567",
69+
integrityKind: "git-commit",
8070
},
81-
grants: {
82-
hooks: {
83-
allowPromptInjection: { effective: false, configured: false },
84-
allowConversationAccess: { effective: false },
71+
provenance: "Git · https://***:***@example.com/calendar.git?token=***#main",
72+
integrityLabel: "Commit: 0123456789abcdef0123…",
73+
},
74+
] as const)(
75+
"presents capabilities, grants, safe $source.kind provenance, and trust before install",
76+
({ source, provenance, integrityLabel }) => {
77+
const inspection = createInspectResult({
78+
plugin: {
79+
id: "calendar-runtime",
80+
name: "Calendar Plus",
81+
version: "2.0.0",
82+
origin: "global",
83+
installed: false,
84+
enabled: false,
8585
},
86-
llm: { allowedModels: ["model-a", "model-b"] },
87-
subagent: { allowModelOverride: true },
88-
},
89-
trust: {
90-
disposition: "review-required",
91-
reasons: ["Requests an elevated permission"],
92-
checkedAt: "2026-08-25",
93-
},
94-
});
95-
const onConfirm = vi.fn();
96-
const container = mount({
97-
consent: {
98-
intent: {
99-
kind: "install",
100-
request: { source: "clawhub", packageName: "@openclaw/calendar-plus" },
101-
installIdentity: "plugin:calendar-runtime",
86+
source,
87+
declared: {
88+
channels: ["calendar-channel"],
89+
providers: ["calendar-provider"],
90+
tools: ["calendar_create"],
91+
contracts: ["gatewayMethodDispatch: calendar.dispatch"],
92+
hooks: ["before_prompt_build"],
93+
mcpServers: ["calendar-mcp"],
94+
cliCommands: ["calendar"],
95+
cliBackends: ["calendar-cli"],
96+
skills: ["schedule"],
97+
dangerousConfigFlags: ["calendar.allowShell"],
10298
},
103-
pluginId: "calendar-runtime",
104-
fallback: { name: "Calendar Plus", version: "2.0.0" },
105-
},
106-
inspection,
107-
onConfirm,
108-
});
109-
110-
const dialog = container.querySelector('[data-plugin-consent="install"]');
111-
const text = normalizedText(dialog);
112-
for (const value of [
113-
"Calendar Plus",
114-
"v2.0.0",
115-
"@openclaw/calendar-plus",
116-
"Integrity: sha256-0123456789abc…",
117-
"Review required",
118-
"Requests an elevated permission",
119-
"Scanned 2026-08-25",
120-
"calendar-channel",
121-
"calendar-provider",
122-
"calendar_create",
123-
"Contracts gatewayMethodDispatch: calendar.dispatch",
124-
"before_prompt_build",
125-
"calendar-mcp",
126-
"calendar-cli",
127-
"schedule",
128-
"Dangerous config flags calendar.allowShell",
129-
"Prompt injection Blocked (set in config)",
130-
"Conversation access Off (default)",
131-
"Off by default for external plugins.",
132-
"Allowed models: model-a, model-b",
133-
"Subagent model overrides Model override: Allowed",
134-
"Install Calendar Plus",
135-
]) {
136-
expect(text).toContain(value);
137-
}
138-
expect(dialog?.querySelector("[title]")?.getAttribute("title")).toBe(
139-
"sha256-0123456789abcdefghijklmnop",
140-
);
141-
dialog?.querySelector<HTMLButtonElement>(".btn.primary")?.click();
142-
expect(onConfirm).toHaveBeenCalledOnce();
143-
});
99+
grants: {
100+
hooks: {
101+
allowPromptInjection: { effective: false, configured: false },
102+
allowConversationAccess: { effective: false },
103+
},
104+
llm: { allowedModels: ["model-a", "model-b"] },
105+
subagent: { allowModelOverride: true },
106+
},
107+
trust: {
108+
disposition: "review-required",
109+
reasons: ["Requests an elevated permission"],
110+
checkedAt: "2026-08-25",
111+
},
112+
});
113+
const onConfirm = vi.fn();
114+
const container = mount({
115+
consent: {
116+
intent: {
117+
kind: "install",
118+
request: { source: "clawhub", packageName: "@openclaw/calendar-plus" },
119+
installIdentity: "plugin:calendar-runtime",
120+
},
121+
pluginId: "calendar-runtime",
122+
fallback: { name: "Calendar Plus", version: "2.0.0" },
123+
},
124+
inspection,
125+
onConfirm,
126+
});
127+
128+
const dialog = container.querySelector('[data-plugin-consent="install"]');
129+
const text = normalizedText(dialog);
130+
for (const value of [
131+
"Calendar Plus",
132+
"v2.0.0",
133+
"@openclaw/calendar-plus",
134+
provenance,
135+
integrityLabel,
136+
"Review required",
137+
"Requests an elevated permission",
138+
"Scanned 2026-08-25",
139+
"calendar-channel",
140+
"calendar-provider",
141+
"calendar_create",
142+
"Contracts gatewayMethodDispatch: calendar.dispatch",
143+
"before_prompt_build",
144+
"calendar-mcp",
145+
"calendar-cli",
146+
"schedule",
147+
"Dangerous config flags calendar.allowShell",
148+
"Prompt injection Blocked (set in config)",
149+
"Conversation access Off (default)",
150+
"Off by default for external plugins.",
151+
"Allowed models: model-a, model-b",
152+
"Subagent model overrides Model override: Allowed",
153+
"Install Calendar Plus",
154+
]) {
155+
expect(text).toContain(value);
156+
}
157+
expect(dialog?.querySelector("[title]")?.getAttribute("title")).toBe(source.integrity);
158+
dialog?.querySelector<HTMLButtonElement>(".btn.primary")?.click();
159+
expect(onConfirm).toHaveBeenCalledOnce();
160+
},
161+
);
144162

145163
it("explains an empty manifest and preserves external-plugin grants", () => {
146164
const container = mount();

‎ui/src/pages/plugins/plugins-consent-controller.ts‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export class PluginsConsentController {
204204
intent.installIdentity,
205205
);
206206
} else {
207-
void this.setEnabled(intent.pluginId, true, intent.rowKey, {
207+
void this.updateEnabled(intent.pluginId, true, intent.rowKey, {
208208
acknowledgeCapabilities: { reviewToken },
209209
});
210210
}
@@ -270,22 +270,9 @@ export class PluginsConsentController {
270270
pluginId: string,
271271
enabled: boolean,
272272
key = pluginRowKey(pluginId),
273-
): Promise<void> {
274-
const plugin = this.host.getResult()?.plugins.find((entry) => entry.id === pluginId);
275-
// Bundled code ships with the release; external code needs an explicit consent moment.
276-
if (enabled && plugin && plugin.origin !== "bundled") {
277-
this.open({ kind: "enable", pluginId, rowKey: key }, pluginId);
278-
return;
279-
}
280-
await this.setEnabled(pluginId, enabled, key);
281-
}
282-
283-
private async setEnabled(
284-
pluginId: string,
285-
enabled: boolean,
286-
key: string,
287273
options: Parameters<typeof setPluginEnabled>[3] = {},
288274
): Promise<void> {
275+
// The server owns whether stored acceptance still covers the installed artifact.
289276
await this.runMutation(
290277
key,
291278
(client) => setPluginEnabled(client, pluginId, enabled, options),

0 commit comments

Comments
 (0)