85453da49f
regression / regression-shards (style-16-prod style-9-prod style-17-prod iframe-render-compat variables-prod mp4-h265-sdr, shard-4) (push) Has been cancelled
regression / regression-shards (style-4-prod style-11-prod style-2-prod animejs-adapter typegpu-adapter parallel-capture-regression, shard-5) (push) Has been cancelled
regression / regression-shards (style-7-prod style-8-prod style-10-prod css-spinner-render-compat webm-transparency mp4-h264-sdr webm-vp9, shard-3) (push) Has been cancelled
regression / regression-shards (sub-composition-video style-18-prod raf-ball-render-compat font-variant-numeric sub-comp-t0 sub-comp-id-selector, shard-7) (push) Has been cancelled
Windows render verification / Detect changes (push) Has been cancelled
Windows render verification / Preflight (lint + format) (push) Has been cancelled
Windows render verification / Render on windows-latest (push) Has been cancelled
Windows render verification / Tests on windows-latest (push) Has been cancelled
CI / Detect changes (push) Has been cancelled
CI / Build (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Fallow audit (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Producer: integration tests (push) Has been cancelled
CI / Producer: unit tests (push) Has been cancelled
CI / File size check (push) Has been cancelled
CI / Test: skills (push) Has been cancelled
CI / Skills: manifest in sync (push) Has been cancelled
CI / CLI: npx shim (macos-latest) (push) Has been cancelled
CI / CLI: npx shim (ubuntu-latest) (push) Has been cancelled
CI / CLI: npx shim (windows-latest) (push) Has been cancelled
CI / SDK: unit + contract + smoke (push) Has been cancelled
CI / Test: runtime contract (push) Has been cancelled
CI / Studio: load smoke (push) Has been cancelled
CI / Smoke: global install (push) Has been cancelled
CI / CLI smoke (required) (push) Has been cancelled
CI / Semantic PR title (push) Has been cancelled
Player perf / Detect changes (push) Has been cancelled
Player perf / Preflight (lint + format) (push) Has been cancelled
Player perf / player-perf (push) Has been cancelled
Player perf / Perf: drift (push) Has been cancelled
Player perf / Perf: fps (push) Has been cancelled
Player perf / Perf: parity (push) Has been cancelled
Player perf / Perf: scrub (push) Has been cancelled
Player perf / Perf: load (push) Has been cancelled
preview-regression / Detect changes (push) Has been cancelled
preview-regression / Preflight (lint + format) (push) Has been cancelled
preview-regression / Preview parity (push) Has been cancelled
preview-regression / preview-regression (push) Has been cancelled
regression / regression (push) Has been cancelled
regression / Detect changes (push) Has been cancelled
regression / Preflight (lint + format) (push) Has been cancelled
regression / regression-shards (hdr-regression style-5-prod style-3-prod mov-prores, shard-1) (push) Has been cancelled
regression / regression-shards (overlay-montage-prod style-12-prod chat missing-host-comp-id png-sequence portrait-edge-bleed, shard-6) (push) Has been cancelled
regression / regression-shards (style-13-prod style-6-prod vignelli-stacking gsap-letters-render-compat audio-mux-parity, shard-8) (push) Has been cancelled
regression / regression-shards (style-15-prod hdr-hlg-regression style-1-prod many-cuts vfr-screen-recording render-symlinked-assets, shard-2) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Docs / Validate docs (push) Has been cancelled
Sync skills to ClawHub / Publish changed skills (push) Has been cancelled
71 lines
3.0 KiB
JavaScript
71 lines
3.0 KiB
JavaScript
import { writeFileSync, copyFileSync, mkdirSync } from "node:fs";
|
|
import { dirname } from "node:path";
|
|
|
|
// ponytail: bound the download so a hostile/runaway URL can't fill the disk.
|
|
// 256MB covers any real media asset; raise if 4K video sources ever exceed it.
|
|
const MAX_FREEZE_BYTES = 256 * 1024 * 1024;
|
|
|
|
export async function freezeUrl(url, destPath) {
|
|
const where = String(url).slice(0, 80);
|
|
const res = await fetch(url);
|
|
if (!res.ok) throw new Error(`freeze failed: HTTP ${res.status} for ${where}`);
|
|
|
|
// Fail fast on an advertised oversize body before reading a single byte.
|
|
const declared = Number(res.headers.get("content-length"));
|
|
if (declared > MAX_FREEZE_BYTES)
|
|
throw new Error(
|
|
`freeze failed: ${declared} bytes exceeds ${MAX_FREEZE_BYTES} cap for ${where}`,
|
|
);
|
|
|
|
// Stream and abort once the cap is crossed, so a lying/chunked hostile URL
|
|
// can't buffer the whole payload into memory before the check (M1).
|
|
const chunks = [];
|
|
let total = 0;
|
|
for await (const chunk of res.body) {
|
|
total += chunk.length;
|
|
if (total > MAX_FREEZE_BYTES)
|
|
throw new Error(`freeze failed: stream exceeds ${MAX_FREEZE_BYTES} cap for ${where}`);
|
|
chunks.push(chunk);
|
|
}
|
|
if (total === 0) throw new Error(`freeze failed: empty response for ${where}`);
|
|
|
|
mkdirSync(dirname(destPath), { recursive: true });
|
|
writeFileSync(destPath, Buffer.concat(chunks, total));
|
|
return total;
|
|
}
|
|
|
|
export function freezeLocalFile(srcPath, destPath) {
|
|
mkdirSync(dirname(destPath), { recursive: true });
|
|
copyFileSync(srcPath, destPath);
|
|
}
|
|
|
|
// Ingest accepts a DIRECT public media URL only — not a platform page. yt-dlp is
|
|
// deliberately out (cloud IPs get blocked, and it's brittle); the supported case
|
|
// is "user points at their own file or a direct asset link". A direct URL is a
|
|
// non-platform host whose path ends in a known media extension.
|
|
const PLATFORM_HOSTS =
|
|
/(^|\.)(youtube\.com|youtu\.be|vimeo\.com|tiktok\.com|instagram\.com|twitter\.com|x\.com|facebook\.com|dailymotion\.com)$/i;
|
|
const MEDIA_EXT = /\.(mp3|wav|m4a|aac|ogg|flac|mp4|mov|webm|mkv|png|jpe?g|webp|gif|svg|avif)$/i;
|
|
|
|
// SSRF guard (m11): a user-supplied --from URL must not point at the local host
|
|
// or a private network. Blocks loopback/localhost, RFC1918, link-local, and the
|
|
// IPv6 equivalents on the literal hostname.
|
|
// ponytail: literal-host check only; a DNS name that *resolves* to a private IP
|
|
// (rebinding) still passes — add resolve-then-check if --from ever fetches from
|
|
// untrusted hostnames at scale.
|
|
const PRIVATE_HOST =
|
|
/^(localhost|.*\.local|.*\.internal|127\.|10\.|0\.|169\.254\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|\[?(::1|::ffff:127\.|f[cd][0-9a-f]{2}:|fe80:))/i;
|
|
|
|
export function isDirectMediaUrl(u) {
|
|
let url;
|
|
try {
|
|
url = new URL(u);
|
|
} catch {
|
|
return false;
|
|
}
|
|
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
if (PLATFORM_HOSTS.test(url.hostname)) return false;
|
|
if (PRIVATE_HOST.test(url.hostname)) return false;
|
|
return MEDIA_EXT.test(url.pathname);
|
|
}
|