Skip to content

Write HTML. Render video. Built for agents.

fix(core): prevent symlink path traversal in htmlBundler safePath (F-005) (#1214)

Vance Ingallsc09b0b91830f
diff --git a/packages/core/src/compiler/htmlBundler.test.ts b/packages/core/src/compiler/htmlBundler.test.ts
index d28f7622fc..43c2b94caf 100644
--- a/packages/core/src/compiler/htmlBundler.test.ts
+++ b/packages/core/src/compiler/htmlBundler.test.ts
@@ -1,5 +1,5 @@
// @vitest-environment node
-import { mkdtempSync, writeFileSync, mkdirSync, symlinkSync } from "node:fs";
+import { mkdtempSync, writeFileSync, mkdirSync, symlinkSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { parseHTML } from "linkedom";
@@ -53,6 +53,17 @@ function tryCreateSymlink(target: string, path: string, type: "dir" | "file"): b
}
}
+function makeSymlinkProject(
+ projectFiles: Record<string, string>,
+ secretCss: string,
+): { dir: string; outsideDir: string } {
+ const outsideDir = mkdtempSync(join(tmpdir(), "hf-outside-"));
+ writeFileSync(join(outsideDir, "secret.css"), secretCss);
+ const dir = makeTempProject(projectFiles);
+ symlinkSync(join(outsideDir, "secret.css"), join(dir, "evil.css"));
+ return { dir, outsideDir };
+}
+
describe("bundleToSingleHtml", () => {
it("bundles a direct composition entry with paths relative to its file", async () => {
const dir = makeTempProject({
@@ -1389,6 +1400,41 @@ describe("bundleToSingleHtml", () => {
warnSpy.mockRestore();
}
});
+
+ describe("symlink path traversal (security: F-005)", () => {
+ it("does not inline CSS from a symlink pointing outside projectDir", async () => {
+ const { dir, outsideDir } = makeSymlinkProject(
+ {
+ "index.html": `<!doctype html><html><head>
+<link rel="stylesheet" href="evil.css"></head>
+<body><div data-composition-id="root" data-width="320" data-height="180"></div></body></html>`,
+ },
+ ".outside-secret { color: red; }",
+ );
+ try {
+ expect(await bundleToSingleHtml(dir)).not.toContain("outside-secret");
+ } finally {
+ rmSync(outsideDir, { recursive: true, force: true });
+ }
+ });
+
+ it("does not inline CSS via @import through a symlink pointing outside projectDir", async () => {
+ const { dir, outsideDir } = makeSymlinkProject(
+ {
+ "index.html": `<!doctype html><html><head>
+<link rel="stylesheet" href="main.css"></head>
+<body><div data-composition-id="root" data-width="320" data-height="180"></div></body></html>`,
+ "main.css": "@import './evil.css';",
+ },
+ ".import-secret { color: blue; }",
+ );
+ try {
+ expect(await bundleToSingleHtml(dir)).not.toContain("import-secret");
+ } finally {
+ rmSync(outsideDir, { recursive: true, force: true });
+ }
+ });
+ });
});
/**