mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
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:
@@ -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:
|
||||
|
||||
@@ -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-"));
|
||||
|
||||
@@ -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"],
|
||||
|
||||
Reference in New Issue
Block a user