Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

plugins: require an explicit approve fingerprint for RPC plugin grants (#36279)

Neil9470b4618c7a
diff --git a/src/main/plugins/plugin-audit-log.ts b/src/main/plugins/plugin-audit-log.ts
index 628dc1d8d34..5dd8504a067 100644
--- a/src/main/plugins/plugin-audit-log.ts
+++ b/src/main/plugins/plugin-audit-log.ts
@@ -5,7 +5,8 @@ import { dirname, join } from 'node:path'
export type PluginAuditEntry = {
ts: number
- actor: `plugin:${string}`
+ /** `cli:<caller>` records approvals granted through the explicit CLI approve flag. */
+ actor: `plugin:${string}` | `cli:${string}`
method: string
/** Bounded summary only; full parameters may contain user content. */
summary: string
diff --git a/src/main/plugins/plugin-cli-approval.test.ts b/src/main/plugins/plugin-cli-approval.test.ts
new file mode 100644
index 00000000000..dc2789cce26
--- /dev/null
+++ b/src/main/plugins/plugin-cli-approval.test.ts
@@ -0,0 +1,163 @@
+import { describe, expect, it, vi } from 'vitest'
+import { parsePluginManifest } from '../../shared/plugins/manifest/plugin-manifest'
+import { fingerprintPluginConsent } from '../../shared/plugins/approval/plugin-consent-fingerprint'
+import {
+ PLUGIN_APPROVAL_REQUIRED_CODE,
+ PLUGIN_APPROVAL_STALE_CODE,
+ PluginApprovalRequiredError
+} from '../../shared/plugins/approval/plugin-cli-approval'
+import type { PluginAuditEntry } from './plugin-audit-log'
+import type { ValidDiscoveredPlugin } from './plugin-discovery'
+import { approvePluginFromCli, pluginCliApprovalRequest } from './plugin-cli-approval'
+
+const CONTENT_HASH = `sha256-${'a'.repeat(64)}`
+
+function plugin(raw: Record<string, unknown>, overrides: Partial<ValidDiscoveredPlugin> = {}) {
+ const parsed = parsePluginManifest({
+ manifestVersion: 2,
+ id: 'demo',
+ publisher: 'acme',
+ name: 'Demo',
+ version: '1.0.0',
+ engines: { orca: '>=1.4.245' },
+ ...raw
+ })
+ if (!parsed.ok) {
+ throw new Error(parsed.error)
+ }
+ const valid: ValidDiscoveredPlugin = {
+ pluginKey: 'acme.demo',
+ rootDir: '/plugins/acme.demo',
+ manifest: parsed.manifest,
+ consentFingerprint: fingerprintPluginConsent(parsed.manifest, CONTENT_HASH),
+ contentHash: CONTENT_HASH,
+ isDev: false,
+ ...overrides
+ }
+ return valid
+}
+
+const WORKER = {
+ execution: 'trusted-worker',
+ pluginApi: 1,
+ main: 'main.mjs',
+ contributes: { commands: [{ id: 'ping', title: 'Ping' }] },
+ capabilities: [{ kind: 'terminal:send' }]
+}
+const THEME = {
+ execution: 'data',
+ contributes: { themes: [{ id: 'dusk', title: 'Dusk', path: 'themes/dusk.json' }] }
+}
+
+function harness(target: ValidDiscoveredPlugin, consents: Record<string, string> = {}) {
+ const audit: PluginAuditEntry[] = []
+ const applyConsent = vi.fn().mockResolvedValue(undefined)
+ const service = {
+ findValidPlugin: (key: string) => (key === target.pluginKey ? target : null),
+ options: { getPluginConsents: () => consents, getDisabledPlugins: () => [] },
+ recordApprovalAudit: vi.fn(async (entry: PluginAuditEntry) => {
+ audit.push(entry)
+ })
+ }
+ const approve = (approvalFingerprint?: string) =>
+ approvePluginFromCli({
+ service,
+ applyConsent,
+ pluginKey: target.pluginKey,
+ approvalFingerprint,
+ action: 'enable',
+ caller: { kind: 'local-cli' }
+ })
+ return { audit, applyConsent, approve }
+}
+
+async function rejection(promise: Promise<unknown>): Promise<PluginApprovalRequiredError> {
+ try {
+ await promise
+ } catch (error) {
+ if (error instanceof PluginApprovalRequiredError) {
+ return error
+ }
+ throw error
+ }
+ throw new Error('expected a rejection')
+}
+
+describe('approvePluginFromCli', () => {
+ it('enables content-only plugins without a flag and audits it', async () => {
+ const theme = plugin(THEME)
+ const { approve, applyConsent, audit } = harness(theme)
+ await expect(approve()).resolves.toBe('content-only')
+ expect(applyConsent).toHaveBeenCalledWith({
+ pluginKey: 'acme.demo',
+ reviewedFingerprint: theme.consentFingerprint,
+ decision: 'approve'
+ })
+ expect(audit.map((entry) => [entry.actor, entry.outcome])).toEqual([
+ ['cli:local', 'attempt'],
+ ['cli:local', 'ok']
+ ])
+ })
+
+ it('refuses code without the flag and explains exactly what would be granted', async () => {
+ const worker = plugin(WORKER)
+ const { approve, applyConsent, audit } = harness(worker)
+ const error = await rejection(approve())
+ expect(error.code).toBe(PLUGIN_APPROVAL_REQUIRED_CODE)
+ expect(error.data.grants.execution).toBe('trusted-worker')
+ expect(error.data.grants.capabilities.map((capability) => capability.kind)).toEqual([
+ 'terminal:send'
+ ])
+ expect(error.data.approveFlag).toBe(`--approve ${error.data.approvalFingerprint}`)
+ expect(error.message).toContain('Type and run commands in your terminals')
+ expect(applyConsent).not.toHaveBeenCalled()
+ expect(audit).toEqual([])
+ })
+
+ it('grants with the shown fingerprint and records that it was approved via CLI', async () => {
+ const worker = plugin(WORKER)
+ const { approve, applyConsent, audit } = harness(worker)
+ const fingerprint = pluginCliApprovalRequest(worker, 'enable').approvalFingerprint
+ await expect(approve(fingerprint)).resolves.toBe('approve-flag')
+ expect(applyConsent).toHaveBeenCalledOnce()
+ expect(audit.at(-1)).toMatchObject({
+ actor: 'cli:local',
+ method: 'plugins.approve',
+ outcome: 'ok',
+ summary: expect.stringContaining(`approved via CLI --approve ${fingerprint}`)
+ })
+ })
+
+ it('rejects a fingerprint shown for another build, plugin or access set', async () => {
+ const shown = pluginCliApprovalRequest(plugin(WORKER), 'enable').approvalFingerprint
+ const variants = [
+ plugin({ ...WORKER, version: '1.0.1' }),
+ plugin(WORKER, { contentHash: `sha256-${'b'.repeat(64)}` }),
+ plugin({ ...WORKER, capabilities: [{ kind: 'terminal:send' }, { kind: 'agent:read' }] }),
+ plugin({ ...WORKER, id: 'other' }, { pluginKey: 'acme.other' })
+ ]
+ for (const variant of variants) {
+ const { approve, applyConsent } = harness(variant)
+ const error = await rejection(approve(shown))
+ expect(error.code).toBe(PLUGIN_APPROVAL_STALE_CODE)
+ expect(error.data.approvalFingerprint).not.toBe(shown)
+ expect(applyConsent).not.toHaveBeenCalled()
+ }
+ })
+
+ it('needs no flag when the current access is already approved', async () => {
+ const worker = plugin(WORKER)
+ const { approve, applyConsent } = harness(worker, { 'acme.demo': worker.consentFingerprint })
+ await expect(approve()).resolves.toBe('already-approved')
+ expect(applyConsent).not.toHaveBeenCalled()
+ })
+
+ it('tells a development folder approval that later code edits are not re-reviewed', () => {
+ const request = pluginCliApprovalRequest(
+ plugin(WORKER, { isDev: true, contentHash: null, consentContentHash: 'dev-identity' }),
+ 'dev-load'
+ )
+ expect(request.contentIdentity).toBe('dev-identity')
+ expect(request.why).toContain('Later code edits in this development folder')
+ })
+})
diff --git a/src/main/plugins/plugin-cli-approval.ts b/src/main/plugins/plugin-cli-approval.ts
new file mode 100644
index 00000000000..75432c8a273
--- /dev/null
+++ b/src/main/plugins/plugin-cli-approval.ts
@@ -0,0 +1,130 @@
+import {
+ buildPluginApprovalRequest,
+ pluginApprovalFingerprint,
+ PluginApprovalRequiredError,
+ pluginNeedsCliApproval,
+ PluginNotFoundError,
+ type PluginApprovalAction
+} from '../../shared/plugins/approval/plugin-cli-approval'
+import type { PluginConsentRequest } from '../../shared/plugins/approval/plugin-consent-request'
+import type { RpcCallerIdentity } from '../runtime/rpc/rpc-caller-identity'
+import type { PluginAuditEntry } from './plugin-audit-log'
+import type { ValidDiscoveredPlugin } from './plugin-discovery'
+
+export type PluginCliApprovalService = {
+ findValidPlugin: (pluginKey: string) => ValidDiscoveredPlugin | null
+ options: {
+ getPluginConsents: () => Record<string, string>
+ getDisabledPlugins: () => string[]
+ }
+ recordApprovalAudit: (entry: PluginAuditEntry) => Promise<void>
+}
+
+export type PluginCliApprovalOutcome = 'content-only' | 'approve-flag' | 'already-approved'
+
+function contentIdentity(plugin: ValidDiscoveredPlugin): string {
+ return plugin.contentHash ?? plugin.consentContentHash ?? `dev:${plugin.rootDir}`
+}
+
+function subject(plugin: ValidDiscoveredPlugin) {
+ return {
+ pluginKey: plugin.pluginKey,
+ manifest: plugin.manifest,
+ consentFingerprint: plugin.consentFingerprint,
+ contentIdentity: contentIdentity(plugin),
+ isDev: plugin.isDev
+ }
+}
+
+export function pluginCliApprovalRequest(
+ plugin: ValidDiscoveredPlugin,
+ action: PluginApprovalAction
+) {
+ return buildPluginApprovalRequest(subject(plugin), action)
+}
+
+export function pluginCliAuditActor(caller: RpcCallerIdentity | undefined): `cli:${string}` {
+ if (!caller) {
+ return 'cli:unknown'
+ }
+ switch (caller.kind) {
+ case 'local-cli':
+ return 'cli:local'
+ case 'paired-device':
+ return `cli:paired-device:${caller.deviceId}`
+ case 'desktop':
+ return 'cli:desktop'
+ }
+}
+
+/**
+ * The only RPC path that grants a plugin access. Content-only plugins pass; anything that runs
+ * code or acts needs the fingerprint from a prior `approval_required`, and every grant is audited.
+ */
+export async function approvePluginFromCli(input: {
+ service: PluginCliApprovalService
+ applyConsent: (request: PluginConsentRequest) => Promise<void>
+ pluginKey: string
+ approvalFingerprint?: string
+ action: PluginApprovalAction
+ caller: RpcCallerIdentity | undefined
+}): Promise<PluginCliApprovalOutcome> {
+ const plugin = input.service.findValidPlugin(input.pluginKey)
+ if (!plugin) {
+ throw new PluginNotFoundError(input.pluginKey)
+ }
+ const consented =
+ input.service.options.getPluginConsents()[plugin.pluginKey] === plugin.consentFingerprint
+ const disabled = input.service.options.getDisabledPlugins().includes(plugin.pluginKey)
+ if (consented && !disabled) {
+ return 'already-approved'
+ }
+ const needsFlag = pluginNeedsCliApproval(plugin.manifest)
+ if (needsFlag) {
+ const request = pluginCliApprovalRequest(plugin, input.action)
+ if (input.approvalFingerprint === undefined) {
+ throw new PluginApprovalRequiredError(request)
+ }
+ if (input.approvalFingerprint !== pluginApprovalFingerprint(subject(plugin))) {
+ throw new PluginApprovalRequiredError(request, true)
+ }
+ }
+ const actor = pluginCliAuditActor(input.caller)
+ const summary = needsFlag
+ ? `${plugin.pluginKey}@${plugin.manifest.version} approved via CLI --approve ${input.approvalFingerprint} (${input.action})`
+ : `${plugin.pluginKey}@${plugin.manifest.version} content-only plugin enabled via CLI (${input.action})`
+ // Why before the write: a failed audit append must not leave an unlogged grant.
+ await input.service.recordApprovalAudit({
+ ts: Date.now(),
+ actor,
+ method: 'plugins.approve',
+ summary,
+ outcome: 'attempt'
+ })
+ try {
+ await input.applyConsent({
+ pluginKey: plugin.pluginKey,
+ reviewedFingerprint: plugin.consentFingerprint,
+ decision: 'approve'
+ })
+ } catch (error) {
+ await input.service
+ .recordApprovalAudit({
+ ts: Date.now(),
+ actor,
+ method: 'plugins.approve',
+ summary,
+ outcome: 'error'
+ })
+ .catch(() => undefined)
+ throw error
+ }
+ await input.service.recordApprovalAudit({
+ ts: Date.now(),
+ actor,
+ method: 'plugins.approve',
+ summary,
+ outcome: 'ok'
+ })
+ return needsFlag ? 'approve-flag' : 'content-only'
+}
diff --git a/src/main/plugins/plugin-service.ts b/src/main/plugins/plugin-service.ts
index 93c65015906..8210af4ead0 100644
--- a/src/main/plugins/plugin-service.ts
+++ b/src/main/plugins/plugin-service.ts
@@ -18,7 +18,7 @@ import {
type DiscoveredPlugin,
type ValidDiscoveredPlugin
} from './plugin-discovery'
-import { PluginAuditLog } from './plugin-audit-log'
+import { PluginAuditLog, type PluginAuditEntry } from './plugin-audit-log'
import { executePluginHostCallRequest } from './workers/plugin-host-call-adapter'
import { PluginContentVerifier } from './plugin-content-integrity'
import {
@@ -189,6 +189,10 @@ export class PluginService {
return this.installed.discovered
}
+ recordApprovalAudit(entry: PluginAuditEntry): Promise<void> {
+ return this.audit.record(entry)
+ }
+
getLogs(pluginKey: string) {
return this.installed.logs.get(pluginKey)
}
diff --git a/src/main/runtime/rpc/errors.ts b/src/main/runtime/rpc/errors.ts
index a9af338eba9..c8f0b0c0f3e 100644
--- a/src/main/runtime/rpc/errors.ts
+++ b/src/main/runtime/rpc/errors.ts
@@ -30,6 +30,7 @@ import {
SKILL_INSTALL_RPC_ERROR_CODE,
classifySkillInstallFailureCode
} from '../../../shared/skill-install-failure'
+import { PLUGIN_CLI_ERROR_CODES } from '../../../shared/plugins/approval/plugin-cli-approval'
import { GIT_DIFF_TOO_LARGE_CODE } from '../../../shared/git-diff-transport-budget'
import { AUTOMATION_OWNER_CONFLICT_CODES } from '../../../shared/automation-owner-conflict'
import { ARCHIVE_HOOK_FAILED_REMOVAL_CODE } from '../../../shared/worktree/archive-hook-removal-gate'
@@ -177,6 +178,7 @@ const STRUCTURED_RUNTIME_PASSTHROUGH_CODES: ReadonlySet<string> = new Set([
AGENT_SKILL_BUNDLE_NAME_TAKEN_CODE,
AGENT_SKILL_SHARING_UNSUPPORTED_ENVIRONMENT_CODE,
SKILL_INSTALL_RPC_ERROR_CODE,
+ ...PLUGIN_CLI_ERROR_CODES,
// Keep owner conflicts distinct so clients can choose reload, re-adopt or stop offering the action.
...Object.values(AUTOMATION_OWNER_CONFLICT_CODES),
...Object.values(ORCHESTRATION_SESSION_CALLER_ERROR_CODES)
diff --git a/src/main/runtime/rpc/methods/plugins.test.ts b/src/main/runtime/rpc/methods/plugins.test.ts
index 902c23810b4..2595b72fe51 100644
--- a/src/main/runtime/rpc/methods/plugins.test.ts
+++ b/src/main/runtime/rpc/methods/plugins.test.ts
@@ -3,6 +3,10 @@ import { eraseRpcMethods, type RpcContext, type RpcMethod } from '../core'
import type { PluginService } from '../../../plugins/plugin-service'
import { PLUGIN_METHODS, setPluginServiceForRpc } from './plugins'
+vi.mock('../../../plugins/plugin-client-list', () => ({
+ listPluginsForClients: vi.fn().mockResolvedValue([])
+}))
+
const SESSION_TOKEN = 's'.repeat(43)
function method(name: string): RpcMethod {
@@ -72,3 +76,98 @@ describe('plugin panel serve RPC identity', () => {
})
})
})
+
+describe('plugin approval over RPC', () => {
+ const worker = {
+ pluginKey: 'acme.worker',
+ rootDir: '/plugins/acme.worker',
+ consentFingerprint: 'sha256-worker',
+ contentHash: `sha256-${'c'.repeat(64)}`,
+ isDev: false,
+ manifest: {
+ id: 'worker',
+ publisher: 'acme',
+ name: 'Worker',
+ version: '2.0.0',
+ execution: 'trusted-worker',
+ main: 'main.mjs',
+ capabilities: [{ kind: 'notifications:show' }],
+ contributes: {
+ panels: [],
+ commands: [],
+ events: [],
+ languagePacks: [],
+ keybindings: [],
+ vmRecipes: [],
+ themes: [],
+ terminalThemes: [],
+ iconThemes: [],
+ syntaxes: [],
+ customEditors: [],
+ newFiles: []
+ }
+ }
+ }
+
+ function setup() {
+ const applyConsent = vi.fn().mockResolvedValue(undefined)
+ const applyEnablement = vi.fn().mockResolvedValue(undefined)
+ const recordApprovalAudit = vi.fn().mockResolvedValue(undefined)
+ const stub = {
+ whenReady: vi.fn().mockResolvedValue(undefined),
+ findValidPlugin: (key: string) => (key === worker.pluginKey ? worker : null),
+ options: { getPluginConsents: () => ({}), getDisabledPlugins: () => [] },
+ recordApprovalAudit,
+ getDiscovered: () => []
+ }
+ // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the approval handlers only read the members stubbed above.
+ setPluginServiceForRpc(stub as unknown as PluginService, { applyConsent, applyEnablement })
+ return { applyConsent, applyEnablement, recordApprovalAudit }
+ }
+
+ const callerContext = (caller: RpcContext['caller']): RpcContext => ({
+ // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: plugin handlers never touch the runtime.
+ runtime: {} as RpcContext['runtime'],
+ caller
+ })
+ const cliContext = () => callerContext({ kind: 'local-cli' })
+
+ it('refuses a consent fingerprint read from plugins.list without the approve flag', async () => {
+ const { applyConsent } = setup()
+ await expect(
+ method('plugins.consent').handler(
+ { pluginKey: 'acme.worker', reviewedFingerprint: 'sha256-worker', decision: 'approve' },
+ cliContext()
+ )
+ ).rejects.toMatchObject({ code: 'approval_required' })
+ expect(applyConsent).not.toHaveBeenCalled()
+ })
+
+ it('refuses enabling code over RPC without the approve flag, even for paired devices', async () => {
+ const { applyConsent, applyEnablement } = setup()
+ await expect(
+ method('plugins.setEnabled').handler(
+ { pluginKey: 'acme.worker', enabled: true },
+ callerContext({ kind: 'paired-device', deviceId: 'd1' })
+ )
+ ).rejects.toMatchObject({ code: 'approval_required' })
+ expect(applyConsent).not.toHaveBeenCalled()
+ expect(applyEnablement).not.toHaveBeenCalled()
+ })
+
+ it('always allows reducing access', async () => {
+ const { applyConsent, applyEnablement } = setup()
+ await method('plugins.setEnabled').handler(
+ { pluginKey: 'acme.worker', enabled: false },
+ cliContext()
+ )
+ await method('plugins.consent').handler(
+ { pluginKey: 'acme.worker', decision: 'keep-disabled' },
+ cliContext()
+ )
+ expect(applyEnablement).toHaveBeenCalledWith('acme.worker', false)
+ expect(applyConsent).toHaveBeenCalledWith(
+ expect.objectContaining({ pluginKey: 'acme.worker', decision: 'keep-disabled' })
+ )
+ })
+})
diff --git a/src/main/runtime/rpc/methods/plugins.ts b/src/main/runtime/rpc/methods/plugins.ts
index f0be67bddc6..9e8f467317b 100644
--- a/src/main/runtime/rpc/methods/plugins.ts
+++ b/src/main/runtime/rpc/methods/plugins.ts
@@ -3,16 +3,19 @@ import type { PluginFrameEntry } from '../../../../shared/plugins/frames/plugin-
import { listPluginsForClients } from '../../../plugins/plugin-client-list'
import type { PluginHostListEntry } from '../../../../shared/plugins/plugin-list-entry'
import type { PluginService } from '../../../plugins/plugin-service'
-import {
- pluginConsentRequestSchema,
- type PluginConsentRequest
-} from '../../../../shared/plugins/approval/plugin-consent-request'
+import type { PluginConsentRequest } from '../../../../shared/plugins/approval/plugin-consent-request'
import {
PluginInvokeCommandParams,
PluginReadPanelEntryParams,
+ PluginRpcConsentParams,
PluginSetEnabledParams,
PluginsPanelActionParams
} from '../../../../shared/rpc-contract/plugins-params'
+import {
+ approvePluginFromCli,
+ pluginCliApprovalRequest
+} from '../../../plugins/plugin-cli-approval'
+import { PluginApprovalRequiredError } from '../../../../shared/plugins/approval/plugin-cli-approval'
/** Expose desktop IPC's plugin consent/actions over serve/headless RPC through the same PluginService permission boundary. */
@@ -42,6 +45,13 @@ function requirePluginService(): PluginService {
return pluginServiceForRpc
}
+function requireConsentWrite(): (request: PluginConsentRequest) => Promise<void> {
+ if (!pluginConsentForRpc) {
+ throw new Error('Plugin consent is not available on this runtime')
+ }
+ return pluginConsentForRpc
+}
+
async function listForRpc(): Promise<PluginHostListEntry[]> {
return listPluginsForClients(requirePluginService())
}
@@ -65,17 +75,39 @@ export const PLUGIN_METHODS = [
handler: async () => listForRpc()
}),
defineMethod({
- // Headless servers have no dialog; only explicit consent can activate a pending plugin.
+ // Why the flag even for paired callers: an agent CLI reaches serve as a paired device too, so
+ // no transport proves a person clicked; only the fingerprint from `approval_required` grants.
name: 'plugins.consent',
permission: 'host-admin',
- params: pluginConsentRequestSchema,
- handler: async (params) => {
+ params: PluginRpcConsentParams,
+ handler: async (params, context) => {
const service = requirePluginService()
await service.whenReady()
- if (!pluginConsentForRpc) {
- throw new Error('Plugin consent is not available on this runtime')
+ const applyConsent = requireConsentWrite()
+ if (params.decision === 'keep-disabled') {
+ await applyConsent({
+ pluginKey: params.pluginKey,
+ reviewedFingerprint: params.reviewedFingerprint ?? '',
+ decision: 'keep-disabled'
+ })
+ return listForRpc()
+ }
+ const plugin = service.findValidPlugin(params.pluginKey)
+ if (
+ plugin &&
+ params.reviewedFingerprint !== undefined &&
+ params.reviewedFingerprint !== plugin.consentFingerprint
+ ) {
+ throw new PluginApprovalRequiredError(pluginCliApprovalRequest(plugin, 'enable'), true)
}
- await pluginConsentForRpc(params)
+ await approvePluginFromCli({
+ service,
+ applyConsent,
+ pluginKey: params.pluginKey,
+ approvalFingerprint: params.approvalFingerprint,
+ action: 'enable',
+ caller: context.caller
+ })
return listForRpc()
}
}),
@@ -83,13 +115,25 @@ export const PLUGIN_METHODS = [
name: 'plugins.setEnabled',
permission: 'host-admin',
params: PluginSetEnabledParams,
- handler: async (params) => {
+ handler: async (params, context) => {
const service = requirePluginService()
await service.whenReady()
if (!pluginEnablementForRpc) {
throw new Error('Plugin enablement is not available on this runtime')
}
- await pluginEnablementForRpc(params.pluginKey, params.enabled)
+ if (!params.enabled) {
+ await pluginEnablementForRpc(params.pluginKey, false)
+ return listForRpc()
+ }
+ // Enabling grants whatever consent is missing, so it goes through the same approve flag.
+ await approvePluginFromCli({
+ service,
+ applyConsent: requireConsentWrite(),
+ pluginKey: params.pluginKey,
+ approvalFingerprint: params.approvalFingerprint,
+ action: 'enable',
+ caller: context.caller
+ })
return listForRpc()
}
}),
diff --git a/src/main/runtime/rpc/rpc-caller-identity.ts b/src/main/runtime/rpc/rpc-caller-identity.ts
index 56fd8ca02d6..11ac7794b9c 100644
--- a/src/main/runtime/rpc/rpc-caller-identity.ts
+++ b/src/main/runtime/rpc/rpc-caller-identity.ts
@@ -11,6 +11,8 @@ export type RpcCallerIdentity =
| { kind: 'paired-device'; deviceId: string }
export const DESKTOP_RPC_CALLER: RpcCallerIdentity = { kind: 'desktop' }
+/** Stamped by the owner-token runtime socket, which only the local `orca` CLI holds. */
+export const LOCAL_CLI_RPC_CALLER: RpcCallerIdentity = { kind: 'local-cli' }
/** The orca CLI agents run, locally or forwarded from a remote host; relayed devices are people. */
export function isAgentRpcCaller(caller: RpcCallerIdentity | undefined): boolean {
@@ -18,7 +20,7 @@ export function isAgentRpcCaller(caller: RpcCallerIdentity | undefined): boolean
}
/** Trust explicit transport identity; unnamed declared clients have none. Temporarily, no declared client means local CLI.
- * SSH CLI bridges/browser automation share that namespace; before plugins ship, require explicit local-cli stamping (plan §4). */
+ * The runtime socket stamps local-cli explicitly; plugin approval never trusts identity alone (it needs the approve fingerprint). */
export function resolveRpcCallerIdentity(
transport:
| Pick<RpcDispatchStreamingOptions, 'caller' | 'clientKind' | 'pairedDeviceId'>
diff --git a/src/main/runtime/runtime-rpc/runtime-rpc-request-admission.ts b/src/main/runtime/runtime-rpc/runtime-rpc-request-admission.ts
index 8c431c6533a..893b2b446b2 100644
--- a/src/main/runtime/runtime-rpc/runtime-rpc-request-admission.ts
+++ b/src/main/runtime/runtime-rpc/runtime-rpc-request-admission.ts
@@ -6,6 +6,7 @@ import { errorResponse } from '../rpc/errors'
import { RuntimeRpcBinaryRouting } from './runtime-rpc-binary-routing'
import { classifyRuntimeLongPoll, type RuntimeLongPollClass } from './runtime-rpc-long-poll'
import { OWNER_RPC_CALLER_SCOPE, type RpcCallerScope } from '../rpc/rpc-caller-scope'
+import { LOCAL_CLI_RPC_CALLER } from '../rpc/rpc-caller-identity'
// Short calls that stop on disconnect without long-poll keepalives or admission slots.
const DISCONNECT_FORWARDED_METHODS = new Set([
@@ -51,6 +52,7 @@ export class RuntimeRpcRequestAdmission extends RuntimeRpcBinaryRouting {
? context?.signal
: undefined,
connectionSignal: context?.signal,
+ caller: LOCAL_CLI_RPC_CALLER,
callerScope
})
} finally {
diff --git a/src/shared/plugins/approval/plugin-cli-approval.ts b/src/shared/plugins/approval/plugin-cli-approval.ts
new file mode 100644
index 00000000000..e86046b7f22
--- /dev/null
+++ b/src/shared/plugins/approval/plugin-cli-approval.ts
@@ -0,0 +1,197 @@
+import { createHash } from 'node:crypto'
+import {
+ canonicalizeCapability,
+ PLUGIN_CAPABILITY_DESCRIPTIONS,
+ type PluginCapability
+} from '../capabilities/plugin-capabilities'
+import {
+ pluginContributionSummary,
+ type PluginContributionSummaryItem
+} from '../contributions/plugin-contribution-summary'
+import {
+ pluginExecutionProfile,
+ type PluginExecutionProfile
+} from '../contributions/plugin-execution-profile'
+import type { PluginManifest } from '../manifest/plugin-manifest'
+
+/** CLI approvals: an explicit `--approve <fingerprint>` bound to the exact bytes and access shown. */
+
+export const PLUGIN_APPROVAL_REQUIRED_CODE = 'approval_required'
+export const PLUGIN_APPROVAL_STALE_CODE = 'approval_stale'
+export const PLUGIN_NOT_FOUND_CODE = 'plugin_not_found'
+/** Codes the runtime passes through to CLI callers with their `data`. */
+export const PLUGIN_CLI_ERROR_CODES = [
+ PLUGIN_APPROVAL_REQUIRED_CODE,
+ PLUGIN_APPROVAL_STALE_CODE,
+ PLUGIN_NOT_FOUND_CODE
+] as const
+
+/** What the caller was doing; install and update reuse the same flag in later commands. */
+export type PluginApprovalAction = 'enable' | 'dev-load' | 'install' | 'update'
+
+export type PluginApprovalGrants = {
+ execution: PluginExecutionProfile
+ executionDescription: string
+ capabilities: { kind: string; description: string }[]
+ contributions: PluginContributionSummaryItem[]
+}
+
+export type PluginApprovalRequest = {
+ pluginKey: string
+ name: string
+ version: string
+ action: PluginApprovalAction
+ approvalFingerprint: string
+ /** Install tree hash, or the development folder's reviewed-content identity. */
+ contentIdentity: string
+ isDev: boolean
+ grants: PluginApprovalGrants
+ why: string
+ /** The flag to add when re-running the same command. */
+ approveFlag: string
+ nextSteps: string[]
+}
+
+type ApprovalSubject = {
+ pluginKey: string
+ manifest: PluginManifest
+ consentFingerprint: string
+ contentIdentity: string
+ isDev: boolean
+}
+
+const EXECUTION_DESCRIPTIONS: Record<PluginExecutionProfile, string> = {
+ data: 'Content only (themes, icons, syntaxes, translations); nothing runs.',
+ declarative:
+ 'Runs Orca actions you could run yourself through the commands, shortcuts or VM recipes it declares.',
+ 'sandboxed-ui':
+ 'Shows its own code in sandboxed panels or editors inside Orca; an editor reads every file it opens.',
+ 'trusted-worker':
+ 'Runs its own code in a separate Node.js process on the Orca host, with your user account’s access to that machine.'
+}
+
+/** Content-only plugins never need the flag; main decides this from the verified manifest. */
+export function pluginNeedsCliApproval(manifest: PluginManifest): boolean {
+ return pluginExecutionProfile(manifest) !== 'data'
+}
+
+export function pluginApprovalGrants(manifest: PluginManifest): PluginApprovalGrants {
+ const execution = pluginExecutionProfile(manifest)
+ return {
+ execution,
+ executionDescription: EXECUTION_DESCRIPTIONS[execution],
+ capabilities: uniqueCapabilities(manifest.capabilities).map((capability) => ({
+ kind: capability.kind,
+ description: PLUGIN_CAPABILITY_DESCRIPTIONS[capability.kind]
+ })),
+ contributions: pluginContributionSummary(manifest)
+ }
+}
+
+function uniqueCapabilities(capabilities: readonly PluginCapability[]): PluginCapability[] {
+ const seen = new Set<string>()
+ return capabilities.filter((capability) => {
+ const key = canonicalizeCapability(capability)
+ if (seen.has(key)) {
+ return false
+ }
+ seen.add(key)
+ return true
+ })
+}
+
+/** Binds key, version, content and every grant shown, so no other plugin, build or access reuses it. */
+export function pluginApprovalFingerprint(subject: ApprovalSubject): string {
+ const grants = pluginApprovalGrants(subject.manifest)
+ const canonical = JSON.stringify([
+ 'orca-plugin-approval-v1',
+ subject.pluginKey,
+ subject.manifest.version,
+ subject.consentFingerprint,
+ subject.contentIdentity,
+ grants.execution,
+ uniqueCapabilities(subject.manifest.capabilities).map(canonicalizeCapability).sort(),
+ grants.contributions.map((item) => [item.kind, item.name, item.detail ?? null])
+ ])
+ return `ap1-${createHash('sha256').update(canonical).digest('hex').slice(0, 32)}`
+}
+
+export function buildPluginApprovalRequest(
+ subject: ApprovalSubject,
+ action: PluginApprovalAction
+): PluginApprovalRequest {
+ const grants = pluginApprovalGrants(subject.manifest)
+ const approvalFingerprint = pluginApprovalFingerprint(subject)
+ const approveFlag = `--approve ${approvalFingerprint}`
+ const devNote = subject.isDev
+ ? ' Later code edits in this development folder run without asking again; new access, a higher execution level, or changed commands and shortcuts need a new approval.'
+ : ''
+ return {
+ pluginKey: subject.pluginKey,
+ name: subject.manifest.name,
+ version: subject.manifest.version,
+ action,
+ approvalFingerprint,
+ contentIdentity: subject.contentIdentity,
+ isDev: subject.isDev,
+ grants,
+ why: `It can run code or act in Orca, so Orca does not enable it without an explicit approval bound to exactly these files and this access.${devNote}`,
+ approveFlag,
+ nextSteps: [
+ 'Approving grants the access listed above. Confirm with your user first unless they already asked for exactly this plugin and access.',
+ `To approve, run the same command again with ${approveFlag}`,
+ 'A different plugin, version, set of files, or more access gets a new fingerprint and needs a new approval.'
+ ]
+ }
+}
+
+/** One message for humans; agents read `data` instead. */
+export function formatPluginApprovalMessage(request: PluginApprovalRequest, stale = false): string {
+ const lead = stale
+ ? `${request.pluginKey} changed since that approval was shown, so the fingerprint no longer matches. Review what it would get now.`
+ : `${request.pluginKey} ${request.version} needs approval before it can run.`
+ const lines = [
+ lead,
+ `Approving ${request.name} (${request.pluginKey} ${request.version}${request.isDev ? ', development folder' : ''}) lets it:`,
+ `- ${request.grants.executionDescription}`,
+ ...request.grants.capabilities.map((capability) => `- ${capability.description}`)
+ ]
+ if (request.grants.contributions.length > 0) {
+ lines.push(
+ `Adds: ${request.grants.contributions.map((item) => `${item.kind} "${item.name}"`).join(', ')}`
+ )
+ }
+ lines.push(
+ `Why approval is needed: ${request.why}`,
+ `Fingerprint: ${request.approvalFingerprint}`
+ )
+ return lines.join('\n')
+}
+
+export class PluginApprovalRequiredError extends Error {
+ readonly code: string
+ readonly data: PluginApprovalRequest
+
+ constructor(request: PluginApprovalRequest, stale = false) {
+ super(formatPluginApprovalMessage(request, stale))
+ this.name = 'PluginApprovalRequiredError'
+ this.code = stale ? PLUGIN_APPROVAL_STALE_CODE : PLUGIN_APPROVAL_REQUIRED_CODE
+ this.data = request
+ }
+}
+
+export class PluginNotFoundError extends Error {
+ readonly code = PLUGIN_NOT_FOUND_CODE
+ readonly data: { pluginKey: string; nextSteps: string[] }
+
+ constructor(pluginKey: string) {
+ super(`No valid plugin ${pluginKey} is loaded on this Orca host.`)
+ this.name = 'PluginNotFoundError'
+ this.data = {
+ pluginKey,
+ nextSteps: [
+ 'Check the plugin key, and that the plugin is installed or loaded on this Orca host.'
+ ]
+ }
+ }
+}
diff --git a/src/shared/rpc-contract/plugins-params.ts b/src/shared/rpc-contract/plugins-params.ts
index 9a8b74a4f3c..bd8297d468b 100644
--- a/src/shared/rpc-contract/plugins-params.ts
+++ b/src/shared/rpc-contract/plugins-params.ts
@@ -1,11 +1,25 @@
import { z } from 'zod'
import { isQualifiedPluginKey } from '../plugins/manifest/plugin-manifest'
+// Why optional: only `approval_required` hands it out; older hosts strip it and older callers omit it.
+const approvalFingerprintParam = z.string().min(1).max(128).optional()
+
export const PluginSetEnabledParams = z.object({
pluginKey: z.string().refine(isQualifiedPluginKey, 'invalid qualified plugin key'),
- enabled: z.boolean()
+ enabled: z.boolean(),
+ approvalFingerprint: approvalFingerprintParam
})
+/** Over RPC, approval needs the explicit CLI fingerprint; the desktop review dialog uses IPC. */
+export const PluginRpcConsentParams = z
+ .object({
+ pluginKey: z.string().min(1),
+ reviewedFingerprint: z.string().min(1).max(256).optional(),
+ decision: z.enum(['approve', 'keep-disabled']),
+ approvalFingerprint: approvalFingerprintParam
+ })
+ .strip()
+
export const PluginReadPanelEntryParams = z.object({
pluginKey: z.string().min(1),
panelId: z.string().min(1)
diff --git a/src/shared/rpc-contract/rpc-params-catalog.generated.ts b/src/shared/rpc-contract/rpc-params-catalog.generated.ts
index 360a6fda6ad..df81d13fe66 100644
--- a/src/shared/rpc-contract/rpc-params-catalog.generated.ts
+++ b/src/shared/rpc-contract/rpc-params-catalog.generated.ts
@@ -42,7 +42,6 @@ import {
OrcadPeerDesktopsParamsSchema
} from '../orcad-peer-desktops-contract'
import { OrcadTerminalCensusParamsSchema } from '../orcad-terminal-census'
-import { pluginConsentRequestSchema } from '../plugins/approval/plugin-consent-request'
import {
AccountsUnsubscribeParams,
AddClaudeFromConfigDirParams,
@@ -496,6 +495,7 @@ import { WorkerDispatchParams as WorkerDispatchParamsOfOrchestrationWorkerStopPa
import {
PluginInvokeCommandParams,
PluginReadPanelEntryParams,
+ PluginRpcConsentParams,
PluginSetEnabledParams,
PluginsPanelActionParams
} from './plugins-params'
@@ -1292,7 +1292,7 @@ export const RPC_PARAMS_BY_METHOD = {
'pairing.getEndpoints': PairingGetEndpointsParamsSchema,
'pairing.provisionRelay': PairingProvisionRelayParamsSchema,
'pairing.registerDeviceKey': RegisterDeviceKeyParamsSchema,
- 'plugins.consent': pluginConsentRequestSchema,
+ 'plugins.consent': PluginRpcConsentParams,
'plugins.invokeCommand': PluginInvokeCommandParams,
'plugins.list': null,
'plugins.panelAction': PluginsPanelActionParams,