mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-25 14:48:38 +00:00
fix(security): harden hooks module loading
This commit is contained in:
58
src/config/config.hooks-module-paths.test.ts
Normal file
58
src/config/config.hooks-module-paths.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { validateConfigObjectWithPlugins } from "./config.js";
|
||||
|
||||
describe("config hooks module paths", () => {
|
||||
it("rejects absolute hooks.mappings[].transform.module", () => {
|
||||
const res = validateConfigObjectWithPlugins({
|
||||
agents: { list: [{ id: "pi" }] },
|
||||
hooks: {
|
||||
mappings: [
|
||||
{
|
||||
match: { path: "custom" },
|
||||
action: "agent",
|
||||
transform: { module: "/tmp/transform.mjs" },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
if (!res.ok) {
|
||||
expect(res.issues.some((iss) => iss.path === "hooks.mappings.0.transform.module")).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects escaping hooks.mappings[].transform.module", () => {
|
||||
const res = validateConfigObjectWithPlugins({
|
||||
agents: { list: [{ id: "pi" }] },
|
||||
hooks: {
|
||||
mappings: [
|
||||
{
|
||||
match: { path: "custom" },
|
||||
action: "agent",
|
||||
transform: { module: "../escape.mjs" },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
if (!res.ok) {
|
||||
expect(res.issues.some((iss) => iss.path === "hooks.mappings.0.transform.module")).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects absolute hooks.internal.handlers[].module", () => {
|
||||
const res = validateConfigObjectWithPlugins({
|
||||
agents: { list: [{ id: "pi" }] },
|
||||
hooks: {
|
||||
internal: {
|
||||
enabled: true,
|
||||
handlers: [{ event: "command:new", module: "/tmp/handler.mjs" }],
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
if (!res.ok) {
|
||||
expect(res.issues.some((iss) => iss.path === "hooks.internal.handlers.0.module")).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user