From 4721739ee702725abaca88e3ebb1dc9af6fd8288 Mon Sep 17 00:00:00 2001 From: James Russo Date: Tue, 17 Nov 2026 09:26:17 +0000 Subject: [PATCH] fix(producer): readers re-check outside-linked compositions, and the refusal names a step every surface can take (#8034) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../producer/src/services/htmlCompiler.ts | 28 +++++++++++++-- .../src/services/outsideProjectAssets.test.ts | 36 ++++++++++++++++++- .../src/services/render/stages/probeStage.ts | 1 + 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/packages/producer/src/services/htmlCompiler.ts b/packages/producer/src/services/htmlCompiler.ts index e2a97bed1c..e8255e4edc 100644 --- a/packages/producer/src/services/htmlCompiler.ts +++ b/packages/producer/src/services/htmlCompiler.ts @@ -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, probes?: SourceProbes, assetRoot?: string, + outsideFiles: OutsideFilePolicy = {}, compiledSrcs: Set = new Set(), ): Promise<{ subCompositions: Map }> { const subCompositions = new Map(); @@ -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, assetRoot: string | undefined, + outsideFiles: OutsideFilePolicy, ): { html: string; variablesByComp: Record> } { const { document } = parseHTML(html); const head = document.querySelector("head"); @@ -1190,7 +1207,10 @@ function inlineSubCompositions( const readOnce = new Map(); 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 { if (resolutions.length === 0) return compiled; @@ -3141,6 +3164,7 @@ export async function recompileWithResolutions( undefined, undefined, assetRoot, + outsideFiles, ); const { videos, audios, images } = compiled; diff --git a/packages/producer/src/services/outsideProjectAssets.test.ts b/packages/producer/src/services/outsideProjectAssets.test.ts index 6fc28256fd..f08858acb4 100644 --- a/packages/producer/src/services/outsideProjectAssets.test.ts +++ b/packages/producer/src/services/outsideProjectAssets.test.ts @@ -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(); + 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()), 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() { diff --git a/packages/producer/src/services/render/stages/probeStage.ts b/packages/producer/src/services/render/stages/probeStage.ts index 9a0e5bdc18..67ff645062 100644 --- a/packages/producer/src/services/render/stages/probeStage.ts +++ b/packages/producer/src/services/render/stages/probeStage.ts @@ -710,6 +710,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise