@hyperframes/producer 0.9.41 → 0.9.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ import {
14
14
  rmSync as rmSync7,
15
15
  writeFileSync as writeFileSync8
16
16
  } from "node:fs";
17
- import { extname as extname4, isAbsolute as isAbsolute3, join as join27, relative as relative6, sep as sep3 } from "node:path";
17
+ import { extname as extname4, isAbsolute as isAbsolute3, join as join27, relative as relative6, sep as sep4 } from "node:path";
18
18
  import {
19
19
  fpsToNumber as fpsToNumber9,
20
20
  HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
@@ -71,6 +71,73 @@ var defaultLogger = createConsoleLogger(
71
71
  process.env.HF_DEBUG_RENDER === "1" ? "debug" : "info"
72
72
  );
73
73
 
74
+ // src/utils/paths.ts
75
+ import {
76
+ basename,
77
+ join,
78
+ sep,
79
+ resolve as nodeResolve,
80
+ relative as nodeRelative,
81
+ isAbsolute as nodeIsAbsolute
82
+ } from "node:path";
83
+ import { statSync } from "node:fs";
84
+ import { fileURLToPath } from "node:url";
85
+ import { isSafePath } from "@hyperframes/core/safe-path";
86
+ import {
87
+ isCopiedOutsideFileType,
88
+ isPrivateOutsideFile,
89
+ leftOutWarning,
90
+ linksOutside
91
+ } from "@hyperframes/studio-server/outside-file";
92
+ import { realFilePath } from "@hyperframes/studio-server/safe-path";
93
+ var DEFAULT_RENDERS_DIR = process.env.PRODUCER_RENDERS_DIR ?? // fileURLToPath (not URL.pathname): on Windows .pathname is "/D:/..." which
94
+ // resolves to a bogus renders dir.
95
+ nodeResolve(fileURLToPath(import.meta.url), "../../..", "renders");
96
+ var LEADING_PARENT_SEGMENT_RE = /^\.\.(?:[\\/]|$)/;
97
+ function isPathInside(childPath, parentPath, options = {}) {
98
+ const resolvePath = options.pathModule?.resolve ?? nodeResolve;
99
+ const relativePath = options.pathModule?.relative ?? nodeRelative;
100
+ const isPathAbsolute = options.pathModule?.isAbsolute ?? nodeIsAbsolute;
101
+ const absChild = resolvePath(childPath);
102
+ const absParent = resolvePath(parentPath);
103
+ if (absChild === absParent) return true;
104
+ const rel = relativePath(absParent, absChild);
105
+ return rel !== "" && !LEADING_PARENT_SEGMENT_RE.test(rel) && !isPathAbsolute(rel);
106
+ }
107
+ function escapesAssetRoot(path, assetRoot) {
108
+ return assetRoot !== void 0 && !isSafePath(assetRoot, path);
109
+ }
110
+ function outsideAssetRefusal(projectDir, path) {
111
+ if (!linksOutside(projectDir, path)) return null;
112
+ if (isPrivateOutsideFile(projectDir, path)) return "blocklisted";
113
+ const folder = statSync(path, { throwIfNoEntry: false })?.isDirectory();
114
+ return folder || isCopiedOutsideFileType(path) ? null : "file_type";
115
+ }
116
+ var leftOutOfRender = (file, reference, reason) => leftOutWarning(file, reference, reason, "render");
117
+ function refusesOutsideLink(projectDir, path, warn) {
118
+ const refusal = outsideAssetRefusal(projectDir, path);
119
+ if (!refusal) return false;
120
+ const file = nodeRelative(projectDir, path).split(sep).join("/");
121
+ warn(leftOutOfRender(file, realFilePath(path), refusal));
122
+ return true;
123
+ }
124
+ function toExternalAssetKey(absPath) {
125
+ if (absPath.startsWith("hf-ext/")) return absPath;
126
+ let normalised = absPath.replace(/\\/g, "/");
127
+ normalised = normalised.replace(/^\/\/\?\/UNC\//i, "//");
128
+ normalised = normalised.replace(/^\/\/\?\//, "");
129
+ normalised = normalised.replace(/^\/\/([^/]+)\//, "unc/$1/");
130
+ normalised = normalised.replace(/^\/+/, "");
131
+ normalised = normalised.replace(/^([A-Za-z]):\/?/, "$1/");
132
+ return "hf-ext/" + normalised;
133
+ }
134
+ function formatCaptureFrameName(index, ext) {
135
+ return `frame_${String(index).padStart(6, "0")}.${ext}`;
136
+ }
137
+ function formatExportFrameName(index, ext) {
138
+ return `frame_${String(index + 1).padStart(6, "0")}.${ext}`;
139
+ }
140
+
74
141
  // src/services/renderOrchestrator.ts
75
142
  import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
76
143
  import {
@@ -78,7 +145,7 @@ import {
78
145
  mkdirSync as mkdirSync6,
79
146
  readdirSync as readdirSync3,
80
147
  rmSync as rmSync5,
81
- statSync as statSync5,
148
+ statSync as statSync6,
82
149
  writeFileSync as writeFileSync5,
83
150
  copyFileSync as copyFileSync5,
84
151
  appendFileSync
@@ -141,7 +208,7 @@ import { settleOnBrowserSafePort } from "@hyperframes/engine";
141
208
  import {
142
209
  existsSync as existsSync2,
143
210
  realpathSync,
144
- statSync,
211
+ statSync as statSync2,
145
212
  createReadStream,
146
213
  openSync,
147
214
  fstatSync,
@@ -151,7 +218,7 @@ import {
151
218
  } from "node:fs";
152
219
  import { promisify } from "node:util";
153
220
  import { Readable } from "node:stream";
154
- import { join, extname, resolve as resolve2, sep } from "node:path";
221
+ import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
155
222
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
156
223
  import { fpsToNumber } from "@hyperframes/core";
157
224
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -161,8 +228,8 @@ import { openRangeEnd } from "@hyperframes/studio-server/media-range";
161
228
  import { createHash } from "node:crypto";
162
229
  import { existsSync, readFileSync } from "node:fs";
163
230
  import { dirname, resolve } from "node:path";
164
- import { fileURLToPath } from "node:url";
165
- var PRODUCER_DIR = dirname(fileURLToPath(import.meta.url));
231
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
232
+ var PRODUCER_DIR = dirname(fileURLToPath2(import.meta.url));
166
233
  var SIBLING_MANIFEST_PATH = resolve(PRODUCER_DIR, "hyperframe.manifest.json");
167
234
  var MODULE_RELATIVE_MANIFEST_PATH = resolve(
168
235
  PRODUCER_DIR,
@@ -233,10 +300,10 @@ function getHfEarlyStub() {
233
300
 
234
301
  // src/services/fileServer.ts
235
302
  var readFileAsync = promisify(readFile);
236
- function isPathInside(child3, parent, options = {}) {
303
+ function isPathInside2(child3, parent, options = {}) {
237
304
  const { resolveSymlinks = false, pathModule } = options;
238
305
  const resolveFn = pathModule?.resolve ?? resolve2;
239
- const separator = pathModule?.sep ?? sep;
306
+ const separator = pathModule?.sep ?? sep2;
240
307
  const resolvedChild = resolveFn(child3);
241
308
  const resolvedParent = resolveFn(parent);
242
309
  const normalizedChild = resolveSymlinks && existsSync2(resolvedChild) ? realpathSync.native(resolvedChild) : resolvedChild;
@@ -759,7 +826,7 @@ function openRegularFile(filePath) {
759
826
  } catch (error) {
760
827
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
761
828
  return null;
762
- if (!statSync(filePath, { throwIfNoEntry: false })?.isFile()) return null;
829
+ if (!statSync2(filePath, { throwIfNoEntry: false })?.isFile()) return null;
763
830
  throw error;
764
831
  }
765
832
  let accepted = false;
@@ -788,6 +855,7 @@ function createFileServer(options) {
788
855
  const headScripts = options.headScripts ?? [getVerifiedHyperframeRuntimeSource()];
789
856
  const bodyScripts = options.bodyScripts ?? [buildRenderModeScript(options.fps), HF_BRIDGE_SCRIPT];
790
857
  const app = new Hono();
858
+ const warnLeftOut = (line) => console.warn(`[FileServer] ${line}`);
791
859
  app.get("/*", async (c) => {
792
860
  let requestPath = c.req.path;
793
861
  if (requestPath === "/") requestPath = "/index.html";
@@ -800,9 +868,12 @@ function createFileServer(options) {
800
868
  }).join("/");
801
869
  let file = null;
802
870
  for (const root of compiledDir ? [compiledDir, projectDir] : [projectDir]) {
803
- const candidate = join(root, relativePath);
871
+ const candidate = join2(root, relativePath);
804
872
  const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
805
- if (isPathInside(candidate, root, { resolveSymlinks })) file = openRegularFile(candidate);
873
+ if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
874
+ const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
875
+ if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
876
+ file = openRegularFile(candidate);
806
877
  if (file) break;
807
878
  }
808
879
  if (!file) {
@@ -977,52 +1048,6 @@ import {
977
1048
  import {
978
1049
  mediaIdPathSegment
979
1050
  } from "@hyperframes/engine";
980
-
981
- // src/utils/paths.ts
982
- import {
983
- basename,
984
- join as join2,
985
- resolve as nodeResolve,
986
- relative as nodeRelative,
987
- isAbsolute as nodeIsAbsolute
988
- } from "node:path";
989
- import { fileURLToPath as fileURLToPath2 } from "node:url";
990
- import { isSafePath } from "@hyperframes/core/safe-path";
991
- var DEFAULT_RENDERS_DIR = process.env.PRODUCER_RENDERS_DIR ?? // fileURLToPath (not URL.pathname): on Windows .pathname is "/D:/..." which
992
- // resolves to a bogus renders dir.
993
- nodeResolve(fileURLToPath2(import.meta.url), "../../..", "renders");
994
- var LEADING_PARENT_SEGMENT_RE = /^\.\.(?:[\\/]|$)/;
995
- function isPathInside2(childPath, parentPath, options = {}) {
996
- const resolvePath = options.pathModule?.resolve ?? nodeResolve;
997
- const relativePath = options.pathModule?.relative ?? nodeRelative;
998
- const isPathAbsolute = options.pathModule?.isAbsolute ?? nodeIsAbsolute;
999
- const absChild = resolvePath(childPath);
1000
- const absParent = resolvePath(parentPath);
1001
- if (absChild === absParent) return true;
1002
- const rel = relativePath(absParent, absChild);
1003
- return rel !== "" && !LEADING_PARENT_SEGMENT_RE.test(rel) && !isPathAbsolute(rel);
1004
- }
1005
- function escapesAssetRoot(path, assetRoot) {
1006
- return assetRoot !== void 0 && !isSafePath(assetRoot, path);
1007
- }
1008
- function toExternalAssetKey(absPath) {
1009
- if (absPath.startsWith("hf-ext/")) return absPath;
1010
- let normalised = absPath.replace(/\\/g, "/");
1011
- normalised = normalised.replace(/^\/\/\?\/UNC\//i, "//");
1012
- normalised = normalised.replace(/^\/\/\?\//, "");
1013
- normalised = normalised.replace(/^\/\/([^/]+)\//, "unc/$1/");
1014
- normalised = normalised.replace(/^\/+/, "");
1015
- normalised = normalised.replace(/^([A-Za-z]):\/?/, "$1/");
1016
- return "hf-ext/" + normalised;
1017
- }
1018
- function formatCaptureFrameName(index, ext) {
1019
- return `frame_${String(index).padStart(6, "0")}.${ext}`;
1020
- }
1021
- function formatExportFrameName(index, ext) {
1022
- return `frame_${String(index + 1).padStart(6, "0")}.${ext}`;
1023
- }
1024
-
1025
- // src/services/render/shared.ts
1026
1051
  var BROWSER_MEDIA_EPSILON = 1e-4;
1027
1052
  function resolveBrowserMediaEnd(start, end, duration) {
1028
1053
  return Number.isFinite(duration) && duration > 0 ? start + duration : end;
@@ -1049,7 +1074,7 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
1049
1074
  writeFileSync(join3(compileDir, "index.html"), compiled.html, "utf-8");
1050
1075
  for (const [srcPath, html] of compiled.subCompositions) {
1051
1076
  const outPath = join3(compileDir, srcPath);
1052
- if (!isPathInside2(outPath, compileDir)) {
1077
+ if (!isPathInside(outPath, compileDir)) {
1053
1078
  console.warn(`[Render] Skipping sub-composition with unsafe path: ${srcPath}`);
1054
1079
  continue;
1055
1080
  }
@@ -1058,7 +1083,7 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
1058
1083
  }
1059
1084
  for (const [relativePath, absolutePath] of compiled.externalAssets) {
1060
1085
  const outPath = resolve3(join3(compileDir, relativePath));
1061
- if (!isPathInside2(outPath, compileDir)) {
1086
+ if (!isPathInside(outPath, compileDir)) {
1062
1087
  console.warn(`[Render] Skipping external asset with unsafe path: ${relativePath}`);
1063
1088
  continue;
1064
1089
  }
@@ -1269,7 +1294,7 @@ function materializeExtractedFramesForCompiledDir(extracted, compiledDir, option
1269
1294
  const compiledFrameRoot = pathModule.join(resolvedCompiledDir, "__hyperframes_video_frames");
1270
1295
  for (const ext of extracted) {
1271
1296
  const resolvedOut = pathModule.resolve(ext.outputDir);
1272
- if (isPathInside2(resolvedOut, resolvedCompiledDir, { pathModule })) continue;
1297
+ if (isPathInside(resolvedOut, resolvedCompiledDir, { pathModule })) continue;
1273
1298
  const linkPath = pathModule.join(compiledFrameRoot, mediaIdPathSegment(ext.videoId));
1274
1299
  if (!fileSystem.existsSync(linkPath)) {
1275
1300
  fileSystem.mkdirSync(pathModule.dirname(linkPath), { recursive: true });
@@ -2196,7 +2221,7 @@ import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolu
2196
2221
  import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
2197
2222
  import { createHash as createHash5 } from "node:crypto";
2198
2223
  import { createReadStream as createReadStream2, existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync5 } from "fs";
2199
- import { join as join9, dirname as dirname6, resolve as resolve6, basename as basename3, relative as relative2, sep as sep2 } from "path";
2224
+ import { join as join9, dirname as dirname6, resolve as resolve6, basename as basename3, relative as relative2, sep as sep3 } from "path";
2200
2225
  import { parseHTML as parseHTML5 } from "linkedom";
2201
2226
 
2202
2227
  // src/services/bundledScripts.ts
@@ -2461,7 +2486,7 @@ import {
2461
2486
 
2462
2487
  // src/services/animatedGifPrep.ts
2463
2488
  import { createHash as createHash3 } from "node:crypto";
2464
- import { copyFileSync as copyFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
2489
+ import { copyFileSync as copyFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync3 } from "node:fs";
2465
2490
  import { dirname as dirname4, isAbsolute as isAbsolute2, join as join6, resolve as resolve4 } from "node:path";
2466
2491
  import { parseHTML as parseHTML3 } from "linkedom";
2467
2492
  import { parseAnimatedGifMetadata } from "@hyperframes/core";
@@ -2509,12 +2534,12 @@ function resolveLocalImageSourcePath(src, options) {
2509
2534
  ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve4(options.projectDir, projectRelative)],
2510
2535
  resolve4(options.downloadDir, normalizedBase)
2511
2536
  ];
2512
- const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) || !escapesAssetRoot(candidate, options.downloadDir);
2537
+ const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir);
2513
2538
  return candidates.find((candidate) => existsSync5(candidate) && allowed(candidate)) ?? null;
2514
2539
  }
2515
2540
  function isUsableFile(path) {
2516
2541
  try {
2517
- const stat = statSync2(path);
2542
+ const stat = statSync3(path);
2518
2543
  return stat.isFile() && stat.size > 0;
2519
2544
  } catch {
2520
2545
  return false;
@@ -2778,7 +2803,7 @@ import {
2778
2803
  readFileSync as readFileSync4,
2779
2804
  readSync,
2780
2805
  rmSync as rmSync3,
2781
- statSync as statSync3,
2806
+ statSync as statSync4,
2782
2807
  writeFileSync as writeFileSync2
2783
2808
  } from "node:fs";
2784
2809
  import { dirname as dirname5, join as join7, resolve as resolve5 } from "node:path";
@@ -3021,7 +3046,7 @@ function resolveImageSource(src, options) {
3021
3046
  }
3022
3047
  function isUsableFile2(path) {
3023
3048
  try {
3024
- return statSync3(path).size > 0;
3049
+ return statSync4(path).size > 0;
3025
3050
  } catch {
3026
3051
  return false;
3027
3052
  }
@@ -3155,6 +3180,11 @@ function dropMediaOutsideProject(input) {
3155
3180
  if (!src || isRemoteOrInlineSource(src)) return true;
3156
3181
  const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
3157
3182
  if (roots.some((root) => !escapesAssetRoot(path, root))) return true;
3183
+ if (input.allowOutsideProjectAssets) {
3184
+ const refusal = outsideAssetRefusal(projectDir, path);
3185
+ if (refusal) log.warn(`[Render] ${leftOutOfRender(`Media "${id}"`, src, refusal)}`);
3186
+ return refusal === null;
3187
+ }
3158
3188
  log.warn(`[Render] Media "${id}" source is missing: it is outside the project folder`, { src });
3159
3189
  return false;
3160
3190
  };
@@ -3281,7 +3311,7 @@ function normalizeCompositionSrcs(html, projectDir) {
3281
3311
  if (!value.includes("%") && !value.startsWith("/")) return whole;
3282
3312
  const file = resolveCompositionSrc(projectDir, value);
3283
3313
  if (file === null) return whole;
3284
- return `${name}${quote}${relative2(projectDir, file).split(sep2).join("/")}${quote}`;
3314
+ return `${name}${quote}${relative2(projectDir, file).split(sep3).join("/")}${quote}`;
3285
3315
  });
3286
3316
  }
3287
3317
  function resolveCompositionFile(projectDir, src, assetRoot) {
@@ -3302,6 +3332,10 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
3302
3332
  problems.push({ srcPath, detail: "it is outside the project folder" });
3303
3333
  continue;
3304
3334
  }
3335
+ if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
3336
+ problems.push({ srcPath, detail: "it is outside the project in a private location" });
3337
+ continue;
3338
+ }
3305
3339
  if (isPrivateCompositionFile(projectDir, filePath)) {
3306
3340
  problems.push({ srcPath, detail: "it is git metadata or an env file" });
3307
3341
  continue;
@@ -4007,17 +4041,24 @@ ${safeText}
4007
4041
  }
4008
4042
  return wrappedFragment ? document2.body.innerHTML || "" : document2.toString();
4009
4043
  }
4010
- function collectExternalAssets(html, projectDir) {
4044
+ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "index.html") {
4011
4045
  const absProjectDir = resolve6(projectDir);
4012
4046
  const externalAssets = /* @__PURE__ */ new Map();
4047
+ const leftOut2 = /* @__PURE__ */ new Set();
4013
4048
  function processPath(rawPath) {
4014
4049
  const trimmed = rawPath.trim();
4015
4050
  if (isNonRelativeUrl(trimmed)) return null;
4016
4051
  const absPath = resolve6(absProjectDir, trimmed);
4017
- if (isPathInside2(absPath, absProjectDir)) {
4052
+ if (isPathInside(absPath, absProjectDir)) {
4018
4053
  return null;
4019
4054
  }
4020
4055
  if (!existsSync7(absPath)) return null;
4056
+ const refusal = outsideAssetRefusal(absProjectDir, absPath);
4057
+ if (refusal) {
4058
+ if (!leftOut2.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
4059
+ leftOut2.add(trimmed);
4060
+ return null;
4061
+ }
4021
4062
  const safeKey = toExternalAssetKey(absPath);
4022
4063
  externalAssets.set(safeKey, absPath);
4023
4064
  return safeKey;
@@ -4263,13 +4304,13 @@ function projectStylesheetFontFamilies(html, projectDir) {
4263
4304
  const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
4264
4305
  if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
4265
4306
  const sheet = resolve6(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
4266
- if (!isPathInside2(sheet, projectDir) || !existsSync7(sheet)) continue;
4307
+ if (!isPathInside(sheet, projectDir) || !existsSync7(sheet)) continue;
4267
4308
  for (const face of extractFontFaceBlocks(readFileSync5(sheet, "utf8"))) {
4268
4309
  const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
4269
4310
  const shipsFile = [...face.matchAll(LOCAL_FONTFACE_URL_RE)].some(([, url = ""]) => {
4270
4311
  const path = decodedUrlPath(url);
4271
4312
  const file = path.startsWith("/") ? resolve6(projectDir, `.${path}`) : resolve6(dirname6(sheet), path);
4272
- return isPathInside2(file, projectDir) && existsSync7(file);
4313
+ return isPathInside(file, projectDir) && existsSync7(file);
4273
4314
  });
4274
4315
  if (family && shipsFile) families.push(family);
4275
4316
  }
@@ -4335,7 +4376,7 @@ async function readLocalFont(absPath) {
4335
4376
  }
4336
4377
  return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
4337
4378
  }
4338
- async function embedLocalFontFaces(html, projectDir, assetRoot) {
4379
+ async function embedLocalFontFaces(html, projectDir, assetRoot, log = defaultLogger) {
4339
4380
  const { fontToDataUri: toDataUri } = await import("@hyperframes/core/fonts/embed");
4340
4381
  const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
4341
4382
  const fontFaceRe = /@font-face\s*\{([^}]*)\}/gi;
@@ -4356,7 +4397,11 @@ async function embedLocalFontFaces(html, projectDir, assetRoot) {
4356
4397
  const localPath = urlMatch[1];
4357
4398
  if (!localPath || embeddedPaths.has(localPath)) continue;
4358
4399
  const absPath = localPath.startsWith("/") ? localPath : resolve6(projectDir, localPath);
4359
- if (!isPathInside2(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) continue;
4400
+ if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) continue;
4401
+ if (refusesOutsideLink(projectDir, absPath, (line) => log.warn(`[Compiler] ${line}`))) {
4402
+ embeddedPaths.add(localPath);
4403
+ continue;
4404
+ }
4360
4405
  const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
4361
4406
  try {
4362
4407
  if (fileBackedAbsolutePaths.has(absPath)) {
@@ -4420,7 +4465,7 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
4420
4465
  );
4421
4466
  }
4422
4467
  function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
4423
- if (!isPathInside2(htmlPath, projectDir)) return html;
4468
+ if (!isPathInside(htmlPath, projectDir)) return html;
4424
4469
  const entryPath = relative2(projectDir, htmlPath).replace(/\\/g, "/");
4425
4470
  if (!entryPath.includes("/")) return html;
4426
4471
  const { document: document2 } = parseHTML5(html);
@@ -4462,9 +4507,10 @@ function bindVariableMediaSources(html, variables) {
4462
4507
  }
4463
4508
  return changed ? document2.toString() : html;
4464
4509
  }
4510
+ var entryFileName = (projectDir, htmlPath) => isPathInside(htmlPath, projectDir) ? relative2(projectDir, htmlPath).split(sep3).join("/") : basename3(htmlPath);
4465
4511
  async function compileForRender(projectDir, htmlPath, downloadDir, options = {}) {
4466
4512
  const assetRoot = options.allowOutsideProjectAssets ? void 0 : projectDir;
4467
- if (isPathInside2(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
4513
+ if (isPathInside(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
4468
4514
  throw new Error(`Entry file ${htmlPath} leads outside the project folder`);
4469
4515
  }
4470
4516
  const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
@@ -4576,8 +4622,18 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
4576
4622
  if (preparedGifs.length > 0) {
4577
4623
  defaultLogger.debug(`[Compiler] Prepared ${preparedGifs.length} animated GIF input(s) as WebM`);
4578
4624
  }
4579
- const embeddedHtml = await embedLocalFontFaces(htmlWithPreparedGifs, projectDir, assetRoot);
4580
- const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(embeddedHtml, projectDir) : { html: embeddedHtml, externalAssets: /* @__PURE__ */ new Map() };
4625
+ const embeddedHtml = await embedLocalFontFaces(
4626
+ htmlWithPreparedGifs,
4627
+ projectDir,
4628
+ assetRoot,
4629
+ options.log
4630
+ );
4631
+ const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(
4632
+ embeddedHtml,
4633
+ projectDir,
4634
+ options.log,
4635
+ entryFileName(projectDir, htmlPath)
4636
+ ) : { html: embeddedHtml, externalAssets: /* @__PURE__ */ new Map() };
4581
4637
  for (const [relPath, absPath] of remoteMediaAssets) {
4582
4638
  externalAssets.set(relPath, absPath);
4583
4639
  }
@@ -5148,9 +5204,13 @@ async function runCompileStage(input) {
5148
5204
  width: compiled.width,
5149
5205
  height: compiled.height
5150
5206
  };
5151
- if (!job.config.allowOutsideProjectAssets) {
5152
- dropMediaOutsideProject({ projectDir, workDir, composition, log });
5153
- }
5207
+ dropMediaOutsideProject({
5208
+ projectDir,
5209
+ workDir,
5210
+ composition,
5211
+ log,
5212
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
5213
+ });
5154
5214
  await preflightCompositionAssetMediaTypes({
5155
5215
  projectDir,
5156
5216
  compiledDir: join10(workDir, "compiled"),
@@ -5775,9 +5835,13 @@ async function runProbeStage(input) {
5775
5835
  }
5776
5836
  }
5777
5837
  }
5778
- if (!job.config.allowOutsideProjectAssets) {
5779
- dropMediaOutsideProject({ projectDir, workDir, composition, log });
5780
- }
5838
+ dropMediaOutsideProject({
5839
+ projectDir,
5840
+ workDir,
5841
+ composition,
5842
+ log,
5843
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
5844
+ });
5781
5845
  await preflightCompositionAssetMediaTypes({
5782
5846
  projectDir,
5783
5847
  compiledDir: join11(workDir, "compiled"),
@@ -7554,7 +7618,7 @@ import {
7554
7618
  readdirSync as readdirSync2,
7555
7619
  readFileSync as readFileSync6,
7556
7620
  rmSync as rmSync4,
7557
- statSync as statSync4,
7621
+ statSync as statSync5,
7558
7622
  writeFileSync as writeFileSync4
7559
7623
  } from "node:fs";
7560
7624
  import { readFile as readFile2 } from "node:fs/promises";
@@ -7683,7 +7747,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
7683
7747
  const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
7684
7748
  if (failure) return failure;
7685
7749
  }
7686
- const fileSize = existsSync13(outputPath) ? statSync4(outputPath).size : 0;
7750
+ const fileSize = existsSync13(outputPath) ? statSync5(outputPath).size : 0;
7687
7751
  return {
7688
7752
  success: true,
7689
7753
  outputPath,
@@ -7937,7 +8001,7 @@ function sampleDirectoryBytes(dir) {
7937
8001
  for (const name of entries) {
7938
8002
  const full = join18(current, name);
7939
8003
  try {
7940
- const st = statSync5(full);
8004
+ const st = statSync6(full);
7941
8005
  if (st.isDirectory()) {
7942
8006
  stack.push(full);
7943
8007
  } else if (st.isFile()) {
@@ -8018,7 +8082,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
8018
8082
  let rangeStart = null;
8019
8083
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
8020
8084
  const framePath = join18(framesDir, formatCaptureFrameName(frameIndex, frameExt));
8021
- const missing = !existsSync14(framePath) || statSync5(framePath).size <= 8;
8085
+ const missing = !existsSync14(framePath) || statSync6(framePath).size <= 8;
8022
8086
  if (missing && rangeStart === null) {
8023
8087
  rangeStart = frameIndex;
8024
8088
  } else if (!missing && rangeStart !== null) {
@@ -10416,7 +10480,7 @@ function pathInside(root, path) {
10416
10480
  function stableSourcePath(roots, srcPath) {
10417
10481
  for (const [root, prefix] of roots) {
10418
10482
  const rel = pathInside(root, srcPath);
10419
- if (rel !== null) return [prefix, ...rel.split(sep3)].filter(Boolean).join("/");
10483
+ if (rel !== null) return [prefix, ...rel.split(sep4)].filter(Boolean).join("/");
10420
10484
  }
10421
10485
  return srcPath;
10422
10486
  }
@@ -10431,7 +10495,7 @@ function createVideoSourceShipper(input) {
10431
10495
  for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
10432
10496
  const rel = pathInside(root, srcPath);
10433
10497
  if (rel !== null && (existsSync19(join27(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
10434
- result = ["compiled", ...rel.split(sep3)].join("/");
10498
+ result = ["compiled", ...rel.split(sep4)].join("/");
10435
10499
  break;
10436
10500
  }
10437
10501
  }
@@ -10506,8 +10570,10 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
10506
10570
  filter: (src) => {
10507
10571
  const rel = relative6(projectDir, src);
10508
10572
  if (rel === "" || rel.startsWith("..")) return true;
10509
- if (!job.config.allowOutsideProjectAssets && !isSafePath2(projectDir, src)) return false;
10510
- const firstSegment = rel.split(sep3, 1)[0];
10573
+ if (job.config.allowOutsideProjectAssets) {
10574
+ if (refusesOutsideLink(projectDir, src, (line) => log.warn(`[Plan] ${line}`))) return false;
10575
+ } else if (!isSafePath2(projectDir, src)) return false;
10576
+ const firstSegment = rel.split(sep4, 1)[0];
10511
10577
  return firstSegment === void 0 || !PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(firstSegment);
10512
10578
  }
10513
10579
  });
@@ -10988,11 +11054,11 @@ import {
10988
11054
  readFileSync as readFileSync10,
10989
11055
  readdirSync as readdirSync7,
10990
11056
  rmSync as rmSync9,
10991
- statSync as statSync7,
11057
+ statSync as statSync8,
10992
11058
  writeFileSync as writeFileSync10
10993
11059
  } from "node:fs";
10994
11060
  import { tmpdir } from "node:os";
10995
- import { dirname as dirname14, isAbsolute as isAbsolute4, join as join30, relative as relative7, resolve as resolve9, sep as sep4 } from "node:path";
11061
+ import { dirname as dirname14, isAbsolute as isAbsolute4, join as join30, relative as relative7, resolve as resolve9, sep as sep5 } from "node:path";
10996
11062
  import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
10997
11063
  import {
10998
11064
  createFrameLookupTable as createFrameLookupTable5,
@@ -11007,7 +11073,7 @@ import {
11007
11073
  linkSync as linkSync2,
11008
11074
  mkdirSync as mkdirSync11,
11009
11075
  rmSync as rmSync8,
11010
- statSync as statSync6,
11076
+ statSync as statSync7,
11011
11077
  writeFileSync as writeFileSync9
11012
11078
  } from "node:fs";
11013
11079
  import { renameWithRetry as renameWithRetry9 } from "@hyperframes/engine";
@@ -11082,7 +11148,7 @@ var LocalPlanV2ArtifactPublisher = class {
11082
11148
  }
11083
11149
  async putBlob(blob) {
11084
11150
  const digest = assertPlanV2Sha256(blob.sha256, "published blob sha256");
11085
- const sourceSize = statSync6(blob.sourcePath).size;
11151
+ const sourceSize = statSync7(blob.sourcePath).size;
11086
11152
  if (sourceSize !== blob.sizeBytes) {
11087
11153
  throw new PlanV2IntegrityError(
11088
11154
  `published blob size changed for ${digest}: expected ${blob.sizeBytes}, got ${sourceSize}`
@@ -11164,7 +11230,7 @@ function listFiles(root) {
11164
11230
  walk(absolutePath);
11165
11231
  } else if (entry.isFile()) {
11166
11232
  files.push({
11167
- path: relative7(rootResolved, absolutePath).split(sep4).join("/"),
11233
+ path: relative7(rootResolved, absolutePath).split(sep5).join("/"),
11168
11234
  absolutePath
11169
11235
  });
11170
11236
  } else {
@@ -11204,7 +11270,7 @@ function isExtractionCacheCompleteSentinelPath(path) {
11204
11270
  function resolveExtractedVideoOutputDir(planDir, videoId) {
11205
11271
  const videoRoot = resolve9(planDir, "video-frames");
11206
11272
  const outputDir = resolve9(videoRoot, mediaIdPathSegment4(videoId));
11207
- if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${sep4}`)) {
11273
+ if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${sep5}`)) {
11208
11274
  throw new PlanV2IntegrityError(`unsafe extracted video id: ${JSON.stringify(videoId)}`);
11209
11275
  }
11210
11276
  return outputDir;
@@ -11364,7 +11430,7 @@ function collectChunkVideoDependencies(input) {
11364
11430
  for (let frame = chunk.startFrame; frame < chunk.endFrame; frame++) {
11365
11431
  const globalTime = frame * input.fpsDen / input.fpsNum;
11366
11432
  for (const [videoId, payload] of input.table.getActiveFramePayloads(globalTime)) {
11367
- const path = input.deferredSources.get(videoId) ?? relative7(resolve9(input.executionPlanDir), payload.framePath).split(sep4).join("/");
11433
+ const path = input.deferredSources.get(videoId) ?? relative7(resolve9(input.executionPlanDir), payload.framePath).split(sep5).join("/");
11368
11434
  assertSafeRelativePath(path);
11369
11435
  const indexes = mutable.get(path) ?? /* @__PURE__ */ new Set();
11370
11436
  indexes.add(chunk.index);
@@ -11396,7 +11462,7 @@ function publishBlobFor(absolutePath, digests) {
11396
11462
  return {
11397
11463
  sourcePath: absolutePath,
11398
11464
  sha256: planFileSha256(absolutePath, digests),
11399
- sizeBytes: statSync7(absolutePath).size
11465
+ sizeBytes: statSync8(absolutePath).size
11400
11466
  };
11401
11467
  }
11402
11468
  async function putBlobs(publisher, blobs) {
@@ -11764,7 +11830,7 @@ function verifyBlob(planV2Dir, artifact) {
11764
11830
  if (!existsSync21(sourcePath)) {
11765
11831
  throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
11766
11832
  }
11767
- const stats = statSync7(sourcePath);
11833
+ const stats = statSync8(sourcePath);
11768
11834
  if (!stats.isFile() || stats.size !== artifact.sizeBytes) {
11769
11835
  throw new PlanV2IntegrityError(`artifact size mismatch for ${artifact.path}`);
11770
11836
  }
@@ -11857,7 +11923,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
11857
11923
  for (const artifact of required) {
11858
11924
  if (Object.hasOwn(remoteSources, artifact.path)) continue;
11859
11925
  const path = join30(planDir, ...artifact.path.split("/"));
11860
- if (!existsSync21(path) || statSync7(path).size !== artifact.sizeBytes) {
11926
+ if (!existsSync21(path) || statSync8(path).size !== artifact.sizeBytes) {
11861
11927
  throw new PlanV2IntegrityError(
11862
11928
  `materialized artifact missing or truncated: ${artifact.path}`
11863
11929
  );
@@ -11886,7 +11952,7 @@ import {
11886
11952
  readFileSync as readFileSync11,
11887
11953
  readdirSync as readdirSync8,
11888
11954
  rmSync as rmSync10,
11889
- statSync as statSync8,
11955
+ statSync as statSync9,
11890
11956
  writeFileSync as writeFileSync11
11891
11957
  } from "node:fs";
11892
11958
  import { basename as basename6, dirname as dirname15, join as join31 } from "node:path";
@@ -11931,7 +11997,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
11931
11997
  outputPath,
11932
11998
  durationMs: Date.now() - start,
11933
11999
  framesEncoded: plan.totalFrames,
11934
- fileSize: statSync8(outputPath).size
12000
+ fileSize: statSync9(outputPath).size
11935
12001
  };
11936
12002
  }
11937
12003
  const format = plan.dimensions.format;
@@ -11978,7 +12044,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
11978
12044
  });
11979
12045
  }
11980
12046
  }
11981
- const fileSize = existsSync22(outputPath) ? statSync8(outputPath).size : 0;
12047
+ const fileSize = existsSync22(outputPath) ? statSync9(outputPath).size : 0;
11982
12048
  return {
11983
12049
  ...referenceBackgroundResult6(plan[REFERENCE_BACKGROUND_FIELD4]),
11984
12050
  outputPath,
@@ -12176,7 +12242,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
12176
12242
  mkdirSync13(outputPath, { recursive: true });
12177
12243
  let globalIdx = 0;
12178
12244
  for (const chunkDir of chunkPaths) {
12179
- if (!statSync8(chunkDir).isDirectory()) {
12245
+ if (!statSync9(chunkDir).isDirectory()) {
12180
12246
  throw new Error(
12181
12247
  `[assemble] png-sequence chunk must be a directory: ${chunkDir} (got a file)`
12182
12248
  );
@@ -12203,7 +12269,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
12203
12269
  let fileSize = 0;
12204
12270
  for (const name of readdirSync8(outputPath)) {
12205
12271
  try {
12206
- fileSize += statSync8(join31(outputPath, name)).size;
12272
+ fileSize += statSync9(join31(outputPath, name)).size;
12207
12273
  } catch {
12208
12274
  }
12209
12275
  }
@@ -13255,7 +13321,7 @@ function validateIntDimension(field, value) {
13255
13321
  }
13256
13322
 
13257
13323
  // src/services/distributed/projectHash.ts
13258
- import { closeSync as closeSync5, openSync as openSync5, readdirSync as readdirSync10, readSync as readSync4, realpathSync as realpathSync2, statSync as statSync9 } from "node:fs";
13324
+ import { closeSync as closeSync5, openSync as openSync5, readdirSync as readdirSync10, readSync as readSync4, realpathSync as realpathSync2, statSync as statSync10 } from "node:fs";
13259
13325
  import { createHash as createHash9 } from "node:crypto";
13260
13326
  import { join as join34 } from "node:path";
13261
13327
  var SITE_ID_SCHEME = "site-v2\0";
@@ -13272,7 +13338,7 @@ function listSiteFiles(projectDir) {
13272
13338
  const relPath = rel === "" ? name : `${rel}/${name}`;
13273
13339
  let stat;
13274
13340
  try {
13275
- stat = statSync9(full);
13341
+ stat = statSync10(full);
13276
13342
  } catch (err) {
13277
13343
  throw new Error(`[listSiteFiles] cannot read ${relPath} (dangling symlink?)`, {
13278
13344
  cause: err