fix(producer): trusted renders refuse outside-linked compositions unless --include-outside-files (#8024)

* fix(producer): trusted renders refuse outside-linked compositions unless --include-outside-files

A sub-composition or entry file whose real file is outside the project is
inlined into the render page, so its scripts run even though outside .js files
are left out without the flag. The pre-flight now refuses it with a message
naming --include-outside-files.

— Rames

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(cli): read the linked outside scene with --include-outside-files in the received-render parity test

The parity test checks that the render compiler reaches an outside file through a
scene in a linked folder outside the project. Trusted renders now refuse that scene
unless --include-outside-files is passed, so the helper passes it.

— Rames

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
James Russo
2026-11-17 04:58:50 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 9fae4ffd81
commit 00d03a4122
3 changed files with 46 additions and 6 deletions
@@ -583,9 +583,11 @@ describe("outsideAssetsAllowed", () => {
expect(line).toContain("scene.html is another name for a file that came from someone else");
});
// With --include-outside-files, so a scene in a linked folder outside the project is read too.
async function compiledPage(dir: string) {
const compiled = await compileForRender(dir, join(dir, "index.html"), join(dir, ".dl"), {
allowOutsideProjectAssets: true,
includeOutsideScripts: true,
});
const rendered = [compiled.html, ...compiled.subCompositions.values()].join("\n");
return { rendered, outside: [...compiled.externalAssets.values()] };
+27 -2
View File
@@ -100,6 +100,7 @@ import {
resolveCompositionSrc,
} from "@hyperframes/parsers/asset-resolution";
import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
import { linksOutside } from "@hyperframes/studio-server/outside-file";
import { extractMediaMetadata, extractAudioMetadata } from "../utils/ffprobe.js";
import { assertCompositionFileSize } from "./compositionSizeLimit.js";
import {
@@ -283,6 +284,18 @@ function resolveCompositionFile(
return file !== null && COMPOSITION_FILE.test(file) ? file : null;
}
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";
/** A trusted local render was not told to run markup whose real file is outside the project. */
const runsOutsideMarkupUnasked = (
projectDir: string,
filePath: string,
assetRoot: string | undefined,
outsideFiles: OutsideFilePolicy,
): boolean =>
assetRoot === undefined && !outsideFiles.includeScripts && linksOutside(projectDir, filePath);
// 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);
@@ -306,6 +319,7 @@ function assertSubCompositionsUsable(
html: string,
projectDir: string,
assetRoot: string | undefined,
outsideFiles: OutsideFilePolicy,
visited: Set<string> = new Set(),
): void {
const { document } = parseHTML(html);
@@ -326,6 +340,10 @@ function assertSubCompositionsUsable(
problems.push({ srcPath, detail: "it is outside the project in a private location" });
continue;
}
if (runsOutsideMarkupUnasked(projectDir, filePath, assetRoot, outsideFiles)) {
problems.push({ srcPath, detail: OUTSIDE_COMPOSITION_NEEDS_FLAG });
continue;
}
if (isPrivateCompositionFile(projectDir, filePath)) {
problems.push({
srcPath,
@@ -376,7 +394,7 @@ function assertSubCompositionsUsable(
const nestedVisited = new Set(visited);
nestedVisited.add(filePath);
try {
assertSubCompositionsUsable(fileHtml, projectDir, assetRoot, nestedVisited);
assertSubCompositionsUsable(fileHtml, projectDir, assetRoot, outsideFiles, nestedVisited);
} catch (err) {
if (err instanceof EmptyCompositionError) {
problems.push(...err.problems);
@@ -2218,9 +2236,16 @@ export async function compileForRender(
options: CompileForRenderOptions = {},
): Promise<CompiledComposition> {
const assetRoot = options.allowOutsideProjectAssets ? undefined : projectDir;
const outsideFiles: OutsideFilePolicy = { includeScripts: options.includeOutsideScripts };
if (isPathInside(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
throw new Error(`Entry file ${htmlPath} leads outside the project folder`);
}
if (
isPathInside(htmlPath, projectDir) &&
runsOutsideMarkupUnasked(projectDir, htmlPath, assetRoot, outsideFiles)
) {
throw new Error(`Entry file ${htmlPath} ${OUTSIDE_COMPOSITION_NEEDS_FLAG}`);
}
if (!COMPOSITION_FILE.test(htmlPath)) {
throw new Error(`Entry file ${htmlPath} is not an .html file, so it is refused`);
}
@@ -2237,7 +2262,7 @@ export async function compileForRender(
// unconditional (not gated behind --strict like lint warnings) — a render
// that silently drops a scene is strictly worse than one that refuses to
// start.
assertSubCompositionsUsable(rawHtml, projectDir, assetRoot);
assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
const probes: SourceProbes = new Map();
const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
@@ -394,11 +394,24 @@ describe.skipIf(!HAS_FFMPEG)("render servers keep markup inside the project", ()
await plan(projectDir, config, planDir, { allowOutsideProjectAssets: true });
expect(existsSync(join(planDir, "compiled", secretKey))).toBe(true);
expect(existsSync(join(planDir, "compiled", "link.png"))).toBe(true);
const linked = symlinkedComposition("scene");
const { result } = await compileInProcess(linked.projectDir, true);
expect(result.compiled.html).toContain("OUTSIDE-SCENE");
});
it.each(["scene", "entry"] as const)(
"trusted local renders refuse a symlinked %s outside the project unless told to run it",
async (link) => {
const { root, projectDir } = symlinkedComposition(link);
const needsFlag =
/outside the project and its scripts would run; pass --include-outside-files/;
await expect(compileInProcess(projectDir, true)).rejects.toThrow(needsFlag);
const planDir = join(root, "plan");
await expect(
plan(projectDir, config, planDir, { allowOutsideProjectAssets: true }),
).rejects.toThrow(needsFlag);
const { result } = await compileInProcess(projectDir, true, true);
expect(result.compiled.html).toContain("OUTSIDE-SCENE");
},
);
});
function outsideScriptsProject() {