fix(aws-lambda): Lambda renders reach only public addresses unless the function opts out (#7780)

* fix(aws-lambda): Lambda renders reach only public addresses unless the function opts out

* chore(aws-lambda): drop a comment the function name already says
This commit is contained in:
Miguel Ángel
2026-11-14 19:39:09 -05:00
committed by GitHub
parent f4b6aad332
commit e8a59bf177
3 changed files with 31 additions and 0 deletions
+6
View File
@@ -58,6 +58,12 @@ All three phases must fit the configured per-invocation Lambda timeout, at most
The handler uses `@sparticuz/chromium` by default, with a build-time fallback for bundling `chrome-headless-shell` directly when needed.
### Page network restriction
The handler sets `PRODUCER_RESTRICT_PAGE_NETWORK=true` unless the function already sets it, so a rendered page reaches only its own project files and public internet addresses. Loopback, private, link-local and IPv6 addresses are refused for anything the page loads. An asset on a VPC-only host or behind private DNS is missing from the video.
Keep it on when you render compositions you did not write. To turn it off, set `PRODUCER_RESTRICT_PAGE_NETWORK=false` in the function's environment.
## Using the SDK
After deploying the AWS resources, use the SDK from Node:
+20
View File
@@ -47,6 +47,7 @@ import {
useBundledBinaries,
} from "./handler.js";
import { S3PlanV2ArtifactPublisher } from "./s3PlanV2Publisher.js";
import { resolveRestrictPageNetwork } from "../../engine/src/config.js";
interface FakeS3Op {
kind: "download" | "upload" | "copy";
@@ -263,6 +264,25 @@ describe("unwrapEvent", () => {
});
});
describe("render page address rules", () => {
it("are on for every invocation unless the function turns them off", async () => {
const before = process.env.PRODUCER_RESTRICT_PAGE_NETWORK;
try {
delete process.env.PRODUCER_RESTRICT_PAGE_NETWORK;
await handleEvent({ Action: "warm" } as never, { skipChromeResolution: true });
expect(process.env.PRODUCER_RESTRICT_PAGE_NETWORK).toBe("true");
expect(resolveRestrictPageNetwork()).toBe(true);
process.env.PRODUCER_RESTRICT_PAGE_NETWORK = "false";
await handleEvent({ Action: "warm" } as never, { skipChromeResolution: true });
expect(resolveRestrictPageNetwork()).toBe(false);
} finally {
if (before === undefined) delete process.env.PRODUCER_RESTRICT_PAGE_NETWORK;
else process.env.PRODUCER_RESTRICT_PAGE_NETWORK = before;
}
});
});
describe("useBundledBinaries", () => {
function taskRoot(...binaries: string[]): string {
const root = mkdtempSync(join(tmpdir(), "hf-lambda-task-"));
+5
View File
@@ -324,11 +324,16 @@ function summarizeEvent(
let runtimeEnvPrimed = false;
function primeRuntimeEnv(): void {
restrictPageNetworkByDefault();
if (runtimeEnvPrimed) return;
runtimeEnvPrimed = true;
useBundledBinaries(process.env.LAMBDA_TASK_ROOT ?? "/var/task");
}
function restrictPageNetworkByDefault(env: NodeJS.ProcessEnv = process.env): void {
if (!env.PRODUCER_RESTRICT_PAGE_NETWORK?.trim()) env.PRODUCER_RESTRICT_PAGE_NETWORK = "true";
}
const BUNDLED_FF_BINARIES = [
["ffmpeg", "HYPERFRAMES_FFMPEG_PATH"],
["ffprobe", "HYPERFRAMES_FFPROBE_PATH"],