refactor: unify boundary hardening for file reads
This commit is contained in:
@@ -651,6 +651,56 @@ describe("loadOpenClawPlugins", () => {
|
||||
expect(registry.diagnostics.some((entry) => entry.message.includes("escapes"))).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects plugin entry files that escape plugin root via hardlink", () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = "/nonexistent/bundled/plugins";
|
||||
const pluginDir = makeTempDir();
|
||||
const outsideDir = makeTempDir();
|
||||
const outsideEntry = path.join(outsideDir, "outside.js");
|
||||
const linkedEntry = path.join(pluginDir, "entry.js");
|
||||
fs.writeFileSync(
|
||||
outsideEntry,
|
||||
'export default { id: "hardlinked", register() { throw new Error("should not run"); } };',
|
||||
"utf-8",
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "openclaw.plugin.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
id: "hardlinked",
|
||||
configSchema: EMPTY_PLUGIN_SCHEMA,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
try {
|
||||
fs.linkSync(outsideEntry, linkedEntry);
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code === "EXDEV") {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
const registry = loadOpenClawPlugins({
|
||||
cache: false,
|
||||
config: {
|
||||
plugins: {
|
||||
load: { paths: [linkedEntry] },
|
||||
allow: ["hardlinked"],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const record = registry.plugins.find((entry) => entry.id === "hardlinked");
|
||||
expect(record?.status).not.toBe("loaded");
|
||||
expect(registry.diagnostics.some((entry) => entry.message.includes("escapes"))).toBe(true);
|
||||
});
|
||||
|
||||
it("prefers dist plugin-sdk alias when loader runs from dist", () => {
|
||||
const root = makeTempDir();
|
||||
const srcFile = path.join(root, "src", "plugin-sdk", "index.ts");
|
||||
|
||||
Reference in New Issue
Block a user