mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
* fix(engine): read PRODUCER_RESTRICT_PAGE_NETWORK's usual spellings and restrict on an unknown value true, 1, yes and on turn the render network restriction on and false, 0, no and off leave it off, in any letter case and with surrounding whitespace. Unset or blank stays off for local renders. Any other value now restricts and logs a warning once, instead of leaving the render browser and ffmpeg URL inputs unrestricted. * fix(producer): on a render service the audio probe reads a composition URL from a downloaded copy With PRODUCER_RESTRICT_PAGE_NETWORK on, a video URL the composition names is fetched through the shared downloader (resolved-address check, pinned connection, per-hop redirect checks) before ffprobe reads it, and skipped if the download is refused. In a distributed audio step the copy lands in the mixer's work folder, so the mix reuses it instead of downloading again. Without the flag the probe reads the URL as before. * fix(engine): on a render service a URL that ffmpeg reads in place must be a self-contained container With PRODUCER_RESTRICT_PAGE_NETWORK on, every https input ffmpeg or ffprobe opens directly (such as a signed storage URL for a project's video or audio sidecar) also gets -format_whitelist with the same self-contained containers the Studio media helpers allow. A playlist, manifest or concat list stored under a media file name can no longer make ffmpeg open other network locations. Local renders are unchanged. * fix(producer): the render-service audio probe skips only refused URLs and downloads once A composition URL is skipped, with one warning, only when the download address rules refuse it. Timeouts, HTTP errors and a cancelled render fail the probe as before. Videos without sound, muted or hidden are not downloaded. The in-process extract stage passes the render's abort signal and the mixer's work folder, so the mix reuses the copy. * fix(producer): unit tests load the orchestrator again; raise the engine size budget audioWorkDir moves to render/shared.ts, so tests that replace the audio stage module still load the orchestrator. The format-whitelist test probe ends its options with -- as the ffprobe argv contract requires. The engine packed size budget rises to 500000 bytes.
122 lines
4.4 KiB
TypeScript
122 lines
4.4 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { VideoSourceExtractionError } from "../services/videoFrameExtractor.js";
|
|
import { getFfmpegBinary, getFfprobeBinary } from "./ffmpegBinaries.js";
|
|
import { redactUrlQueriesInError, urlInputArgs } from "./urlInput.js";
|
|
|
|
const signed =
|
|
"https://bucket.s3.us-east-2.amazonaws.com/a/b?X-Amz-Credential=AKID&X-Amz-Signature=deadbeef";
|
|
|
|
describe("urlInputArgs", () => {
|
|
const caBundles = ["/nonexistent.crt", import.meta.filename];
|
|
const verifyAndReconnect = [
|
|
"-tls_verify",
|
|
"1",
|
|
"-ca_file",
|
|
import.meta.filename,
|
|
"-rw_timeout",
|
|
"30000000",
|
|
"-reconnect",
|
|
"1",
|
|
"-reconnect_delay_max",
|
|
"2",
|
|
];
|
|
|
|
it("makes ffmpeg verify the certificate of an https input and reconnect on network errors", () => {
|
|
expect(urlInputArgs(signed, { caBundles })).toEqual([
|
|
...verifyAndReconnect,
|
|
"-reconnect_on_network_error",
|
|
"1",
|
|
]);
|
|
});
|
|
|
|
it("gives ffprobe only the options its 4.0 build accepts", () => {
|
|
expect(urlInputArgs(signed, { tool: "ffprobe", caBundles })).toEqual(verifyAndReconnect);
|
|
});
|
|
|
|
it.each(["true", "1", " TRUE\n"])(
|
|
"limits what an https input may open to HTTPS on a render service (%j)",
|
|
(flag) => {
|
|
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", flag);
|
|
try {
|
|
expect(urlInputArgs(signed, { tool: "ffprobe", caBundles })).toEqual([
|
|
...verifyAndReconnect,
|
|
"-protocol_whitelist",
|
|
"https,tls,tcp",
|
|
"-format_whitelist",
|
|
expect.any(String),
|
|
]);
|
|
expect(urlInputArgs("/plan/compiled/bg.mp4", { caBundles: [] })).toEqual([]);
|
|
} finally {
|
|
vi.unstubAllEnvs();
|
|
}
|
|
},
|
|
);
|
|
|
|
it.skipIf(spawnSync(getFfprobeBinary(), ["-version"]).status !== 0)(
|
|
"on a render service lets ffprobe open a video but not a playlist or concat list named .mp4",
|
|
() => {
|
|
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", "true");
|
|
const args = urlInputArgs(signed, { caBundles });
|
|
vi.unstubAllEnvs();
|
|
const formats = args[args.indexOf("-format_whitelist") + 1]!;
|
|
const dir = mkdtempSync(join(tmpdir(), "hf-url-input-"));
|
|
try {
|
|
const video = join(dir, "clip.mp4");
|
|
const lavfi = ["-f", "lavfi", "-i", "testsrc2=size=32x32:rate=5:duration=1"];
|
|
spawnSync(getFfmpegBinary(), ["-v", "error", "-y", ...lavfi, "-c:v", "mpeg4", video]);
|
|
const playlist = join(dir, "playlist.mp4");
|
|
writeFileSync(playlist, "#EXTM3U\n#EXTINF:1,\nhttps://127.0.0.1:9/a.ts\n#EXT-X-ENDLIST\n");
|
|
const concat = join(dir, "concat.mp4");
|
|
writeFileSync(concat, "ffconcat version 1.0\nfile https://127.0.0.1:9/a.mp4\n");
|
|
const probe = (path: string) =>
|
|
spawnSync(getFfprobeBinary(), [
|
|
"-v",
|
|
"error",
|
|
"-format_whitelist",
|
|
formats,
|
|
"-show_format",
|
|
"--",
|
|
path,
|
|
]).status;
|
|
expect(probe(video)).toBe(0);
|
|
expect(probe(playlist)).not.toBe(0);
|
|
expect(probe(concat)).not.toBe(0);
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
},
|
|
);
|
|
|
|
it("adds nothing for local paths and plain http", () => {
|
|
expect(urlInputArgs("/plan/compiled/bg.mp4", { caBundles: [] })).toEqual([]);
|
|
expect(urlInputArgs("http://127.0.0.1:8080/bg.mp4", { caBundles: [] })).toEqual([]);
|
|
});
|
|
|
|
it("refuses an https input when no CA bundle exists", () => {
|
|
expect(() => urlInputArgs(signed, { caBundles: ["/nonexistent.crt"] })).toThrow(/no CA bundle/);
|
|
});
|
|
});
|
|
|
|
describe("redactUrlQueriesInError", () => {
|
|
it("strips a signed URL's query from the message, diagnostic and stack", () => {
|
|
const error = redactUrlQueriesInError(
|
|
new VideoSourceExtractionError("ffmpeg_failed", false, `read ${signed}`, `${signed}: 403`),
|
|
);
|
|
for (const text of [error.message, error.diagnostic, error.stack]) {
|
|
expect(text).toContain("https://bucket.s3.us-east-2.amazonaws.com/a/b?");
|
|
expect(text).not.toContain("deadbeef");
|
|
}
|
|
});
|
|
|
|
it("also strips it from a wrapped cause", () => {
|
|
const error = redactUrlQueriesInError(
|
|
new Error("render failed", { cause: new Error(`read ${signed}`) }),
|
|
);
|
|
expect(String((error.cause as Error).message)).not.toContain("deadbeef");
|
|
});
|
|
});
|