fix(engine): local media inputs open with the file protocol only, and other schemes are refused (#8726)

This commit is contained in:
Miguel Ángel
2026-11-24 17:34:21 +00:00
committed by GitHub
parent 5969cd2b43
commit d975475cd5
3 changed files with 74 additions and 5 deletions
@@ -125,8 +125,10 @@ describe("media inputs with PRODUCER_RESTRICT_PAGE_NETWORK on", () => {
});
it("reads a local file and a URL the render declared as before, with no proxy", () => {
expect(urlInputArgs("/renders/clip.mp4")).not.toContain("-protocol_whitelist");
expect(urlInputArgs("C:\\renders\\clip.mp4")).not.toContain("-protocol_whitelist");
for (const local of ["/renders/clip.mp4", "C:\\renders\\clip.mp4"]) {
expect(urlInputArgs(local).slice(0, 2)).toEqual(["-protocol_whitelist", "file"]);
expect(urlInputArgs(local)).not.toContain("-http_proxy");
}
const declared = "https://bucket.s3.amazonaws.com/renders/abc.mp4";
declareContentAddressedUrl(declared, "a".repeat(64));
const args = urlInputArgs(`${declared}?X-Amz-Signature=deadbeef`, {
@@ -180,6 +180,66 @@ describe("urlInputArgs", () => {
},
);
// fails without the fix: off a render service a local input had no protocol limit and a scheme went to ffmpeg as
// is, so a relative src such as concat:a.wav|/elsewhere/b.wav made ffmpeg open files the project never held.
it("opens a local input with the file protocol only, in every mode", () => {
for (const restricted of ["", "true"]) {
vi.stubEnv("PRODUCER_RESTRICT_PAGE_NETWORK", restricted);
try {
for (const input of [
"/plan/compiled/bg.mp4",
"clip.mp4",
"./a:b.wav",
"C:\\renders\\bg.mp4",
])
expect(urlInputArgs(input).slice(0, 2)).toEqual(["-protocol_whitelist", "file"]);
} finally {
vi.unstubAllEnvs();
}
}
});
it.each(["ffmpeg", "ffprobe"] as const)(
"refuses, for %s, a scheme ffmpeg would open as something other than the file it names",
(tool) => {
for (const input of [
"concat:a.wav|/etc/passwd",
"subfile,,start,0,end,0,,:/etc/passwd",
"crypto:/etc/passwd",
"async:/etc/passwd",
"cache:/etc/passwd",
"data:,x",
"pipe:0",
"fd:3",
])
expect(() => urlInputArgs(input, { tool })).toThrow(/input is not read/);
expect(urlInputArgs("http://127.0.0.1:8080/bg.mp4", { tool })).not.toContain(
"-protocol_whitelist",
);
},
);
it.skipIf(spawnSync(getFfprobeBinary(), ["-version"]).status !== 0)(
"keeps ffprobe from opening another protocol under a local input's options",
() => {
const dir = mkdtempSync(join(tmpdir(), "hf-url-input-"));
try {
const wav = join(dir, "outside.wav");
const tone = ["-f", "lavfi", "-i", "sine=frequency=440:duration=1"];
spawnSync(getFfmpegBinary(), ["-v", "error", "-y", ...tone, wav]);
const probe = (options: string[], input: string) =>
spawnSync(getFfprobeBinary(), ["-v", "error", ...options, "-show_format", "--", input])
.status;
const local = urlInputArgs(wav, { tool: "ffprobe" });
expect(probe(local, wav)).toBe(0);
expect(probe([], `concat:${wav}|${wav}`)).toBe(0);
expect(probe(local, `concat:${wav}|${wav}`)).not.toBe(0);
} finally {
rmSync(dir, { recursive: true, force: true });
}
},
);
it("refuses an https input when no CA bundle exists", () => {
expect(() => urlInputArgs(signed, { caBundles: ["/nonexistent.crt"] })).toThrow(/no CA bundle/);
});
+10 -3
View File
@@ -39,11 +39,16 @@ const ROUTES = new Map<string, "local" | "proxy">([
["https", "proxy"],
]);
function restrictedRoute(input: string): "local" | "declared" | "proxy" {
function schemeRoute(input: string): "local" | "proxy" {
const scheme = /^subfile,/i.test(input) ? "subfile" : SCHEME.exec(input)?.[1]?.toLowerCase();
const route = scheme === undefined ? "local" : ROUTES.get(scheme);
if (!route)
throw new Error(`[FFmpeg] a ${scheme}: input is not read with a restricted page network`);
if (route) return route;
const where = resolveRestrictPageNetwork() ? " with a restricted page network" : "";
throw new Error(`[FFmpeg] a ${scheme}: input is not read${where}`);
}
function restrictedRoute(input: string): "local" | "declared" | "proxy" {
const route = schemeRoute(input);
return route === "proxy" && /^https:/i.test(input) && contentAddressedSha256(input)
? "declared"
: route;
@@ -73,6 +78,8 @@ export function urlInputArgs(
...proxiedLimits(),
...PROXY_THAT_REACHES_NOTHING,
];
if ((route ?? schemeRoute(input)) === "local")
return ["-protocol_whitelist", "file", ...mediaFormats()];
if (!/^https:\/\//i.test(input)) return mediaFormats();
const caFile = caBundles.find((path) => existsSync(path));
if (!caFile) {