mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(producer): local renders leave out scripts from outside the project unless included (#7998)
A local render brought in .js and .mjs files that markup or a project link reached outside the project, so an imported composition could copy a script from elsewhere on disk into the page it runs and read it. Images, video, audio, fonts and CSS still come in. Scripts are left out with a warning that names each one and how to include it: move it into the project, or pass the new --include-outside-files to hyperframes render. The policy covers the compiler's outside-asset copy, the file server's linked files and the distributed plan's project copy. — Rames Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
02c1fb48e7
commit
581a43bb6a
@@ -1953,11 +1953,19 @@ How it uses the machine, and when it gives up:
|
||||
| `--wait` / `--no-wait` | on | One local render at a time per user account: wait while another runs, or fail at once. Env: `HYPERFRAMES_RENDER_LOCK=off` renders side by side. |
|
||||
| `--strict` / `--strict-all` | off | Fail on lint errors, or on errors and warnings |
|
||||
| `--strict-variables` | off | Fail rather than warn on an undeclared or mistyped variable key |
|
||||
| `--include-outside-files` | off | Also run `.js` and `.mjs` scripts the project references from outside its folder. See the note below. |
|
||||
| `--batch-concurrency` / `--batch-fail-fast` | `1` / off | Batch rows at once, and whether the first failure stops the rest |
|
||||
| `--debug` | off | Keep intermediates and write diagnostics under the Producer `.debug` directory |
|
||||
| `--quiet` | off | Less output |
|
||||
| `--skill` | — | Record which authoring workflow started this render, in usage telemetry |
|
||||
|
||||
A local render brings in images, video, audio, fonts and CSS that the project
|
||||
references from outside its folder. It leaves out scripts from outside the
|
||||
folder, warning with each one's name, because a script runs in the render's
|
||||
browser and can read and send anything the render can reach. Move a script you
|
||||
trust into the project, or pass `--include-outside-files` to run it where it is.
|
||||
A composition that needs the left-out script stops with a script-load error.
|
||||
|
||||
Renders started side by side starve each other of CPU and GPU until frames stop
|
||||
landing, so a second local or `--docker` render from the same user account waits
|
||||
for the first and says which render it is waiting for (pid and project). The
|
||||
|
||||
@@ -348,6 +348,13 @@ export default defineCommand({
|
||||
description: "Fail render on lint errors",
|
||||
default: false,
|
||||
},
|
||||
"include-outside-files": {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Also run .js and .mjs scripts the project references from outside its folder. Without it they are left out " +
|
||||
"with a warning; images, video, audio, fonts and CSS outside the folder are always included.",
|
||||
default: false,
|
||||
},
|
||||
"strict-all": {
|
||||
type: "boolean",
|
||||
description: "Fail render on lint errors AND warnings",
|
||||
@@ -585,6 +592,8 @@ export interface RenderOptions {
|
||||
/** Segmented capture: keep the segment directory after success. */
|
||||
keepSegments?: boolean;
|
||||
bestEffort?: boolean;
|
||||
/** --include-outside-files: run scripts the project references from outside its folder. */
|
||||
includeOutsideScripts?: boolean;
|
||||
browserPath?: string;
|
||||
variables?: Record<string, unknown>;
|
||||
entryFile?: string;
|
||||
@@ -1155,6 +1164,7 @@ async function executeLocalRender(
|
||||
const allowOutsideProjectAssets = outsideAssetsAllowed(projectDir, options.entryFile, (line) =>
|
||||
console.warn(c.warn(` ${line}`)),
|
||||
);
|
||||
const includeOutsideScripts = options.includeOutsideScripts === true;
|
||||
const deParallelRouterActive =
|
||||
options.manageDeParallelRouterBreaker === true
|
||||
? applyDeParallelRouterCircuitBreaker(options.quiet)
|
||||
@@ -1235,10 +1245,15 @@ async function executeLocalRender(
|
||||
cpu,
|
||||
signal: cancellation.signal,
|
||||
allowOutsideProjectAssets,
|
||||
includeOutsideScripts,
|
||||
});
|
||||
}
|
||||
const job = producer.createRenderJob(
|
||||
producer.renderConfigFromRequest(request, { logger, allowOutsideProjectAssets }),
|
||||
producer.renderConfigFromRequest(request, {
|
||||
logger,
|
||||
allowOutsideProjectAssets,
|
||||
includeOutsideScripts,
|
||||
}),
|
||||
);
|
||||
|
||||
const onProgress = options.quiet
|
||||
@@ -1357,6 +1372,7 @@ async function renderRange(input: {
|
||||
cpu: RenderCpuSampler;
|
||||
signal: AbortSignal;
|
||||
allowOutsideProjectAssets: boolean;
|
||||
includeOutsideScripts: boolean;
|
||||
}): Promise<SingleRenderResult> {
|
||||
const { producer, options } = input;
|
||||
let framesEncoded = 0;
|
||||
@@ -1371,7 +1387,10 @@ async function renderRange(input: {
|
||||
config,
|
||||
input.range,
|
||||
input.outputPath,
|
||||
{ allowOutsideProjectAssets: input.allowOutsideProjectAssets },
|
||||
{
|
||||
allowOutsideProjectAssets: input.allowOutsideProjectAssets,
|
||||
includeOutsideScripts: input.includeOutsideScripts,
|
||||
},
|
||||
);
|
||||
framesEncoded = spanResult.framesEncoded;
|
||||
reference = producer.referenceBackgroundResult(spanResult[producer.REFERENCE_BACKGROUND_FIELD]);
|
||||
|
||||
@@ -206,6 +206,7 @@ export function renderOptionsFromPlan(
|
||||
resumeSegments: plan.resumeSegments,
|
||||
keepSegments: plan.keepSegments,
|
||||
bestEffort: plan.bestEffort,
|
||||
includeOutsideScripts: plan.includeOutsideScripts,
|
||||
variables,
|
||||
entryFile: plan.entryFile,
|
||||
outputResolution: plan.outputResolution,
|
||||
@@ -425,6 +426,7 @@ export function batchRowRenderOptions(
|
||||
resumeSegments: plan.resumeSegments,
|
||||
keepSegments: plan.keepSegments,
|
||||
bestEffort: plan.bestEffort,
|
||||
includeOutsideScripts: plan.includeOutsideScripts,
|
||||
exitAfterComplete: false,
|
||||
throwOnError: true,
|
||||
skipFeedback: true,
|
||||
|
||||
@@ -127,6 +127,12 @@ describe("createRenderPlan", () => {
|
||||
expect(plan.bestEffort).toBe(false);
|
||||
});
|
||||
|
||||
it("runs outside scripts only with --include-outside-files", () => {
|
||||
expect(createRenderPlan({ dir: projectDir }).includeOutsideScripts).toBe(false);
|
||||
const included = createRenderPlan({ dir: projectDir, "include-outside-files": true });
|
||||
expect(included.includeOutsideScripts).toBe(true);
|
||||
});
|
||||
|
||||
it.each([undefined, "off"])("preserves page motion blur override %s", (value) => {
|
||||
expect(createRenderPlan({ dir: projectDir, "page-motion-blur": value }).pageMotionBlur).toBe(
|
||||
value,
|
||||
|
||||
@@ -104,6 +104,7 @@ export interface RenderCommandArgs {
|
||||
wait?: boolean;
|
||||
strict?: boolean;
|
||||
"strict-all"?: boolean;
|
||||
"include-outside-files"?: boolean;
|
||||
"lint-verbose"?: boolean;
|
||||
"max-concurrent-renders"?: string;
|
||||
variables?: string;
|
||||
@@ -168,6 +169,7 @@ export interface RenderPlan {
|
||||
/** Segmented capture: keep the segment directory after success. */
|
||||
keepSegments: boolean;
|
||||
bestEffort: boolean;
|
||||
includeOutsideScripts: boolean;
|
||||
waitForRenderSlot: boolean;
|
||||
batchJson: boolean;
|
||||
effectiveQuiet: boolean;
|
||||
@@ -671,6 +673,7 @@ export function createRenderPlan(args: RenderCommandArgs, now = new Date()): Ren
|
||||
resumeSegments: args.resume ?? false,
|
||||
keepSegments: args["keep-segments"] ?? false,
|
||||
bestEffort: args["best-effort"] ?? true,
|
||||
includeOutsideScripts: args["include-outside-files"] ?? false,
|
||||
waitForRenderSlot: args.wait ?? true,
|
||||
batchJson,
|
||||
effectiveQuiet: quiet || batchJson,
|
||||
|
||||
@@ -860,7 +860,7 @@ function composeNamesInText(fileContents: Map<string, StagedFile>, filePaths: st
|
||||
}
|
||||
}
|
||||
|
||||
type WalkedLeftOutReason = Exclude<LeftOutReason, "file_type" | "network_share">;
|
||||
type WalkedLeftOutReason = Exclude<LeftOutReason, "file_type" | "network_share" | "script">;
|
||||
|
||||
const WALKED_LEFT_OUT: Record<WalkedLeftOutReason, string> = {
|
||||
private:
|
||||
|
||||
@@ -285,7 +285,11 @@ export function createRenderRequest(input: CreateRenderRequestInput): RenderRequ
|
||||
|
||||
export function renderConfigFromRequest(
|
||||
request: RenderRequest,
|
||||
runtime: { logger?: ProducerLogger; allowOutsideProjectAssets?: boolean } = {},
|
||||
runtime: {
|
||||
logger?: ProducerLogger;
|
||||
allowOutsideProjectAssets?: boolean;
|
||||
includeOutsideScripts?: boolean;
|
||||
} = {},
|
||||
): RenderConfig {
|
||||
const { engineConfig, distributed: _distributed, ...options } = request.options;
|
||||
return {
|
||||
@@ -293,6 +297,7 @@ export function renderConfigFromRequest(
|
||||
producerConfig: engineConfig,
|
||||
logger: runtime.logger,
|
||||
allowOutsideProjectAssets: runtime.allowOutsideProjectAssets === true,
|
||||
includeOutsideScripts: runtime.includeOutsideScripts === true,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -358,6 +358,7 @@ export interface BuildLocalExecutionPlanOptions {
|
||||
readonly deferAudio?: boolean;
|
||||
/** Trusted local callers only; see CompileForRenderOptions. Never read from config. */
|
||||
readonly allowOutsideProjectAssets?: boolean;
|
||||
readonly includeOutsideScripts?: boolean;
|
||||
}
|
||||
|
||||
export interface RemoteProjectFile {
|
||||
@@ -1202,7 +1203,10 @@ async function compilePlanComposition(
|
||||
planDir: string,
|
||||
options: Pick<
|
||||
BuildLocalExecutionPlanOptions,
|
||||
"executionPlanSizeLimitBytes" | "remoteFiles" | "allowOutsideProjectAssets"
|
||||
| "executionPlanSizeLimitBytes"
|
||||
| "remoteFiles"
|
||||
| "allowOutsideProjectAssets"
|
||||
| "includeOutsideScripts"
|
||||
>,
|
||||
) {
|
||||
// Plan-time validation. Rejections here surface as typed errors with
|
||||
@@ -1250,6 +1254,7 @@ async function compilePlanComposition(
|
||||
strictVariables: config.strictVariables,
|
||||
pageMotionBlur: config.pageMotionBlur,
|
||||
allowOutsideProjectAssets: options.allowOutsideProjectAssets === true,
|
||||
includeOutsideScripts: options.includeOutsideScripts === true,
|
||||
});
|
||||
const entryFile = config.entryFile ?? "index.html";
|
||||
const htmlPath = join(projectDir, entryFile);
|
||||
@@ -1286,7 +1291,9 @@ async function compilePlanComposition(
|
||||
if (rel === "") return true;
|
||||
if (leavesRoot(rel)) return false;
|
||||
if (job.config.allowOutsideProjectAssets) {
|
||||
if (refusesOutsideLink(projectDir, src, (line) => log.warn(`[Plan] ${line}`))) return false;
|
||||
const warn = (line: string) => log.warn(`[Plan] ${line}`);
|
||||
const policy = { includeScripts: job.config.includeOutsideScripts };
|
||||
if (refusesOutsideLink(projectDir, src, warn, policy)) return false;
|
||||
} else if (!isSafePath(projectDir, src)) return false;
|
||||
const firstSegment = rel.split(sep, 1)[0];
|
||||
return firstSegment === undefined || !PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(firstSegment);
|
||||
@@ -1915,7 +1922,7 @@ export async function plan(
|
||||
planDir: string,
|
||||
options: Pick<
|
||||
BuildLocalExecutionPlanOptions,
|
||||
"chunksCarryAudio" | "allowOutsideProjectAssets"
|
||||
"chunksCarryAudio" | "allowOutsideProjectAssets" | "includeOutsideScripts"
|
||||
> = {},
|
||||
): Promise<PlanResult> {
|
||||
const executionPlan = await buildLocalExecutionPlan(projectDir, config, planDir, options);
|
||||
|
||||
@@ -55,7 +55,7 @@ export async function renderSpan(
|
||||
config: DistributedRenderConfig,
|
||||
span: { startSeconds: number; endSeconds?: number },
|
||||
outputPath: string,
|
||||
options: { allowOutsideProjectAssets?: boolean } = {},
|
||||
options: { allowOutsideProjectAssets?: boolean; includeOutsideScripts?: boolean } = {},
|
||||
): Promise<RenderSpanResult> {
|
||||
if (config.format !== "mp4") {
|
||||
throw new RenderSpanUnsupportedError(
|
||||
@@ -75,7 +75,11 @@ export async function renderSpan(
|
||||
projectDir,
|
||||
{ ...config, rejectOnSystemFonts: false, failClosedFontFetch: false },
|
||||
planDir,
|
||||
{ chunksCarryAudio: true, allowOutsideProjectAssets: options.allowOutsideProjectAssets },
|
||||
{
|
||||
chunksCarryAudio: true,
|
||||
allowOutsideProjectAssets: options.allowOutsideProjectAssets,
|
||||
includeOutsideScripts: options.includeOutsideScripts,
|
||||
},
|
||||
);
|
||||
const { startFrame, endFrame } = spanFrameRange(
|
||||
span.startSeconds,
|
||||
|
||||
@@ -447,6 +447,7 @@ export interface SyntheticRenderJobInput {
|
||||
strictVariables?: RenderConfig["strictVariables"];
|
||||
pageMotionBlur?: RenderConfig["pageMotionBlur"];
|
||||
allowOutsideProjectAssets?: boolean;
|
||||
includeOutsideScripts?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -477,6 +478,7 @@ export function buildSyntheticRenderJob(input: SyntheticRenderJobInput): RenderJ
|
||||
strictVariables: input.strictVariables,
|
||||
pageMotionBlur: input.pageMotionBlur,
|
||||
allowOutsideProjectAssets: input.allowOutsideProjectAssets,
|
||||
includeOutsideScripts: input.includeOutsideScripts,
|
||||
};
|
||||
return createRenderJob(renderConfig);
|
||||
}
|
||||
|
||||
@@ -724,6 +724,7 @@ export interface FileServerOptions {
|
||||
stripEmbeddedRuntime?: boolean;
|
||||
/** Serve project symlinks that lead outside projectDir, as local preview does. Default: false. */
|
||||
allowOutsideProjectAssets?: boolean;
|
||||
includeOutsideScripts?: boolean;
|
||||
}
|
||||
|
||||
export interface FileServerHandle {
|
||||
@@ -802,6 +803,7 @@ export function createFileServer(options: FileServerOptions): Promise<FileServer
|
||||
port = 0,
|
||||
stripEmbeddedRuntime = true,
|
||||
allowOutsideProjectAssets = false,
|
||||
includeOutsideScripts = false,
|
||||
} = options;
|
||||
|
||||
// HF_EARLY_STUB must run before *any* page script so libraries that write
|
||||
@@ -821,6 +823,7 @@ export function createFileServer(options: FileServerOptions): Promise<FileServer
|
||||
|
||||
const app = new Hono();
|
||||
const warnLeftOut = (line: string) => console.warn(`[FileServer] ${terminalText(line)}`);
|
||||
const outsidePolicy = { includeScripts: includeOutsideScripts };
|
||||
let listeningPort = -1;
|
||||
|
||||
app.use(async function loadEachFileOnlyAsItsNamedType(c, next) {
|
||||
@@ -845,7 +848,7 @@ export function createFileServer(options: FileServerOptions): Promise<FileServer
|
||||
if (!isPathInside(candidate, root, { resolveSymlinks })) continue;
|
||||
if (isPrivateFileUnder(root, candidate, isStudioPrivatePath)) continue;
|
||||
const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
|
||||
if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
|
||||
if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut, outsidePolicy)) continue;
|
||||
file = openRegularFile(candidate);
|
||||
if (file) break;
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ import {
|
||||
isPathInside,
|
||||
leftOutOfRender,
|
||||
outsideAssetRefusal,
|
||||
type OutsideFilePolicy,
|
||||
refusesOutsideLink,
|
||||
toExternalAssetKey,
|
||||
} from "../utils/paths.js";
|
||||
@@ -1478,6 +1479,7 @@ export function collectExternalAssets(
|
||||
projectDir: string,
|
||||
log: ProducerLogger = defaultLogger,
|
||||
file = "index.html",
|
||||
policy: OutsideFilePolicy = {},
|
||||
): { html: string; externalAssets: Map<string, string> } {
|
||||
const absProjectDir = resolve(projectDir);
|
||||
const externalAssets = new Map<string, string>();
|
||||
@@ -1492,7 +1494,7 @@ export function collectExternalAssets(
|
||||
}
|
||||
const onShare = namesAnotherNetworkRoot(absProjectDir, absPath);
|
||||
if (!onShare && !existsSync(absPath)) return null;
|
||||
const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath);
|
||||
const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath, policy);
|
||||
if (refusal) {
|
||||
if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
|
||||
leftOut.add(trimmed);
|
||||
@@ -2109,6 +2111,7 @@ export interface CompileForRenderOptions {
|
||||
pageMotionBlur?: "off";
|
||||
/** Trusted local renders only (CLI, Studio): import files markup reaches outside projectDir. */
|
||||
allowOutsideProjectAssets?: boolean;
|
||||
includeOutsideScripts?: boolean;
|
||||
}
|
||||
|
||||
/** Renders follow the same `HYPERFRAMES_GSAP_BASE_URL` mirror as Studio preview. */
|
||||
@@ -2411,6 +2414,7 @@ export async function compileForRender(
|
||||
projectDir,
|
||||
options.log,
|
||||
entryFileName(projectDir, htmlPath),
|
||||
{ includeScripts: options.includeOutsideScripts },
|
||||
)
|
||||
: { html: embeddedHtml, externalAssets: new Map<string, string>() };
|
||||
|
||||
|
||||
@@ -147,7 +147,11 @@ async function statusOf(
|
||||
}
|
||||
}
|
||||
|
||||
async function compileInProcess(projectDir: string, allowOutsideProjectAssets?: boolean) {
|
||||
async function compileInProcess(
|
||||
projectDir: string,
|
||||
allowOutsideProjectAssets?: boolean,
|
||||
includeOutsideScripts?: boolean,
|
||||
) {
|
||||
const workDir = join(projectDir, "..", "work");
|
||||
mkdirSync(workDir, { recursive: true });
|
||||
const warnings: string[] = [];
|
||||
@@ -156,6 +160,7 @@ async function compileInProcess(projectDir: string, allowOutsideProjectAssets?:
|
||||
fps: { num: 30, den: 1 },
|
||||
quality: "draft",
|
||||
allowOutsideProjectAssets,
|
||||
includeOutsideScripts,
|
||||
});
|
||||
const cfg = resolveConfig();
|
||||
const result = await runCompileStage({
|
||||
@@ -168,7 +173,8 @@ async function compileInProcess(projectDir: string, allowOutsideProjectAssets?:
|
||||
...{ projectDir, compiledDir, job, cfg, log, composition: result.composition },
|
||||
...{ abortSignal: undefined, assertNotAborted: () => {} },
|
||||
});
|
||||
const serve = () => createFileServer({ projectDir, compiledDir, allowOutsideProjectAssets });
|
||||
const serve = () =>
|
||||
createFileServer({ projectDir, compiledDir, allowOutsideProjectAssets, includeOutsideScripts });
|
||||
return { result, compiledDir, extract, serve, warnings };
|
||||
}
|
||||
|
||||
@@ -395,6 +401,58 @@ describe.skipIf(!HAS_FFMPEG)("render servers keep markup inside the project", ()
|
||||
});
|
||||
});
|
||||
|
||||
function outsideScriptsProject() {
|
||||
const { root, projectDir, outsideDir, secretKey } = outsideProject(false);
|
||||
writeFileSync(join(outsideDir, "tool.js"), "window.OUTSIDE_TOOL = 1;");
|
||||
writeFileSync(join(outsideDir, "tool.mjs"), "export const OUTSIDE_TOOL = 1;");
|
||||
writeFileSync(join(outsideDir, "look.css"), ".x { color: red; }");
|
||||
symlinkSync(join(outsideDir, "tool.mjs"), join(projectDir, "linked.mjs"));
|
||||
const html = readFileSync(join(projectDir, "index.html"), "utf-8").replace(
|
||||
"</head>",
|
||||
`<link rel="stylesheet" href="../outside/look.css"><script src="../outside/tool.js"></script></head>`,
|
||||
);
|
||||
writeFileSync(join(projectDir, "index.html"), html);
|
||||
const key = (file: string) => toExternalAssetKey(join(outsideDir, file));
|
||||
return { root, projectDir, secretKey, tool: key("tool.js"), css: key("look.css") };
|
||||
}
|
||||
|
||||
describe.skipIf(!HAS_FFMPEG)("outside scripts in a trusted local render", () => {
|
||||
it("are left out with a warning naming the flag, while media and CSS still come in", async () => {
|
||||
const { root, projectDir, secretKey, tool, css } = outsideScriptsProject();
|
||||
const { result, compiledDir, serve, warnings } = await compileInProcess(projectDir, true);
|
||||
|
||||
expect(filesUnder(compiledDir).sort()).toEqual([css, secretKey, "index.html"].sort());
|
||||
expect(result.compiled.html).toContain('src="../outside/tool.js"');
|
||||
expect(warnings.join("\n")).toContain(
|
||||
"index.html references ../outside/tool.js, which is a script outside the project; it was left out of the render. Move it into the project, or pass --include-outside-files to hyperframes render, to run it.",
|
||||
);
|
||||
expect(await statusOf(await serve(), ["/linked.mjs", "/link.png"])).toEqual([404, 200]);
|
||||
|
||||
const planDir = join(root, "plan");
|
||||
await plan(projectDir, config, planDir, { allowOutsideProjectAssets: true });
|
||||
const planned = filesUnder(join(planDir, "compiled"));
|
||||
expect(planned).not.toContain(tool);
|
||||
expect(planned).not.toContain("linked.mjs");
|
||||
expect(planned).toEqual(expect.arrayContaining([css, secretKey, "link.png"]));
|
||||
});
|
||||
|
||||
it("come in with --include-outside-files", async () => {
|
||||
const { root, projectDir, tool } = outsideScriptsProject();
|
||||
const { compiledDir, serve, warnings } = await compileInProcess(projectDir, true, true);
|
||||
|
||||
expect(existsSync(join(compiledDir, tool))).toBe(true);
|
||||
expect(warnings.join("\n")).not.toContain("script outside the project");
|
||||
expect(await statusOf(await serve(), [`/${tool}`, "/linked.mjs"])).toEqual([200, 200]);
|
||||
|
||||
const planDir = join(root, "plan");
|
||||
const included = { allowOutsideProjectAssets: true, includeOutsideScripts: true };
|
||||
await plan(projectDir, config, planDir, included);
|
||||
expect(filesUnder(join(planDir, "compiled"))).toEqual(
|
||||
expect.arrayContaining([tool, "linked.mjs"]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// These sources skip the earlier filters on purpose: each reader must refuse them on its own.
|
||||
describe.skipIf(!HAS_FFMPEG)("render readers open nothing outside the project", () => {
|
||||
const escaping = (file: string) => [
|
||||
|
||||
@@ -263,6 +263,7 @@ export async function runCompileStage(input: CompileStageInput): Promise<Compile
|
||||
animatedGifCacheDir: animatedGifCacheDir(cfg.extractCacheDir),
|
||||
ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
|
||||
allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
|
||||
includeOutsideScripts: job.config.includeOutsideScripts,
|
||||
});
|
||||
assertNotAborted();
|
||||
const compileOnlyMs = Date.now() - compileStart;
|
||||
|
||||
@@ -463,6 +463,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageR
|
||||
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
||||
fps: job.config.fps,
|
||||
allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
|
||||
includeOutsideScripts: job.config.includeOutsideScripts,
|
||||
});
|
||||
assertNotAborted();
|
||||
|
||||
|
||||
@@ -452,6 +452,7 @@ export interface RenderConfig {
|
||||
/** Entry HTML file relative to projectDir. Defaults to "index.html". */
|
||||
entryFile?: string;
|
||||
allowOutsideProjectAssets?: CompileForRenderOptions["allowOutsideProjectAssets"];
|
||||
includeOutsideScripts?: CompileForRenderOptions["includeOutsideScripts"];
|
||||
/** Full producer config. When provided, env vars are not read. */
|
||||
producerConfig?: EngineConfig;
|
||||
/** Custom logger. Defaults to console-based defaultLogger. */
|
||||
@@ -3793,6 +3794,7 @@ async function executeRenderPipeline(input: {
|
||||
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
||||
fps: job.config.fps,
|
||||
allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
|
||||
includeOutsideScripts: job.config.includeOutsideScripts,
|
||||
});
|
||||
assertNotAborted();
|
||||
observability.stageEnd("file_server", fileServerStart);
|
||||
|
||||
@@ -16,6 +16,7 @@ import { isSafePath } from "@hyperframes/core/safe-path";
|
||||
import {
|
||||
isCopiedOutsideFileType,
|
||||
isPrivateOutsideFile,
|
||||
isUploadedOutsideFileType,
|
||||
type LeftOutReason,
|
||||
leftOutWarning,
|
||||
linksOutside,
|
||||
@@ -80,20 +81,36 @@ export function escapesAssetRoot(path: string, assetRoot: string | undefined): b
|
||||
return assetRoot !== undefined && !isSafePath(assetRoot, path);
|
||||
}
|
||||
|
||||
export interface OutsideFilePolicy {
|
||||
/** The person passed --include-outside-files, so scripts outside the project run too. */
|
||||
includeScripts?: boolean;
|
||||
}
|
||||
|
||||
/** Why a trusted local render leaves out `path`, which leads outside `projectDir`, as publish does; null to bring it in. */
|
||||
export function outsideAssetRefusal(projectDir: string, path: string): LeftOutReason | null {
|
||||
export function outsideAssetRefusal(
|
||||
projectDir: string,
|
||||
path: string,
|
||||
policy: OutsideFilePolicy = {},
|
||||
): LeftOutReason | null {
|
||||
if (!linksOutside(projectDir, path)) return null;
|
||||
if (isPrivateOutsideFile(projectDir, path)) return "blocklisted";
|
||||
const folder = statSync(path, { throwIfNoEntry: false })?.isDirectory();
|
||||
return folder || isCopiedOutsideFileType(path) ? null : "file_type";
|
||||
if (folder || isUploadedOutsideFileType(path)) return null;
|
||||
if (!isCopiedOutsideFileType(path)) return "file_type";
|
||||
return policy.includeScripts ? null : "script";
|
||||
}
|
||||
|
||||
export const leftOutOfRender = (file: string, reference: string, reason: LeftOutReason): string =>
|
||||
leftOutWarning(file, reference, reason, "render");
|
||||
|
||||
/** True, after a warning, when a trusted local render must not serve or copy `path`, a project file that leads outside. */
|
||||
export function refusesOutsideLink(projectDir: string, path: string, warn: (line: string) => void) {
|
||||
const refusal = outsideAssetRefusal(projectDir, path);
|
||||
export function refusesOutsideLink(
|
||||
projectDir: string,
|
||||
path: string,
|
||||
warn: (line: string) => void,
|
||||
policy: OutsideFilePolicy = {},
|
||||
) {
|
||||
const refusal = outsideAssetRefusal(projectDir, path, policy);
|
||||
if (!refusal) return false;
|
||||
const file = nodeRelative(projectDir, path).split(sep).join("/");
|
||||
warn(leftOutOfRender(file, realFilePath(path), refusal));
|
||||
|
||||
@@ -146,14 +146,21 @@ export function isPrivateOutsideFile(projectDir: string, absPath: string): boole
|
||||
export const linksOutside = (projectDir: string, filePath: string): boolean =>
|
||||
isOutside(relative(realFilePath(projectDir), realFilePath(filePath)));
|
||||
|
||||
/** `blocklisted`: a private location; `received`: reached from an imported file; `file_type`: not a type uploads copy; `network_share`: on another computer. */
|
||||
export type LeftOutReason = "blocklisted" | "received" | "file_type" | "private" | "network_share";
|
||||
/** `blocklisted`: a private location; `received`: reached from an imported file; `file_type`: not a type uploads copy; `network_share`: on another computer; `script`: a script a local render was not told to run. */
|
||||
export type LeftOutReason =
|
||||
| "blocklisted"
|
||||
| "received"
|
||||
| "file_type"
|
||||
| "private"
|
||||
| "network_share"
|
||||
| "script";
|
||||
|
||||
const WHY: Record<Exclude<LeftOutReason, "file_type">, string> = {
|
||||
private: "which holds secrets or tool data",
|
||||
blocklisted: "which is outside the project in a private location",
|
||||
received: "which leads outside the project and came in with an imported project",
|
||||
network_share: "which is on another computer's network share or is a Windows device path",
|
||||
script: "which is a script outside the project",
|
||||
};
|
||||
|
||||
const COPIED_TYPES = {
|
||||
@@ -172,5 +179,7 @@ export function leftOutWarning(
|
||||
? `which is outside the project and is not ${COPIED_TYPES[from]}`
|
||||
: WHY[reason];
|
||||
const warning = `${file} references ${reference}, ${why}; it was left out of the ${from}.`;
|
||||
return reason === "file_type" ? `${warning} Move it into the project to include it.` : warning;
|
||||
if (reason === "file_type") return `${warning} Move it into the project to include it.`;
|
||||
if (reason !== "script") return warning;
|
||||
return `${warning} Move it into the project, or pass --include-outside-files to hyperframes render, to run it.`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user