fix: harden sandbox media reads against TOCTOU escapes

This commit is contained in:
Peter Steinberger
2026-03-02 01:03:40 +00:00
parent 4320cde91d
commit c823a85302
12 changed files with 223 additions and 27 deletions

View File

@@ -0,0 +1,22 @@
import { describe, expect, it, vi } from "vitest";
import { createSandboxBridgeReadFile } from "./sandbox-media-paths.js";
import type { SandboxFsBridge } from "./sandbox/fs-bridge.js";
describe("createSandboxBridgeReadFile", () => {
it("delegates reads through the sandbox bridge with sandbox root cwd", async () => {
const readFile = vi.fn(async () => Buffer.from("ok"));
const scopedRead = createSandboxBridgeReadFile({
sandbox: {
root: "/tmp/sandbox-root",
bridge: {
readFile,
} as unknown as SandboxFsBridge,
},
});
await expect(scopedRead("media/inbound/example.png")).resolves.toEqual(Buffer.from("ok"));
expect(readFile).toHaveBeenCalledWith({
filePath: "media/inbound/example.png",
cwd: "/tmp/sandbox-root",
});
});
});