Files
claude-code-conduit/server/actions.mjs
mikael-lovqvists-claude-agent 0568026e7c Validate URL protocol in open-browser action
Parse the URL and reject anything that isn't http/https before passing
to xdg-open, blocking file://, javascript:// and other schemes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 20:36:26 +00:00

71 lines
1.9 KiB
JavaScript

// Action registry — defines all available actions, their parameters, and policies.
// policy: "auto-accept" | "auto-deny" | "queue"
import { resolve_path, exec } from "./helpers.mjs";
export const actions = {
"list-actions": {
description: "List all available actions and their definitions",
params: [],
policy: "auto-accept",
handler: async () => {
return Object.entries(actions).map(([name, def]) => ({
action: name,
description: def.description,
params: def.params,
policy: def.policy,
}));
},
},
"edit-file": {
description: "Open a file in the editor",
params: [{ name: "filename", required: true, type: "path" }],
policy: "auto-accept",
handler: async ({ filename }) => {
const resolved = resolve_path(filename);
await exec('subl3', [resolved]);
return { opened: resolved };
},
},
/*
"open-directory": {
description: "Open a directory in the file manager",
params: [{ name: "path", required: true, type: "path" }],
policy: 'queue',
handler: async ({ path }) => {
const resolved = resolve_path(path);
// await exec( ... );
return { opened: resolved };
},
},
*/
"open-browser": {
description: "Open a URL in the web browser",
params: [{ name: "url", required: true, type: "string" }],
policy: "queue",
handler: async ({ url }) => {
const parsed = new URL(url);
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
throw new Error(`Disallowed protocol: ${parsed.protocol}`);
}
await exec('xdg-open', [parsed.href]);
return { opened: parsed.href };
},
},
"open-terminal": {
description: "Open a terminal in a given directory",
params: [{ name: "path", required: false, type: "path" }],
policy: 'queue',
handler: async ({ path }) => {
const resolved = resolve_path(path ?? 'workspace');
await exec('konsole', ['--workdir', resolved, '-e', 'bash']);
return { opened: resolved };
},
},
};