mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(engine,producer): render media readers skip private project files and text-art input (#7928)
* fix(engine,producer): render media readers treat private project files as missing A video, audio, GIF or HEIC src that names a file the file servers refuse (git metadata, env, credentials, tool state, app records), as written or through a link, is now treated as missing by every render-time reader: the compile-time duration probe and keyframe advisory, GIF and HEIC prep, the media drop step, the HDR probe, frame extraction and the audio mixer. The engine's isPrivateUnderAssetRoots judges a path from every asset root that holds it, so a render's own work folder inside the project's .hyperframes/ keeps its downloaded and prepared files. * fix(engine): probe refuses a text file that ffmpeg reads as text-art video ffmpeg's tty and bintext demuxers turn a text file (such as .asc or .nfo) into a video stream that draws the text into frames. Every probe now refuses an input whose container is tty or whose video codec is ansi, bintext, xbin or idf, as not media. Probing, frame extraction and audio reads all go through the same probe, on every render. No demuxer for real video or audio produces these, so local renders keep every other format. * fix(engine,producer,cli): playlist entries and check probes skip private files - A media playlist (HLS segment, key or map URI, ffconcat file) that names a private file inside its own folder is refused as not media, like one that names a file outside it. - `hyperframes check` no longer probes a media source outside the project or private in it: mediaPath returns null for such a file and the audio, heard-clip and HDR checks skip it. - The compiler's duration probe and keyframe check judge privacy from every asset root, as the render-time readers do.
This commit is contained in:
@@ -139,9 +139,8 @@ async function videoSoundsAutoDetected(
|
||||
dependencies: AudioCheckDependencies,
|
||||
): Promise<boolean> {
|
||||
for (const video of media.videos) {
|
||||
if (!video.hasAudio) continue;
|
||||
if (await dependencies.videoHasAudio(mediaPath(video.src, projectDir)).catch(() => false))
|
||||
return true;
|
||||
const path = video.hasAudio ? mediaPath(video.src, projectDir) : null;
|
||||
if (path && (await dependencies.videoHasAudio(path).catch(() => false))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -156,7 +155,7 @@ async function inspectClip(
|
||||
): Promise<CheckFinding[]> {
|
||||
const path = mediaPath(clip.src, projectDir);
|
||||
// ponytail: remote sources are not fetched; missing local files are lint's audio_src_not_found.
|
||||
if (path === clip.src || !existsSync(path)) return [];
|
||||
if (path === null || path === clip.src || !existsSync(path)) return [];
|
||||
const problem = await clipProblem(path, clip, dependencies);
|
||||
if (!problem) return [];
|
||||
const id = clip.type === "video" ? clip.id.replace(/-audio$/, "") : clip.id;
|
||||
|
||||
@@ -20,11 +20,10 @@ export async function inspectHdrAutoPromotion(
|
||||
colorSpace: Awaited<ReturnType<typeof extractMediaMetadata>>["colorSpace"];
|
||||
}> = [];
|
||||
for (const { src } of [...media.videos, ...media.images]) {
|
||||
const path = mediaPath(src, project.dir);
|
||||
if (path === null) continue;
|
||||
try {
|
||||
assets.push({
|
||||
asset: src,
|
||||
colorSpace: (await extractMetadata(mediaPath(src, project.dir))).colorSpace,
|
||||
});
|
||||
assets.push({ asset: src, colorSpace: (await extractMetadata(path)).colorSpace });
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { heardClips } from "./projectMedia.js";
|
||||
import { heardClips, mediaPath } from "./projectMedia.js";
|
||||
|
||||
let dir = "";
|
||||
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
||||
@@ -29,6 +29,36 @@ ${scene}
|
||||
|
||||
const probe = { seconds: async () => 6 };
|
||||
|
||||
describe("mediaPath", () => {
|
||||
it("never hands check a local file outside the project or private in it", () => {
|
||||
dir = mkdtempSync(join(tmpdir(), "hf-media-path-"));
|
||||
for (const rel of [
|
||||
".git/clip.mp4",
|
||||
".hyperframes/clip.mp4",
|
||||
"media/id_rsa",
|
||||
"media/clip.mp4",
|
||||
]) {
|
||||
mkdirSync(join(dir, rel, ".."), { recursive: true });
|
||||
writeFileSync(join(dir, rel), "x");
|
||||
}
|
||||
expect(mediaPath(".git/clip.mp4", dir)).toBeNull();
|
||||
expect(mediaPath(".hyperframes/clip.mp4", dir)).toBeNull();
|
||||
expect(mediaPath("media/id_rsa", dir)).toBeNull();
|
||||
expect(mediaPath("../../outside.mp4", dir)).toBeNull();
|
||||
expect(mediaPath("media/clip.mp4", dir)).toBe(join(dir, "media", "clip.mp4"));
|
||||
expect(mediaPath("https://cdn.example.com/a.mp4", dir)).toBe("https://cdn.example.com/a.mp4");
|
||||
});
|
||||
|
||||
it("does not probe a private file a scene's audio names", async () => {
|
||||
const seen: string[] = [];
|
||||
const root = project('<audio id="a" src="../.git/voice.wav" data-start="0"></audio>');
|
||||
mkdirSync(join(root, ".git"));
|
||||
writeFileSync(join(root, ".git", "voice.wav"), "x");
|
||||
await heardClips(root, { seconds: async (path) => (seen.push(path), 6) });
|
||||
expect(seen).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("heardClips", () => {
|
||||
it("hears a speaking video inside a timed wrapper in a scene, where the render plays it", async () => {
|
||||
const clips = await heardClips(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
assetRootsRefusal,
|
||||
extractAudioMetadata,
|
||||
resolveProjectRelativeSrc,
|
||||
type AudioElement,
|
||||
@@ -26,9 +27,11 @@ export async function collectProjectMedia(projectDir: string): Promise<ProjectMe
|
||||
return { ...producer.collectRenderMedia(html), html };
|
||||
}
|
||||
|
||||
/** The path the render reads a media `src` from: remote URLs as they are, local ones resolved like render. */
|
||||
export function mediaPath(src: string, projectDir: string): string {
|
||||
return /^https?:\/\//i.test(src) ? src : resolveProjectRelativeSrc(src, projectDir, projectDir);
|
||||
/** The path the render reads a media `src` from, resolved like render; null for a local file it never opens. */
|
||||
export function mediaPath(src: string, projectDir: string): string | null {
|
||||
if (/^https?:\/\//i.test(src)) return src;
|
||||
const path = resolveProjectRelativeSrc(src, projectDir, projectDir);
|
||||
return assetRootsRefusal(path, [projectDir]) === null ? path : null;
|
||||
}
|
||||
|
||||
/** A clip the render mixes into the film, on the film's clock; `end` 0 means it runs to its media's end. */
|
||||
@@ -55,6 +58,7 @@ export async function heardClips(
|
||||
const lengths = new Map<string, Promise<number | null>>();
|
||||
const length = (src: string): Promise<number | null> => {
|
||||
const path = mediaPath(src, projectDir);
|
||||
if (path === null) return Promise.resolve(null);
|
||||
const known = lengths.get(path) ?? probe.seconds(path).catch(() => null);
|
||||
lengths.set(path, known);
|
||||
return known;
|
||||
|
||||
@@ -441,7 +441,11 @@ export {
|
||||
type PublicHttpsTextOptions,
|
||||
} from "./utils/urlDownloader.js";
|
||||
export { isBlockedNetworkHost } from "./utils/networkPolicy.js";
|
||||
export { isInsideAssetRoots } from "./utils/assetRoots.js";
|
||||
export {
|
||||
assetRootsRefusal,
|
||||
isInsideAssetRoots,
|
||||
isPrivateUnderAssetRoots,
|
||||
} from "./utils/assetRoots.js";
|
||||
export { onRenderRefusal } from "./services/publicNetwork/captureProxy.js";
|
||||
export type { RefusedHostClass } from "./services/publicNetwork/publicNetwork.js";
|
||||
export {
|
||||
|
||||
@@ -309,6 +309,37 @@ describe("processCompositionAudio", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it.each([".git/music.mp3", ".hyperframes/music.mp3", ".claude/music.mp3", "keys/id_rsa"])(
|
||||
"never opens the private project file %s as an audio source",
|
||||
async (src) => {
|
||||
const baseDir = mkdtempSync(join(tmpdir(), "hf-audio-private-"));
|
||||
const workDir = mkdtempSync(join(tmpdir(), "hf-audio-work-"));
|
||||
tempDirs.push(baseDir, workDir);
|
||||
mkdirSync(join(baseDir, src, ".."), { recursive: true });
|
||||
writeFileSync(join(baseDir, src), "not for the render");
|
||||
|
||||
const result = await processCompositionAudio(
|
||||
[{ id: "bed", src, start: 0, end: 2, mediaStart: 0, layer: 0, volume: 1, type: "audio" }],
|
||||
baseDir,
|
||||
workDir,
|
||||
join(workDir, "out.m4a"),
|
||||
2,
|
||||
undefined,
|
||||
{ assetRoots: [baseDir] },
|
||||
);
|
||||
|
||||
expect(result.failures).toEqual([
|
||||
expect.objectContaining({
|
||||
reason: "source_not_found",
|
||||
elementId: "bed",
|
||||
detail: "Audio element bed source is a private project file",
|
||||
}),
|
||||
]);
|
||||
expect(extractAudioMetadataMock).not.toHaveBeenCalled();
|
||||
expect(runFfmpegMock.mock.calls.flat(2)).not.toContain(join(baseDir, src));
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{
|
||||
message: "AbortError: ffprobe operation aborted",
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
type AudioMetadata,
|
||||
} from "../utils/ffprobe.js";
|
||||
import { isNotMediaPayload } from "../utils/notMediaPayload.js";
|
||||
import { isInsideAssetRoots } from "../utils/assetRoots.js";
|
||||
import { assetRootsRefusal } from "../utils/assetRoots.js";
|
||||
import { urlInputArgs } from "../utils/urlInput.js";
|
||||
import { clampAudioGain, clipGain } from "@hyperframes/core/audio-gain";
|
||||
import { clampFadesToDuration, readElementFades } from "@hyperframes/core/audio-fade";
|
||||
@@ -1434,7 +1434,7 @@ export async function processCompositionAudio(
|
||||
urlByAbsentLocalPath?: ReadonlyMap<string, string>;
|
||||
audioSidecarUrlByLocalPath?: ReadonlyMap<string, string>;
|
||||
keepEncoderInputAt?: string;
|
||||
/** Folders a local source must be in; one outside them is never opened. Unset allows any folder. */
|
||||
/** Folders a local source must be in; one outside them, or private there, is never opened. Unset allows any folder. */
|
||||
assetRoots?: readonly string[];
|
||||
},
|
||||
compiledDir?: string,
|
||||
@@ -1500,18 +1500,21 @@ export async function processCompositionAudio(
|
||||
audioSidecarUrl = config?.audioSidecarUrlByLocalPath?.get(srcPath);
|
||||
srcPath = remoteUrl;
|
||||
readInPlace = true;
|
||||
} else if (config?.assetRoots && !isInsideAssetRoots(srcPath, config.assetRoots)) {
|
||||
failures.push({
|
||||
stage: "source",
|
||||
reason: "source_not_found",
|
||||
owner: "user",
|
||||
retryable: false,
|
||||
elementId: element.id,
|
||||
detail: boundedDetail(
|
||||
`Audio element ${element.id} source is outside the project folder`,
|
||||
),
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
const refusal = config?.assetRoots
|
||||
? assetRootsRefusal(srcPath, config.assetRoots)
|
||||
: null;
|
||||
if (refusal) {
|
||||
failures.push({
|
||||
stage: "source",
|
||||
reason: "source_not_found",
|
||||
owner: "user",
|
||||
retryable: false,
|
||||
elementId: element.id,
|
||||
detail: boundedDetail(`Audio element ${element.id} source is ${refusal}`),
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -691,6 +691,49 @@ describe("video extraction failure taxonomy and bounded retry", () => {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it.skipIf(!HAS_FFMPEG)("refuses a text file that ffmpeg would draw as video", async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "hf-extract-text-art-"));
|
||||
try {
|
||||
writeFileSync(join(dir, "notes.nfo"), "API_TOKEN=not-for-the-frame\nhello\n");
|
||||
const video = { id: "v1", src: "notes.nfo", start: 0, end: 1, mediaStart: 0, loop: false };
|
||||
const extraction = extractAllVideoFrames([{ ...video, hasAudio: false }], dir, {
|
||||
fps: 30,
|
||||
outputDir: join(dir, "out"),
|
||||
assetRoots: [dir],
|
||||
});
|
||||
await expect(extraction).rejects.toThrow(/text file, not a media container/);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it.each([".git/clip.mp4", ".hyperframes/clip.mp4", ".ssh/clip.mp4"])(
|
||||
"treats the private project file %s as a missing source",
|
||||
async (src) => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "hf-extract-private-"));
|
||||
try {
|
||||
mkdirSync(join(dir, src, ".."), { recursive: true });
|
||||
writeFileSync(join(dir, src), "not for the render");
|
||||
const video = { id: "v1", src, start: 0, end: 1, mediaStart: 0, loop: false };
|
||||
const result = await extractAllVideoFrames([{ ...video, hasAudio: false }], dir, {
|
||||
fps: 30,
|
||||
outputDir: join(dir, "out"),
|
||||
assetRoots: [dir],
|
||||
});
|
||||
expect(result.extracted).toEqual([]);
|
||||
expect(result.errors).toEqual([
|
||||
expect.objectContaining({
|
||||
videoId: "v1",
|
||||
kind: "source_missing",
|
||||
error: `Video source is a private project file: ${src}`,
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// Codec-based alpha defaulting replaces tag-based detection (the
|
||||
|
||||
@@ -15,7 +15,7 @@ import { parseHTML } from "linkedom";
|
||||
import { HF_COLOR_GRADING_ATTR } from "@hyperframes/core";
|
||||
import { isPathInside } from "@hyperframes/parsers/asset-paths";
|
||||
import { resolveProjectRelativeSrc } from "@hyperframes/parsers/asset-resolution";
|
||||
import { isInsideAssetRoots } from "../utils/assetRoots.js";
|
||||
import { assetRootsRefusal } from "../utils/assetRoots.js";
|
||||
import { alphaDecoderFor } from "@hyperframes/parsers/media-alpha";
|
||||
import {
|
||||
MEDIA_RENDER_ID_ATTR,
|
||||
@@ -319,7 +319,7 @@ export interface ExtractionOptions {
|
||||
/** Directories the caller rewrites on every render (downloaded media); their sources are cached by content. */
|
||||
contentKeyedDirs?: readonly string[];
|
||||
urlByAbsentLocalPath?: ReadonlyMap<string, string>;
|
||||
/** Folders a local source must be in; one outside them is never opened. Unset allows any folder. */
|
||||
/** Folders a local source must be in; one outside them, or private there, is never opened. Unset allows any folder. */
|
||||
assetRoots?: readonly string[];
|
||||
shownBox?: { width: number; height: number };
|
||||
shownBoxes?: ReadonlyMap<string, { width: number; height: number }>;
|
||||
@@ -2275,12 +2275,13 @@ export async function extractAllVideoFrames(
|
||||
continue;
|
||||
}
|
||||
const roots = options.assetRoots;
|
||||
if (!isHttpUrl(videoPath) && roots && !isInsideAssetRoots(videoPath, roots)) {
|
||||
const refusal = !isHttpUrl(videoPath) && roots ? assetRootsRefusal(videoPath, roots) : null;
|
||||
if (refusal) {
|
||||
errors.push({
|
||||
videoId: video.id,
|
||||
kind: "source_missing",
|
||||
retryable: false,
|
||||
error: `Video source is outside the project folder: ${video.src}`,
|
||||
error: `Video source is ${refusal}: ${video.src}`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { afterAll, describe, expect, it } from "vitest";
|
||||
import { assetRootsRefusal, isPrivateUnderAssetRoots } from "./assetRoots.js";
|
||||
|
||||
describe("isPrivateUnderAssetRoots", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "hf-asset-roots-"));
|
||||
const projectDir = join(root, "project");
|
||||
const workDir = join(projectDir, ".hyperframes", "share-renders", "work");
|
||||
const roots = [projectDir, join(workDir, "compiled"), join(workDir, "downloads")];
|
||||
const file = (rel: string) => {
|
||||
const path = join(projectDir, rel);
|
||||
mkdirSync(dirname(path), { recursive: true });
|
||||
writeFileSync(path, "x");
|
||||
return path;
|
||||
};
|
||||
afterAll(() => rmSync(root, { recursive: true, force: true }));
|
||||
|
||||
it.each([
|
||||
".git/objects/clip.mp4",
|
||||
".hyperframes/agent-handoff.mp4",
|
||||
".claude/voice.wav",
|
||||
".ssh/frames.gif",
|
||||
"keys/id_ed25519",
|
||||
"certs/server.pem",
|
||||
".env",
|
||||
])("refuses the project file %s", (rel) => {
|
||||
expect(isPrivateUnderAssetRoots(file(rel), roots)).toBe(true);
|
||||
expect(assetRootsRefusal(file(rel), roots)).toBe("a private project file");
|
||||
});
|
||||
|
||||
it("refuses a link whose target is a private project file", () => {
|
||||
const link = join(projectDir, "clip.mp4");
|
||||
symlinkSync(file(".git/config"), link);
|
||||
expect(isPrivateUnderAssetRoots(link, roots)).toBe(true);
|
||||
});
|
||||
|
||||
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();
|
||||
const downloaded = file(".hyperframes/share-renders/work/downloads/remote.mp4");
|
||||
expect(isPrivateUnderAssetRoots(downloaded, roots)).toBe(false);
|
||||
});
|
||||
|
||||
it("leaves a file outside every root to the containment check", () => {
|
||||
const outside = join(root, ".git", "config");
|
||||
mkdirSync(dirname(outside), { recursive: true });
|
||||
writeFileSync(outside, "x");
|
||||
expect(isPrivateUnderAssetRoots(outside, roots)).toBe(false);
|
||||
expect(assetRootsRefusal(outside, roots)).toBe("outside the project folder");
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import { isSafePath } from "@hyperframes/core/safe-path";
|
||||
import { isPrivateFileUnder, isSafePath, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
||||
import { isWithinProjectRoot } from "@hyperframes/parsers/asset-resolution";
|
||||
|
||||
export function isInsideAssetRoots(path: string, roots: readonly string[]): boolean {
|
||||
@@ -7,3 +7,17 @@ export function isInsideAssetRoots(path: string, roots: readonly string[]): bool
|
||||
// A name the file system refuses, such as a long data: URL, opens nothing, so its spelling decides.
|
||||
return !existsSync(path) && roots.some((root) => isWithinProjectRoot(root, 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));
|
||||
return (
|
||||
holders.length > 0 &&
|
||||
holders.every((root) => isPrivateFileUnder(root, path, isStudioPrivatePath))
|
||||
);
|
||||
}
|
||||
|
||||
export function assetRootsRefusal(path: string, roots: readonly string[]): string | null {
|
||||
if (!isInsideAssetRoots(path, roots)) return "outside the project folder";
|
||||
return isPrivateUnderAssetRoots(path, roots) ? "a private project file" : null;
|
||||
}
|
||||
|
||||
@@ -349,6 +349,56 @@ describe("probeMediaProfile", () => {
|
||||
vi.doUnmock("child_process");
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ format_name: "tty", codec_name: "ansi" },
|
||||
{ format_name: "bin", codec_name: "bintext" },
|
||||
{ format_name: "xbin", codec_name: "xbin" },
|
||||
{ format_name: "idf", codec_name: "idf" },
|
||||
{ format_name: "tty", codec_name: undefined },
|
||||
])(
|
||||
"refuses a text file ffmpeg reads as $format_name video",
|
||||
async ({ format_name, codec_name }) => {
|
||||
const outcome = {
|
||||
kind: "exit" as const,
|
||||
code: 0,
|
||||
stdout: JSON.stringify({
|
||||
streams: [{ codec_type: "video", codec_name }],
|
||||
format: { format_name },
|
||||
}),
|
||||
};
|
||||
const { spawn } = createSpawnSpy([outcome, outcome]);
|
||||
vi.resetModules();
|
||||
vi.doMock("child_process", () => ({ spawn }));
|
||||
const { probeMediaProfile, extractMediaMetadata } = await import("./ffprobe.js");
|
||||
const { NotMediaPayloadError } = await import("./notMediaPayload.js");
|
||||
|
||||
await expect(probeMediaProfile("/tmp/notes-profile")).rejects.toBeInstanceOf(
|
||||
NotMediaPayloadError,
|
||||
);
|
||||
await expect(extractMediaMetadata("/tmp/notes-meta")).rejects.toThrow(/text file/);
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(spawnSync("ffprobe", ["-version"]).status !== 0)(
|
||||
"refuses a real .asc or .nfo text file named as media",
|
||||
async () => {
|
||||
vi.resetModules();
|
||||
vi.doUnmock("child_process");
|
||||
const dir = mkdtempSync(resolve(tmpdir(), "hf-text-art-"));
|
||||
const { probeMediaProfile, extractMediaMetadata } = await import("./ffprobe.js");
|
||||
try {
|
||||
for (const name of ["notes.asc", "notes.nfo"]) {
|
||||
const path = resolve(dir, name);
|
||||
writeFileSync(path, "API_TOKEN=not-for-the-frame\nhello\n");
|
||||
await expect(probeMediaProfile(path)).rejects.toThrow(/text file/);
|
||||
await expect(extractMediaMetadata(path)).rejects.toThrow(/text file/);
|
||||
}
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("classifies still, moving, audio-only, and mixed streams from probe data", async () => {
|
||||
const { spawn } = createSpawnSpy([
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
videoStreamHasAlpha,
|
||||
} from "@hyperframes/parsers/media-alpha";
|
||||
import { urlInputArgs } from "./urlInput.js";
|
||||
import { TextArtMediaError } from "./notMediaPayload.js";
|
||||
import { decodableAudioStream, misstatesPcmByteRate } from "@hyperframes/parsers/media-streams";
|
||||
import { runFfmpeg } from "./runFfmpeg.js";
|
||||
import { FFPROBE_PATH_ENV, getFfprobeBinary } from "./ffmpegBinaries.js";
|
||||
@@ -571,7 +572,9 @@ async function probeMediaOutput(filePath: string, signal?: AbortSignal): Promise
|
||||
}
|
||||
return cached.promise;
|
||||
}
|
||||
const promise = readProbeJson(filePath, signal).then(parseProbeJson);
|
||||
const promise = readProbeJson(filePath, signal).then((json) =>
|
||||
refuseTextArt(parseProbeJson(json)),
|
||||
);
|
||||
if (identity !== null) {
|
||||
cache.set(filePath, { identity, promise });
|
||||
if (!signal && cache.size > MEDIA_PROBE_OUTPUT_CACHE_MAX_ENTRIES) {
|
||||
@@ -589,6 +592,18 @@ async function probeMediaOutput(filePath: string, signal?: AbortSignal): Promise
|
||||
|
||||
class StructurallyIncompletePngError extends Error {}
|
||||
|
||||
const TEXT_ART_CODECS = new Set(["ansi", "bintext", "xbin", "idf"]);
|
||||
|
||||
function refuseTextArt(output: FFProbeOutput): FFProbeOutput {
|
||||
const formats = (output.format?.format_name ?? "").toLowerCase().split(",");
|
||||
const drawsText = (output.streams ?? []).some(
|
||||
(stream) =>
|
||||
stream.codec_type === "video" && TEXT_ART_CODECS.has(stream.codec_name?.toLowerCase() ?? ""),
|
||||
);
|
||||
if (formats.includes("tty") || drawsText) throw new TextArtMediaError();
|
||||
return output;
|
||||
}
|
||||
|
||||
async function readFileRange(
|
||||
filePath: string,
|
||||
start: number,
|
||||
|
||||
@@ -271,6 +271,27 @@ describe("playlistLeavesItsFolder", () => {
|
||||
expect(await isNotMediaPayload(file)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["a git segment", hls("#EXTINF:1,", ".git/objects/seg.ts")],
|
||||
["an encoded app record", hls("#EXTINF:1,", "%2ehyperframes/agent-handoff.ts")],
|
||||
["a key file", hls('#EXT-X-KEY:METHOD=AES-128,URI="keys/id_rsa"', "#EXTINF:1,", "seg.ts")],
|
||||
["a credential folder in a map", hls('#EXT-X-MAP:URI=".ssh/init.mp4"', "#EXTINF:1,", "seg.ts")],
|
||||
["a concat entry in agent state", concat("'.claude/part.mp4'")],
|
||||
["an env file", concat(".env")],
|
||||
])("refuses %s that stays in its folder", async (_name, contents) => {
|
||||
const file = writeFixture("clip.m3u8", contents);
|
||||
expect(await playlistLeavesItsFolder(file)).toBe(true);
|
||||
expect(await isNotMediaPayload(file)).toBe(true);
|
||||
});
|
||||
|
||||
it("refuses a nested list naming a private file from its own folder", async () => {
|
||||
const master = writeTree({
|
||||
"master.m3u8": "#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=1\nsub/inner.m3u8\n",
|
||||
"sub/inner.m3u8": hls("#EXTINF:1,", ".git/seg.ts"),
|
||||
});
|
||||
expect(await playlistLeavesItsFolder(master)).toBe(true);
|
||||
});
|
||||
|
||||
it("refuses a list whose nested list names a file outside the top folder", async () => {
|
||||
const master = writeTree({
|
||||
"master.m3u8": "#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=1\nsub/inner.m3u8\n",
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
||||
import { constants } from "node:fs";
|
||||
import { open as openFile } from "node:fs/promises";
|
||||
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
||||
import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
||||
|
||||
export const NOT_MEDIA_PAYLOAD = "NOT_MEDIA_PAYLOAD" as const;
|
||||
|
||||
@@ -56,6 +57,14 @@ export class NotMediaPayloadError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
/** A file ffmpeg reads as text art, which it would draw into video frames. */
|
||||
export class TextArtMediaError extends NotMediaPayloadError {
|
||||
constructor() {
|
||||
super([]);
|
||||
this.message = "Media source is a text file, not a media container";
|
||||
}
|
||||
}
|
||||
|
||||
/** Stable, bounded correlation key. Never the raw element id or source. */
|
||||
export function fingerprintElementId(elementId: string): string {
|
||||
return createHash("sha256").update(elementId).digest("hex").slice(0, 16);
|
||||
@@ -330,7 +339,7 @@ interface Walk {
|
||||
}
|
||||
|
||||
/**
|
||||
* True for an HLS or ffconcat list naming a file outside its folder; ffmpeg would open it. Never throws.
|
||||
* True for an HLS or ffconcat list naming a file outside its folder or private in it; ffmpeg would open it.
|
||||
* `placedAt` is where the file will live when it is read from elsewhere first (a download not yet published).
|
||||
*/
|
||||
export async function playlistLeavesItsFolder(
|
||||
@@ -430,6 +439,7 @@ async function entryLeaves(
|
||||
if (HTTP_URL.test(entry)) return false;
|
||||
for (const local of new Set([entry, percentDecoded(entry)])) {
|
||||
const nested = resolve(base, local);
|
||||
if (isPrivateFileUnder(walk.folder, nested, isStudioPrivatePath)) return true;
|
||||
let verdict = walk.verdicts.get(nested);
|
||||
if (verdict === undefined) {
|
||||
verdict = await listLeaves(nested, nested, walk, depth + 1);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { dirname, join } from "node:path";
|
||||
import { parseHTML } from "linkedom";
|
||||
import {
|
||||
buildAnimatedGifTranscodeArgs,
|
||||
prepareAnimatedGifInputs,
|
||||
resolveLocalImageSourcePath,
|
||||
type AnimatedGifTranscodeRequest,
|
||||
} from "./animatedGifPrep.js";
|
||||
|
||||
@@ -97,6 +98,36 @@ describe("buildAnimatedGifTranscodeArgs", () => {
|
||||
});
|
||||
|
||||
describe("prepareAnimatedGifInputs", () => {
|
||||
it.each([".git/sticker.gif", ".hyperframes/sticker.gif", ".claude/sticker.gif"])(
|
||||
"never transcodes the private project file %s",
|
||||
async (src) => {
|
||||
const projectDir = makeProject();
|
||||
try {
|
||||
mkdirSync(dirname(join(projectDir, src)), { recursive: true });
|
||||
writeFileSync(join(projectDir, src), gif([...frame(5), ...frame(15)], 0));
|
||||
const calls: AnimatedGifTranscodeRequest[] = [];
|
||||
const result = await prepareAnimatedGifInputs(
|
||||
`<img data-start="0" data-duration="2" src="${src}" />`,
|
||||
{
|
||||
projectDir,
|
||||
downloadDir: projectDir,
|
||||
transcode: async (request) => {
|
||||
calls.push(request);
|
||||
writeFileSync(request.outputPath, "webm");
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(calls).toEqual([]);
|
||||
expect(result.preparedGifs).toEqual([]);
|
||||
expect(
|
||||
resolveLocalImageSourcePath(src, { projectDir, downloadDir: projectDir }),
|
||||
).toBeNull();
|
||||
} finally {
|
||||
rmSync(projectDir, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("rewrites animated GIF images to muted looped videos", async () => {
|
||||
const projectDir = makeProject();
|
||||
writeFileSync(join(projectDir, "sticker.gif"), gif([...frame(5), ...frame(15)], 0));
|
||||
|
||||
@@ -4,7 +4,12 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, statSync } f
|
||||
import { dirname, isAbsolute, join, resolve } from "node:path";
|
||||
import { parseHTML } from "linkedom";
|
||||
import { parseAnimatedGifMetadata, type AnimatedGifMetadata } from "@hyperframes/core";
|
||||
import { DEFAULT_VP9_CPU_USED, runFfmpeg, renameWithRetry } from "@hyperframes/engine";
|
||||
import {
|
||||
DEFAULT_VP9_CPU_USED,
|
||||
isPrivateUnderAssetRoots,
|
||||
runFfmpeg,
|
||||
renameWithRetry,
|
||||
} from "@hyperframes/engine";
|
||||
import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
|
||||
import { isHttpUrl } from "../utils/urlDownloader.js";
|
||||
import { escapesAssetRoot, outsideAssetRefusal } from "../utils/paths.js";
|
||||
@@ -106,6 +111,7 @@ export function resolveLocalImageSourcePath(
|
||||
|
||||
const allowed = (candidate: string) =>
|
||||
!namesAnotherNetworkRoot(options.projectDir, candidate) &&
|
||||
!isPrivateUnderAssetRoots(candidate, [options.projectDir, options.downloadDir]) &&
|
||||
((!escapesAssetRoot(candidate, options.assetRoot) &&
|
||||
outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted") ||
|
||||
!escapesAssetRoot(candidate, options.downloadDir));
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import {
|
||||
copyFileSync,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
rmSync,
|
||||
symlinkSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { dirname, join } from "node:path";
|
||||
import { NOT_MEDIA_PAYLOAD, NotMediaPayloadError } from "@hyperframes/engine";
|
||||
import {
|
||||
ASSET_MEDIA_TYPE_MISMATCH,
|
||||
@@ -289,7 +297,7 @@ describe("dropMediaOutsideProject", () => {
|
||||
const workDir = join(root, "work");
|
||||
afterAll(() => rmSync(root, { recursive: true, force: true }));
|
||||
|
||||
const keptVideos = (srcs: Record<string, string>) => {
|
||||
const keptVideos = (srcs: Record<string, string>, allowOutsideProjectAssets = false) => {
|
||||
mkdirSync(projectDir, { recursive: true });
|
||||
mkdirSync(join(root, "outside"), { recursive: true });
|
||||
writeFileSync(join(root, "outside", "secret.txt"), "secret");
|
||||
@@ -299,10 +307,32 @@ describe("dropMediaOutsideProject", () => {
|
||||
});
|
||||
const composition = { videos: Object.entries(srcs).map(video), audios: [], images: [] };
|
||||
const log = { error() {}, info() {}, debug() {}, warn() {} };
|
||||
dropMediaOutsideProject({ projectDir, workDir, composition, log });
|
||||
dropMediaOutsideProject({ projectDir, workDir, composition, log, allowOutsideProjectAssets });
|
||||
return composition.videos.map((v) => v.id);
|
||||
};
|
||||
|
||||
it.each([false, true])(
|
||||
"drops media that names a private project file (outside assets allowed: %s)",
|
||||
(allowOutside) => {
|
||||
const srcs = {
|
||||
git: ".git/clip.mp4",
|
||||
app: ".hyperframes/clip.mp4",
|
||||
agent: ".claude/clip.mp4",
|
||||
ssh: "media/.ssh/clip.mp4",
|
||||
key: "media/id_rsa",
|
||||
link: "linked.mp4",
|
||||
local: "media/clip.mp4",
|
||||
};
|
||||
for (const src of Object.values(srcs).filter((src) => src !== "linked.mp4")) {
|
||||
mkdirSync(dirname(join(projectDir, src)), { recursive: true });
|
||||
writeFileSync(join(projectDir, src), "x");
|
||||
}
|
||||
rmSync(join(projectDir, "linked.mp4"), { force: true });
|
||||
symlinkSync(join(projectDir, ".git", "clip.mp4"), join(projectDir, "linked.mp4"));
|
||||
expect(keptVideos(srcs, allowOutside)).toEqual(["local"]);
|
||||
},
|
||||
);
|
||||
|
||||
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(
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
isHttpUrl,
|
||||
isInsideAssetRoots,
|
||||
isNotMediaPayload,
|
||||
isPrivateUnderAssetRoots,
|
||||
playlistLeavesItsFolder,
|
||||
NotMediaPayloadError,
|
||||
probeMediaProfile,
|
||||
@@ -97,7 +98,7 @@ export function mediaAssetRoots(projectDir: string, compiledDir: string): string
|
||||
return [projectDir, compiledDir, join(dirname(compiledDir), "downloads")];
|
||||
}
|
||||
|
||||
/** Treats local media outside the project, compiled and download dirs as missing: no probe or extraction opens it. */
|
||||
/** Treats local media outside the project, compiled and download dirs, or private there, as missing: none is opened. */
|
||||
export function dropMediaOutsideProject(input: {
|
||||
projectDir: string;
|
||||
workDir: string;
|
||||
@@ -111,6 +112,10 @@ 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)) {
|
||||
log.warn(`[Render] Media "${id}" source is missing: it is a private project file`, { src });
|
||||
return false;
|
||||
}
|
||||
if (isInsideAssetRoots(path, roots)) return true;
|
||||
if (input.allowOutsideProjectAssets) {
|
||||
const refusal = outsideAssetRefusal(projectDir, path);
|
||||
|
||||
@@ -3398,6 +3398,25 @@ describe("compileForRender non-media payload sniff (STUDIO-5433)", () => {
|
||||
expect(warnings.join("\n")).toContain("text document");
|
||||
expect(warnings.join("\n")).toContain("a1");
|
||||
});
|
||||
|
||||
it.each([".git/clip.mp4", ".hyperframes/clip.mp4", ".claude/clip.mp4", "keys/id_rsa"])(
|
||||
"never probes the private project file %s that a <video> or <audio> names",
|
||||
async (src) => {
|
||||
const projectDir = writeProject(
|
||||
`<video id="v1" src="${src}" data-start="0" muted></video>` +
|
||||
`<audio id="a1" src="${src}" data-start="0"></audio>`,
|
||||
);
|
||||
mkdirSync(dirname(join(projectDir, src)), { recursive: true });
|
||||
writeFileSync(join(projectDir, 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 });
|
||||
|
||||
expect(warnings.join("\n")).not.toContain("text document");
|
||||
rmSync(projectDir, { recursive: true, force: true });
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("duplicate media ids across nested compositions", () => {
|
||||
|
||||
@@ -118,6 +118,7 @@ import {
|
||||
type MediaProbeProfile,
|
||||
analyzeKeyframeIntervals,
|
||||
assertMediaPayload,
|
||||
isPrivateUnderAssetRoots,
|
||||
NotMediaPayloadError,
|
||||
parseMasterFxChain,
|
||||
probeMediaProfile,
|
||||
@@ -568,6 +569,7 @@ async function resolveMediaDuration(
|
||||
src: string,
|
||||
mediaStart: number,
|
||||
playbackRate: RateSpec,
|
||||
projectDir: string,
|
||||
baseDir: string,
|
||||
downloadDir: string,
|
||||
tagName: string,
|
||||
@@ -594,7 +596,12 @@ async function resolveMediaDuration(
|
||||
} else {
|
||||
filePath = decodedUrlPath(src);
|
||||
if (!filePath.startsWith("/")) filePath = join(baseDir, filePath);
|
||||
if (escapesAssetRoot(filePath, assetRoot)) return { duration: null, resolvedPath: filePath };
|
||||
if (
|
||||
escapesAssetRoot(filePath, assetRoot) ||
|
||||
isPrivateUnderAssetRoots(filePath, [projectDir, downloadDir])
|
||||
) {
|
||||
return { duration: null, resolvedPath: filePath };
|
||||
}
|
||||
// ffprobe reads only the header of a remote source, so it is probed in place.
|
||||
filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
|
||||
if (!isHttpUrl(filePath) && namesAnotherNetworkRoot(baseDir, filePath)) {
|
||||
@@ -712,6 +719,7 @@ function markInferredVariableMediaDurations(
|
||||
|
||||
async function compileHtmlFile(
|
||||
html: string,
|
||||
projectDir: string,
|
||||
baseDir: string,
|
||||
downloadDir: string,
|
||||
log?: ProducerLogger,
|
||||
@@ -734,6 +742,7 @@ async function compileHtmlFile(
|
||||
el.src!,
|
||||
el.mediaStart,
|
||||
el.playbackRate,
|
||||
projectDir,
|
||||
baseDir,
|
||||
downloadDir,
|
||||
el.tagName,
|
||||
@@ -765,6 +774,7 @@ async function compileHtmlFile(
|
||||
el.src!,
|
||||
el.mediaStart,
|
||||
el.playbackRate,
|
||||
projectDir,
|
||||
baseDir,
|
||||
downloadDir,
|
||||
el.tagName,
|
||||
@@ -886,6 +896,7 @@ async function parseSubCompositions(
|
||||
workItems.map(async (item) => {
|
||||
const { html: compiledSub } = await compileHtmlFile(
|
||||
rewriteUnresolvableGsapToCdn(item.rawSubHtml, projectDir, item.srcPath),
|
||||
projectDir,
|
||||
dirname(item.filePath),
|
||||
downloadDir,
|
||||
undefined,
|
||||
@@ -2222,6 +2233,7 @@ export async function compileForRender(
|
||||
const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
|
||||
rawHtml,
|
||||
projectDir,
|
||||
projectDir,
|
||||
downloadDir,
|
||||
options.log,
|
||||
options.urlByAbsentLocalPath,
|
||||
@@ -2434,7 +2446,8 @@ export async function compileForRender(
|
||||
advised.has(videoPath) ||
|
||||
namesAnotherNetworkRoot(projectDir, videoPath) ||
|
||||
!existsSync(videoPath) ||
|
||||
escapesAssetRoot(videoPath, assetRoot)
|
||||
escapesAssetRoot(videoPath, assetRoot) ||
|
||||
isPrivateUnderAssetRoots(videoPath, [projectDir, downloadDir])
|
||||
)
|
||||
continue;
|
||||
advised.add(videoPath);
|
||||
|
||||
@@ -51,7 +51,7 @@ import {
|
||||
resolveFinalFrameExtractionWindow,
|
||||
resolveVideoExtractionWindow,
|
||||
isHttpUrl,
|
||||
isInsideAssetRoots,
|
||||
assetRootsRefusal,
|
||||
assertPublicHttpsUrl,
|
||||
downloadToTemp,
|
||||
resolveRestrictPageNetwork,
|
||||
@@ -687,7 +687,7 @@ interface VideoAudioProbeInput {
|
||||
}
|
||||
|
||||
function opensLocally(path: string, assetRoots: readonly string[] | undefined): boolean {
|
||||
return existsSync(path) && (!assetRoots || isInsideAssetRoots(path, assetRoots));
|
||||
return existsSync(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
|
||||
}
|
||||
|
||||
function localProbeSource(src: string, input: VideoAudioProbeInput): string | null {
|
||||
|
||||
Reference in New Issue
Block a user