fix(producer): readers re-check outside-linked compositions, and the refusal names a step every surface can take (#8034)

- parseSubCompositions and the inliner's disk fallback check again right before they
  read a composition, so a file swapped for an outside link after the pre-flight is
  refused too. recompileWithResolutions carries the outside-file policy.
- The refusal says any scripts in the file would run, which holds whether or not it
  has any, and offers moving the file into the project, which Studio and benchmark
  renders can do without the CLI flag.

— Rames

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
James Russo
2026-11-17 09:26:17 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 39347da9de
commit 4721739ee7
3 changed files with 62 additions and 3 deletions
+26 -2
View File
@@ -285,7 +285,7 @@ function resolveCompositionFile(
}
const OUTSIDE_COMPOSITION_NEEDS_FLAG =
"it is outside the project and its scripts would run; pass --include-outside-files to hyperframes render to run it";
"it is outside the project, and any scripts in it would run; move it into the project, or pass --include-outside-files to hyperframes render, to include it";
/** A trusted local render was not told to run markup whose real file is outside the project. */
const runsOutsideMarkupUnasked = (
@@ -296,6 +296,19 @@ const runsOutsideMarkupUnasked = (
): boolean =>
assetRoot === undefined && !outsideFiles.includeScripts && linksOutside(projectDir, filePath);
/** The readers check again, so a file swapped for an outside link after the pre-flight is still refused. */
function assertOutsideMarkupAsked(
projectDir: string,
filePath: string,
srcPath: string,
assetRoot: string | undefined,
outsideFiles: OutsideFilePolicy,
): void {
if (runsOutsideMarkupUnasked(projectDir, filePath, assetRoot, outsideFiles)) {
throw new EmptyCompositionError([{ srcPath, detail: OUTSIDE_COMPOSITION_NEEDS_FLAG }]);
}
}
// Git metadata, env files and the app's `.hyperframes/` records are never inlined into a render, as preview refuses them.
const isPrivateCompositionFile = (projectDir: string, filePath: string): boolean =>
isPrivateFileUnder(projectDir, filePath, isStudioPrivatePath);
@@ -894,6 +907,7 @@ async function parseSubCompositions(
urlByAbsentLocalPath?: ReadonlyMap<string, string>,
probes?: SourceProbes,
assetRoot?: string,
outsideFiles: OutsideFilePolicy = {},
compiledSrcs: Set<string> = new Set(),
): Promise<{ subCompositions: Map<string, string> }> {
const subCompositions = new Map<string, string>();
@@ -924,6 +938,7 @@ async function parseSubCompositions(
if (compiledSrcs.has(srcPath)) continue;
compiledSrcs.add(srcPath);
assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outsideFiles);
assertCompositionFileSize(filePath, srcPath);
const read = readProjectFile(filePath);
if (read.kind !== "file") {
@@ -959,6 +974,7 @@ async function parseSubCompositions(
urlByAbsentLocalPath,
probes,
assetRoot,
outsideFiles,
compiledSrcs,
);
@@ -1167,6 +1183,7 @@ function inlineSubCompositions(
projectDir: string,
variableOverrides: Record<string, unknown>,
assetRoot: string | undefined,
outsideFiles: OutsideFilePolicy,
): { html: string; variablesByComp: Record<string, Record<string, unknown>> } {
const { document } = parseHTML(html);
const head = document.querySelector("head");
@@ -1190,7 +1207,10 @@ function inlineSubCompositions(
const readOnce = new Map<string, string | null>();
const readMountHtml = (srcPath: string): string | null => {
const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
if (filePath) assertCompositionFileSize(filePath, srcPath);
if (filePath) {
assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outsideFiles);
assertCompositionFileSize(filePath, srcPath);
}
const read =
filePath && !isPrivateCompositionFile(projectDir, filePath)
? readProjectFile(filePath)
@@ -2319,6 +2339,7 @@ export async function compileForRender(
options.urlByAbsentLocalPath,
probes,
assetRoot,
outsideFiles,
);
// Ensure the HTML is a full document before inlining sub-compositions.
@@ -2336,6 +2357,7 @@ export async function compileForRender(
projectDir,
options.variables ?? {},
assetRoot,
outsideFiles,
);
// Strip preload="none" from media elements — the renderer needs to load all
@@ -3123,6 +3145,7 @@ export async function recompileWithResolutions(
projectDir: string,
downloadDir: string,
assetRoot?: string,
outsideFiles: OutsideFilePolicy = {},
): Promise<CompiledComposition> {
if (resolutions.length === 0) return compiled;
@@ -3141,6 +3164,7 @@ export async function recompileWithResolutions(
undefined,
undefined,
assetRoot,
outsideFiles,
);
const { videos, audios, images } = compiled;
@@ -49,6 +49,24 @@ vi.mock("node:child_process", async (importOriginal) => {
};
});
// Runs once, right after the named file is read: lets a test change the file between the pre-flight's read and the reader's.
const afterRead = vi.hoisted(() => ({ path: "", run: () => {} }));
vi.mock("@hyperframes/parsers/asset-resolution", async (importOriginal) => {
const actual = await importOriginal<typeof import("@hyperframes/parsers/asset-resolution")>();
return {
...actual,
readProjectFile: (path: string) => {
const read = actual.readProjectFile(path);
if (afterRead.path === path) {
afterRead.path = "";
afterRead.run();
}
return read;
},
};
});
vi.mock("../utils/urlDownloader.js", async (importOriginal) => ({
...(await importOriginal<typeof import("../utils/urlDownloader.js")>()),
downloadToTemp: async (_url: string, destDir: string) => {
@@ -401,7 +419,7 @@ describe.skipIf(!HAS_FFMPEG)("render servers keep markup inside the project", ()
async (link) => {
const { root, projectDir } = symlinkedComposition(link);
const needsFlag =
/outside the project and its scripts would run; pass --include-outside-files/;
/outside the project, and any scripts in it would run; move it into the project, or pass --include-outside-files/;
await expect(compileInProcess(projectDir, true)).rejects.toThrow(needsFlag);
const planDir = join(root, "plan");
await expect(
@@ -412,6 +430,22 @@ describe.skipIf(!HAS_FFMPEG)("render servers keep markup inside the project", ()
expect(result.compiled.html).toContain("OUTSIDE-SCENE");
},
);
it("trusted local renders refuse a scene swapped for an outside link after the pre-flight", async () => {
const { root, projectDir } = symlinkedComposition("scene");
const scenePath = join(projectDir, "scenes", "a.html");
rmSync(scenePath);
writeFileSync(scenePath, scene.replace("OUTSIDE-SCENE", "INSIDE-SCENE"));
afterRead.path = scenePath;
afterRead.run = () => {
rmSync(scenePath);
symlinkSync(join(root, "outside", "scene.html"), scenePath);
};
await expect(compileInProcess(projectDir, true)).rejects.toThrow(
/scenes\/a\.html: it is outside the project, and any scripts in it would run/,
);
expect(afterRead.path).toBe("");
});
});
function outsideScriptsProject() {
@@ -710,6 +710,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageR
projectDir,
join(workDir, "downloads"),
job.config.allowOutsideProjectAssets ? undefined : projectDir,
{ includeScripts: job.config.includeOutsideScripts },
);
assertNotAborted();
// Update composition metadata with re-parsed media