fix(producer): a private project file stays private under any path spelling (#8786)

* fix(producer): a private project file stays private under any path spelling

A local render that brings in outside files read a media path spelled
outside the project, but resolving to a private project file, as an
ordinary outside file. isPrivateUnderAssetRoots can now also pick a
root by the real file, and the render callers ask for that when outside
files are allowed. The default still never looks at a file spelled
outside the project.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(engine): leave a path on another network root unread when judging private files

The real-path lookup added for renders that bring in outside files ran before the
network-root refusal in the duration probe. The lookup now answers no for such a
path without looking at it, so every caller keeps the order.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(producer): a private project file is not copied in under another path spelling

The outside-asset collector asked only whether a path's real file leaves the
project, so a private project file named by a path spelled outside the project
was copied into the compiled output. The refusal every collector passes through
now answers for that case too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(engine): a media source that is no file is not looked up as one

With outside files allowed, a long inline data source reached the real-path
lookup, which walks one folder per slash when the path does not exist and ran
out of stack. The lookup now runs only for a path that exists.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
James Russo
2026-11-25 02:38:29 +00:00
committed by GitHub
co-authored by Claude Fable 5.2
parent c7e19fdd24
commit ff34919fb2
10 changed files with 197 additions and 11 deletions
@@ -36,6 +36,26 @@ describe("isPrivateUnderAssetRoots", () => {
expect(isPrivateUnderAssetRoots(link, roots)).toBe(true);
});
it("refuses a private project file named through a link outside the project, when asked to follow it", () => {
const alias = join(root, "alias");
symlinkSync(projectDir, alias);
const named = join(alias, ".git", "objects", "clip.mp4");
file(".git/objects/clip.mp4");
expect(isPrivateUnderAssetRoots(named, roots)).toBe(false);
expect(isPrivateUnderAssetRoots(named, roots, true)).toBe(true);
expect(
isPrivateUnderAssetRoots(
join(alias, file("media/clip.mp4").slice(projectDir.length)),
roots,
true,
),
).toBe(false);
const outside = join(root, ".ssh", "clip.mp4");
mkdirSync(dirname(outside), { recursive: true });
writeFileSync(outside, "x");
expect(isPrivateUnderAssetRoots(outside, roots, true)).toBe(false);
});
it("keeps project media and the render's own files inside .hyperframes", () => {
expect(isPrivateUnderAssetRoots(file("media/clip.mp4"), roots)).toBe(false);
expect(assetRootsRefusal(file("media/clip.mp4"), roots)).toBeNull();
+26 -4
View File
@@ -1,6 +1,15 @@
import { existsSync } from "node:fs";
import { isPrivateFileUnder, isSafePath, isStudioPrivatePath } from "@hyperframes/core/safe-path";
import { isWithinProjectRoot } from "@hyperframes/parsers/asset-resolution";
import {
isPrivateFileUnder,
isSafePath,
isStudioPrivatePath,
realFilePath,
realPathWithin,
} from "@hyperframes/core/safe-path";
import {
isWithinProjectRoot,
namesAnotherNetworkRoot,
} from "@hyperframes/parsers/asset-resolution";
export function isInsideAssetRoots(path: string, roots: readonly string[]): boolean {
if (roots.some((root) => isSafePath(root, path))) return true;
@@ -8,9 +17,22 @@ export function isInsideAssetRoots(path: string, roots: readonly string[]): bool
return roots.some((root) => isWithinProjectRoot(root, path)) && !existsSync(path);
}
const existingFileWithinUnlessOnAnotherNetworkRoot = (root: string, path: string): boolean =>
!namesAnotherNetworkRoot(root, path) &&
existsSync(path) &&
realPathWithin(realFilePath(root), realFilePath(path));
// Judged from every root holding it, since a render's own work folder may sit in the project's `.hyperframes/`.
export function isPrivateUnderAssetRoots(path: string, roots: readonly string[]): boolean {
const holders = roots.filter((root) => isSafePath(root, path));
export function isPrivateUnderAssetRoots(
path: string,
roots: readonly string[],
bySpellingOrRealFile = false,
): boolean {
const holders = roots.filter(
(root) =>
isSafePath(root, path) ||
(bySpellingOrRealFile && existingFileWithinUnlessOnAnotherNetworkRoot(root, path)),
);
return (
holders.length > 0 &&
holders.every((root) => isPrivateFileUnder(root, path, isStudioPrivatePath))
@@ -0,0 +1,42 @@
import { fileURLToPath } from "node:url";
import { describe, expect, it, vi } from "vitest";
const looked = vi.hoisted(() => ({ at: [] as string[] }));
vi.mock("@hyperframes/parsers/asset-resolution", async (original) => ({
...(await original<typeof import("@hyperframes/parsers/asset-resolution")>()),
// POSIX has no second network root, so the answer Windows gives for `\\server\share` is stood in here.
namesAnotherNetworkRoot: (_base: string, target: string) => target.startsWith("/share/"),
}));
vi.mock("@hyperframes/core/safe-path", async (original) => {
const actual = await original<typeof import("@hyperframes/core/safe-path")>();
return {
...actual,
realFilePath: (path: string) => {
looked.at.push(path);
return actual.realFilePath(path);
},
};
});
const { isPrivateUnderAssetRoots } = await import("./assetRoots.js");
describe("isPrivateUnderAssetRoots on another network root", () => {
it("answers without looking at the file", () => {
expect(isPrivateUnderAssetRoots("/share/.git/clip.mp4", ["/project"], true)).toBe(false);
expect(looked.at).toEqual([]);
});
it("still looks at a file on this machine when asked to", () => {
const file = fileURLToPath(import.meta.url);
expect(isPrivateUnderAssetRoots(file, ["/project"], true)).toBe(false);
expect(looked.at).toContain(file);
});
it("does not look at a name that is no file", () => {
looked.at.length = 0;
const inline = `/project/data:video/mp4;base64,${"A/".repeat(20_000)}`;
expect(isPrivateUnderAssetRoots(inline, ["/project", "/work"], true)).toBe(false);
expect(looked.at).toEqual([]);
});
});
@@ -5,6 +5,7 @@ import {
mkdtempSync,
readdirSync,
rmSync,
symlinkSync,
truncateSync,
writeFileSync,
} from "node:fs";
@@ -151,6 +152,25 @@ describe("prepareAnimatedGifInputs", () => {
},
);
it("never resolves a private project file named by a path spelled outside the project", () => {
const projectDir = makeProject();
const alias = `${projectDir}-alias`;
try {
symlinkSync(projectDir, alias);
for (const folder of [".git", "media"]) {
mkdirSync(join(projectDir, folder), { recursive: true });
writeFileSync(join(projectDir, folder, "sticker.gif"), gif([...frame(5), ...frame(15)], 0));
}
const options = { projectDir, downloadDir: projectDir, allowOutsideFiles: true };
const named = (folder: string) => join(alias, folder, "sticker.gif");
expect(resolveLocalImageSourcePath(named(".git"), options)).toBeNull();
expect(resolveLocalImageSourcePath(named("media"), options)).toBe(named("media"));
} finally {
rmSync(alias, { force: true });
rmSync(projectDir, { recursive: true, force: true });
}
});
it("does not cache a transcode that ffmpeg cut off at its output size limit", async () => {
const projectDir = makeProject();
try {
@@ -115,7 +115,11 @@ export function resolveLocalImageSourcePath(
const assetRoot = options.allowOutsideFiles ? undefined : options.projectDir;
const allowed = (candidate: string) =>
!namesAnotherNetworkRoot(options.projectDir, candidate) &&
!isPrivateUnderAssetRoots(candidate, [options.projectDir, options.downloadDir]) &&
!isPrivateUnderAssetRoots(
candidate,
[options.projectDir, options.downloadDir],
options.allowOutsideFiles,
) &&
((!escapesAssetRoot(candidate, assetRoot) &&
outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted") ||
!escapesAssetRoot(candidate, options.downloadDir));
@@ -373,6 +373,25 @@ describe("dropMediaOutsideProject", () => {
},
);
it("drops a private project file named by a path spelled outside the project", () => {
for (const rel of [".git/clip.mp4", "media/clip.mp4"]) {
mkdirSync(dirname(join(projectDir, rel)), { recursive: true });
writeFileSync(join(projectDir, rel), "x");
}
const alias = join(root, "alias");
rmSync(alias, { force: true });
symlinkSync(projectDir, alias);
const srcs: Record<string, string> = {
link: join(alias, ".git", "clip.mp4"),
local: join(alias, "media", "clip.mp4"),
};
// Another letter case names the same folder only where the volume folds case.
const upper = join(root, "PROJECT");
if (existsSync(upper)) srcs.letterCase = join(upper, ".git", "clip.mp4");
expect(keptVideos(srcs, true)).toEqual(["local"]);
expect(keptVideos(srcs)).toEqual([]);
});
it("drops a URL scheme followed by parent folders, in any letter case", () => {
const schemes = ["data:", "DATA:", "blob:", "Blob:", "about:", "https:", "HTTP:"];
const srcs = Object.fromEntries(
@@ -391,4 +410,10 @@ describe("dropMediaOutsideProject", () => {
};
expect(keptVideos(srcs)).toEqual(Object.keys(srcs));
});
it("keeps long inline media when outside files are allowed, without walking its text as folders", () => {
// A regression test: each `/` in the base64 text was walked as a folder, and thousands of them overflowed the stack.
const srcs = { long: `data:video/mp4;base64,${"A/".repeat(20_000)}`, local: "clip.mp4" };
expect(keptVideos(srcs, true)).toEqual(Object.keys(srcs));
});
});
@@ -114,7 +114,7 @@ export function dropMediaOutsideProject(input: {
const staysInside = ({ id, src }: { id: string; src: string }) => {
if (!src || isHttpUrl(src)) return true;
const path = resolveProjectRelativeSrc(src, projectDir, compiledDir);
if (isPrivateUnderAssetRoots(path, roots)) {
if (isPrivateUnderAssetRoots(path, roots, input.allowOutsideProjectAssets)) {
log.warn(`[Render] Media "${id}" source is missing: it is a private project file`, { src });
return false;
}
@@ -1,7 +1,15 @@
// fallow-ignore-file code-duplication
import { afterEach, beforeAll, beforeEach, describe, expect, it, mock } from "bun:test";
import { createHash } from "node:crypto";
import { mkdtempSync, writeFileSync, mkdirSync, rmSync, readFileSync, readdirSync } from "node:fs";
import {
mkdtempSync,
writeFileSync,
mkdirSync,
rmSync,
readFileSync,
readdirSync,
symlinkSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { runInThisContext } from "node:vm";
@@ -295,6 +303,20 @@ describe("collectExternalAssets", () => {
expect(result.html).toBe(html); // unchanged
});
it("leaves out a private project file named by a path spelled outside the project", () => {
const alias = `${projectDir}-alias`;
symlinkSync(projectDir, alias);
mkdirSync(join(projectDir, ".git"), { recursive: true });
writeFileSync(join(projectDir, ".git", "clip.png"), "fake-private");
const warnings: string[] = [];
const log = { ...defaultLogger, warn: (message: string) => warnings.push(message) };
const html = `<html><body><img src="../project-alias/.git/clip.png"><img src="../project-alias/logo.png"></body></html>`;
const result = collectExternalAssets(html, projectDir, log);
rmSync(alias, { force: true });
expect([...result.externalAssets.values()]).toEqual([join(alias, "logo.png")]);
expect(warnings).toHaveLength(1);
});
it("collects and rewrites assets outside projectDir via src attribute", () => {
const html = `<html><body><img src="../external/hero.png"></body></html>`;
const result = collectExternalAssets(html, projectDir);
@@ -3583,6 +3605,33 @@ describe("compileForRender non-media payload sniff (STUDIO-5433)", () => {
rmSync(projectDir, { recursive: true, force: true });
},
);
it("never probes a private project file named by a path spelled outside the project", async () => {
const projectDir = writeProject("<!--media-->");
const alias = `${projectDir}-alias`;
symlinkSync(projectDir, alias);
const src = join(alias, ".git", "clip.mp4");
writeFileSync(
join(projectDir, "index.html"),
readFileSync(join(projectDir, "index.html"), "utf8").replace(
"<!--media-->",
`<video id="v1" src="${src}" data-start="0" muted></video>`,
),
);
mkdirSync(join(projectDir, ".git"), { recursive: true });
writeFileSync(src, readFileSync(join(projectDir, "assets", "nested.html")));
const warnings: string[] = [];
const log = { ...defaultLogger, warn: (message: string) => warnings.push(message) };
await compileForRender(projectDir, join(projectDir, "index.html"), projectDir, {
log,
allowOutsideProjectAssets: true,
});
expect(warnings.join("\n")).not.toContain("text document");
rmSync(alias, { force: true });
rmSync(projectDir, { recursive: true, force: true });
});
});
describe("duplicate media ids across nested compositions", () => {
@@ -836,7 +836,7 @@ async function resolveMediaDuration(
if (!filePath.startsWith("/")) filePath = join(baseDir, filePath);
if (
escapesAssetRoot(filePath, assetRoot) ||
isPrivateUnderAssetRoots(filePath, [projectDir, downloadDir])
isPrivateUnderAssetRoots(filePath, [projectDir, downloadDir], assetRoot === undefined)
) {
return { duration: null, resolvedPath: filePath };
}
@@ -3007,7 +3007,7 @@ async function compileWithAssets(
namesAnotherNetworkRoot(projectDir, videoPath) ||
!existsSync(videoPath) ||
escapesAssetRoot(videoPath, assetRoot) ||
isPrivateUnderAssetRoots(videoPath, [projectDir, downloadDir])
isPrivateUnderAssetRoots(videoPath, [projectDir, downloadDir], assetRoot === undefined)
)
continue;
advised.add(videoPath);
+6 -2
View File
@@ -12,7 +12,7 @@ import {
} from "node:path";
import { statSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { isSafePath } from "@hyperframes/core/safe-path";
import { isPrivateFileUnder, isSafePath, isStudioPrivatePath } from "@hyperframes/core/safe-path";
import {
isCopiedOutsideFileType,
isPrivateOutsideFile,
@@ -92,7 +92,11 @@ export function outsideAssetRefusal(
path: string,
policy: OutsideFilePolicy = {},
): LeftOutReason | null {
if (!linksOutside(projectDir, path)) return null;
if (!linksOutside(projectDir, path)) {
const privateByAnotherSpelling =
!isPathInside(path, projectDir) && isPrivateFileUnder(projectDir, path, isStudioPrivatePath);
return privateByAnotherSpelling ? "blocklisted" : null;
}
if (isPrivateOutsideFile(projectDir, path)) return "blocklisted";
const folder = statSync(path, { throwIfNoEntry: false })?.isDirectory();
if (folder || isUploadedOutsideFileType(path)) return null;