* security: add skill/plugin code safety scanner module * security: integrate skill scanner into security audit * security: add pre-install code safety scan for plugins * style: fix curly brace lint errors in skill-scanner.ts * docs: add changelog entry for skill code safety scanner * style: append ellipsis to truncated evidence strings * fix(security): harden plugin code safety scanning * fix: scan skills on install and report code-safety details * fix: dedupe audit-extra import * fix(security): make code safety scan failures observable * fix(test): stabilize smoke + gateway timeouts (#9806) (thanks @abdelsfane) --------- Co-authored-by: Darshil <ddhameliya@mail.sfsu.edu> Co-authored-by: Darshil <81693876+dvrshil@users.noreply.github.com> Co-authored-by: George Pickett <gpickett00@gmail.com>
117 lines
3.3 KiB
TypeScript
117 lines
3.3 KiB
TypeScript
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import type { ExecApprovalsResolved } from "../infra/exec-approvals.js";
|
|
|
|
const previousBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
|
|
|
beforeAll(() => {
|
|
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = path.join(
|
|
os.tmpdir(),
|
|
"openclaw-test-no-bundled-extensions",
|
|
);
|
|
});
|
|
|
|
afterAll(() => {
|
|
if (previousBundledPluginsDir === undefined) {
|
|
delete process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
|
} else {
|
|
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = previousBundledPluginsDir;
|
|
}
|
|
});
|
|
|
|
vi.mock("../infra/shell-env.js", async (importOriginal) => {
|
|
const mod = await importOriginal<typeof import("../infra/shell-env.js")>();
|
|
return {
|
|
...mod,
|
|
getShellPathFromLoginShell: vi.fn(() => "/usr/bin:/bin"),
|
|
resolveShellEnvFallbackTimeoutMs: vi.fn(() => 500),
|
|
};
|
|
});
|
|
|
|
vi.mock("../plugins/tools.js", () => ({
|
|
getPluginToolMeta: () => undefined,
|
|
resolvePluginTools: () => [],
|
|
}));
|
|
|
|
vi.mock("../infra/shell-env.js", async (importOriginal) => {
|
|
const mod = await importOriginal<typeof import("../infra/shell-env.js")>();
|
|
return { ...mod, getShellPathFromLoginShell: () => null };
|
|
});
|
|
|
|
vi.mock("../infra/exec-approvals.js", async (importOriginal) => {
|
|
const mod = await importOriginal<typeof import("../infra/exec-approvals.js")>();
|
|
const approvals: ExecApprovalsResolved = {
|
|
path: "/tmp/exec-approvals.json",
|
|
socketPath: "/tmp/exec-approvals.sock",
|
|
token: "token",
|
|
defaults: {
|
|
security: "allowlist",
|
|
ask: "off",
|
|
askFallback: "deny",
|
|
autoAllowSkills: false,
|
|
},
|
|
agent: {
|
|
security: "allowlist",
|
|
ask: "off",
|
|
askFallback: "deny",
|
|
autoAllowSkills: false,
|
|
},
|
|
allowlist: [],
|
|
file: {
|
|
version: 1,
|
|
socket: { path: "/tmp/exec-approvals.sock", token: "token" },
|
|
defaults: {
|
|
security: "allowlist",
|
|
ask: "off",
|
|
askFallback: "deny",
|
|
autoAllowSkills: false,
|
|
},
|
|
agents: {},
|
|
},
|
|
};
|
|
return { ...mod, resolveExecApprovals: () => approvals };
|
|
});
|
|
|
|
describe("createOpenClawCodingTools safeBins", () => {
|
|
it("threads tools.exec.safeBins into exec allowlist checks", async () => {
|
|
if (process.platform === "win32") {
|
|
return;
|
|
}
|
|
|
|
const { createOpenClawCodingTools } = await import("./pi-tools.js");
|
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-safe-bins-"));
|
|
const cfg: OpenClawConfig = {
|
|
tools: {
|
|
exec: {
|
|
host: "gateway",
|
|
security: "allowlist",
|
|
ask: "off",
|
|
safeBins: ["echo"],
|
|
},
|
|
},
|
|
};
|
|
|
|
const tools = createOpenClawCodingTools({
|
|
config: cfg,
|
|
sessionKey: "agent:main:main",
|
|
workspaceDir: tmpDir,
|
|
agentDir: path.join(tmpDir, "agent"),
|
|
});
|
|
const execTool = tools.find((tool) => tool.name === "exec");
|
|
expect(execTool).toBeDefined();
|
|
|
|
const marker = `safe-bins-${Date.now()}`;
|
|
const result = await execTool!.execute("call1", {
|
|
command: `echo ${marker}`,
|
|
workdir: tmpDir,
|
|
});
|
|
const text = result.content.find((content) => content.type === "text")?.text ?? "";
|
|
|
|
expect(result.details.status).toBe("completed");
|
|
expect(text).toContain(marker);
|
|
});
|
|
});
|