fix(infra): avoid EISDIR leak to messaging when Read targets directory (Closes #31186)

This commit is contained in:
倪汉杰0668001185
2026-03-02 10:55:36 +08:00
committed by Peter Steinberger
parent 8a4d8c889c
commit 6398a0ba8f
2 changed files with 40 additions and 1 deletions

View File

@@ -73,6 +73,22 @@ describe("fs-safe", () => {
).rejects.toMatchObject({ code: "outside-workspace" });
});
it("rejects directory path within root without leaking EISDIR (issue #31186)", async () => {
const root = await tempDirs.make("openclaw-fs-safe-root-");
await fs.mkdir(path.join(root, "memory"), { recursive: true });
await expect(
openFileWithinRoot({ rootDir: root, relativePath: "memory" }),
).rejects.toMatchObject({ code: expect.stringMatching(/invalid-path|not-file/) });
const err = await openFileWithinRoot({
rootDir: root,
relativePath: "memory",
}).catch((e: unknown) => e);
expect(err).toBeInstanceOf(SafeOpenError);
expect((err as SafeOpenError).message).not.toMatch(/EISDIR/i);
});
it("reads a file within root", async () => {
const root = await tempDirs.make("openclaw-fs-safe-root-");
await fs.writeFile(path.join(root, "inside.txt"), "inside");