fix: render file servers refuse env and Git files; shown-box sampling stays within the render (#7765)

* fix(producer): shown-box sampling stays within the validated render duration

Sampling where each oversized video is drawn stepped through the authored
start and end in 0.25 s float steps with no bound, before the render
duration was checked. An enormous start never advanced the step, and an
unbounded end grew the sample set until memory ran out.

The render duration is now validated first, each window is cut at the
composition's end, a window that is not finite is skipped, and the loop
counts integer steps. Building the sample list happens inside the
measurement's try, so any failure falls back to full-size extraction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: render and capture file servers refuse env files and Git data

The producer render file server, the engine file server and the CLI
static project server served every regular file under the project to the
page, including `.env*` files and anything under `.git`. Compile already
refuses to inline those files, and Studio preview and play refuse to
serve them.

All three now answer 404 for them through the shared isVcsOrSecretPath
rule, checked on the requested name and on a link's target, with the
case and Windows spelling variants it already covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michael Wang
2026-11-14 23:36:46 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 0e767d620f
commit 603395c89a
9 changed files with 121 additions and 11 deletions
@@ -690,3 +690,23 @@ describe("serveStaticProjectHtml when a sandbox refuses listen()", () => {
});
});
});
describe("serveStaticProjectHtml private project files", () => {
it.each([".env", ".env.local", ".git/config", "%2egit/config"])(
"answers %s with 404",
async (requestPath) => {
dir = mkdtempSync(join(tmpdir(), "hf-static-private-"));
mkdirSync(join(dir, ".git"));
writeFileSync(join(dir, ".env"), "SECRET=1");
writeFileSync(join(dir, ".env.local"), "SECRET=1");
writeFileSync(join(dir, ".git", "config"), "SECRET=1");
writeFileSync(join(dir, "asset.txt"), "ok");
server = await serveStaticProjectHtml(dir, "<html></html>");
const res = await fetch(`${server.url}${requestPath}`);
expect(res.status).toBe(404);
expect(await res.text()).not.toContain("SECRET");
expect((await fetch(`${server.url}asset.txt`)).status).toBe(200);
},
);
});
@@ -2,6 +2,7 @@ import { createServer, request as httpRequest, type Server, type ServerResponse
import { Duplex } from "node:stream";
import { createReadStream, existsSync, readFileSync, statSync } from "node:fs";
import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
import { isAbsolute, relative, resolve } from "node:path";
import {
PREVIEW_PROXY_BOX_PARAM,
@@ -330,6 +331,7 @@ export async function serveStaticProjectHtml(
const filePath = resolve(root, requestPath);
const rel = relative(root, filePath);
if (rel.startsWith("..") || isAbsolute(rel)) continue; // traversal guard; try next root
if (isPrivateFileUnder(root, filePath, isVcsOrSecretPath)) continue;
if (existsSync(filePath)) {
if (proxyRequest) {
void serveProxyRequest(
@@ -61,3 +61,27 @@ describe("fileServer path containment", () => {
expect(await response.text()).toContain("<html>");
});
});
describe("fileServer private project files", () => {
it.each(["/.env", "/.Env.local", "/.git/config", "/%2egit/config"])(
"answers %s with 404",
async (requestPath) => {
const projectDir = fs.mkdtempSync(path.join(tmpdir(), "hf-fileserver-private-"));
fs.mkdirSync(path.join(projectDir, ".git"));
fs.writeFileSync(path.join(projectDir, ".env"), "SECRET=1");
fs.writeFileSync(path.join(projectDir, ".Env.local"), "SECRET=1");
fs.writeFileSync(path.join(projectDir, ".git", "config"), "SECRET=1");
fs.writeFileSync(path.join(projectDir, "asset.txt"), "ok");
const server = await createFileServer({ headScripts: [], bodyScripts: [], projectDir });
try {
const response = await fetch(`${server.url}${requestPath}`);
expect(response.status).toBe(404);
expect(await response.text()).not.toContain("SECRET");
expect((await fetch(`${server.url}/asset.txt`)).status).toBe(200);
} finally {
server.close();
fs.rmSync(projectDir, { recursive: true, force: true });
}
},
);
});
@@ -11,6 +11,7 @@ import { serve } from "@hono/node-server";
import { readFileSync, openSync, fstatSync, closeSync, statSync, constants } from "node:fs";
import { join, extname } from "node:path";
import { injectScriptsIntoHtml } from "@hyperframes/core/compiler";
import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
import { isWithinProjectRoot } from "@hyperframes/parsers/asset-resolution";
const MIME_TYPES: Record<string, string> = {
@@ -98,9 +99,11 @@ function resolveContainedPaths(
): { projectPath: string; compiledPath: string | null } | null {
const projectPath = join(projectDir, relativePath);
if (!isWithinProjectRoot(projectDir, projectPath)) return null;
if (isPrivateFileUnder(projectDir, projectPath, isVcsOrSecretPath)) return null;
if (!compiledDir) return { projectPath, compiledPath: null };
const compiledPath = join(compiledDir, relativePath);
if (!isWithinProjectRoot(compiledDir, compiledPath)) return null;
if (isPrivateFileUnder(compiledDir, compiledPath, isVcsOrSecretPath)) return null;
return { projectPath, compiledPath };
}
@@ -1133,3 +1133,33 @@ describe("createFileServer colour-tagged PNGs", () => {
}
});
});
describe("createFileServer private project files", () => {
it.each(["/.env", "/.ENV.local", "/.env.production", "/.git/config", "/%2egit/HEAD", "/.envrc"])(
"answers %s with 404 and keeps ordinary assets",
async (requestPath) => {
const projectDir = mkdtempSync(join(tmpdir(), "hf-fs-private-"));
try {
writeEmptyIndex(projectDir);
mkdirSync(join(projectDir, ".git"));
for (const name of [".env", ".ENV.local", ".env.production", ".envrc"]) {
writeFileSync(join(projectDir, name), "SECRET=1");
}
writeFileSync(join(projectDir, ".git", "config"), "SECRET=1");
writeFileSync(join(projectDir, ".git", "HEAD"), "SECRET=1");
writeFileSync(join(projectDir, "asset.txt"), "ok");
symlinkSync(join(projectDir, ".env"), join(projectDir, "linked.txt"));
await withFileServer(projectDir, async (server) => {
const response = await fetch(`${server.url}${requestPath}`);
expect(response.status).toBe(404);
expect(await response.text()).not.toContain("SECRET");
const linked = await fetch(`${server.url}/linked.txt`);
expect(linked.status).toBe(404);
expect((await fetch(`${server.url}/asset.txt`)).status).toBe(200);
});
} finally {
rmSync(projectDir, { recursive: true, force: true });
}
},
);
});
@@ -29,6 +29,7 @@ import { Readable } from "node:stream";
import { join, extname, resolve, sep } from "node:path";
import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
import { fpsToNumber, type Fps } from "@hyperframes/core";
import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
import { openRangeEnd } from "@hyperframes/studio-server/media-range";
import { getVerifiedHyperframeRuntimeSource } from "./hyperframeRuntimeLoader.js";
@@ -830,6 +831,7 @@ export function createFileServer(options: FileServerOptions): Promise<FileServer
const candidate = join(root, relativePath);
const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
if (!isPathInside(candidate, root, { resolveSymlinks })) continue;
if (isPrivateFileUnder(root, candidate, isVcsOrSecretPath)) continue;
const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
file = openRegularFile(candidate);
@@ -46,16 +46,30 @@ function page(ranges: unknown, error?: Error): Page {
describe("shownBoxTimes", () => {
it("samples each video from its first frame every 0.25 s to its last frame", () => {
expect(shownBoxTimes([video("a", 1, 2)], fps)).toEqual([1, 1.25, 1.5, 1.75, 2 - 1 / 30]);
expect(shownBoxTimes([video("a", 1, 2)], fps, 10)).toEqual([1, 1.25, 1.5, 1.75, 2 - 1 / 30]);
});
it("merges the times of several videos once each, in order", () => {
expect(shownBoxTimes([video("a", 0, 0.5), video("b", 0.25, 0.5)], fps)).toEqual([
expect(shownBoxTimes([video("a", 0, 0.5), video("b", 0.25, 0.5)], fps, 10)).toEqual([
0,
0.25,
0.5 - 1 / 30,
]);
});
it("cuts each window at the composition's end", () => {
expect(shownBoxTimes([video("a", 0.5, Number.POSITIVE_INFINITY)], fps, 1)).toEqual([
0.5,
0.75,
1 - 1 / 30,
]);
expect(shownBoxTimes([video("a", 0, 1e12)], fps, 0.5)).toEqual([0, 0.25, 0.5 - 1 / 30]);
});
it("returns promptly for a start too large for the stride to advance", () => {
expect(shownBoxTimes([video("a", 2 ** 53, 2 ** 54)], fps, 10)).toEqual([]);
expect(shownBoxTimes([video("a", Number.NaN, 1)], fps, 10)).toEqual([]);
});
});
describe("measureLocalShownBoxes", () => {
@@ -71,6 +85,7 @@ describe("measureLocalShownBoxes", () => {
]),
[video("still", 0, 1), video("zoom", 0, 1)],
fps,
1,
log,
);
expect(Object.fromEntries(boxes!)).toEqual({
@@ -90,6 +105,7 @@ describe("measureLocalShownBoxes", () => {
page(undefined, new Error("Target closed")),
[video("clip", 0, 1)],
fps,
1,
log,
);
expect(boxes).toBeUndefined();
@@ -35,16 +35,21 @@ export async function oversizedVideos(
return videos.filter((_, index) => sized[index]);
}
/** Each video's first and last frame and every stride between, in composition seconds, ascending. */
/** Each video's first and last frame before `duration` and every stride between, in seconds, ascending. */
export function shownBoxTimes(
videos: readonly VideoElement[],
fps: { num: number; den: number },
duration: number,
): number[] {
const frame = fps.den / fps.num;
const times = new Set<number>();
for (const { start, end } of videos) {
for (const { start, end: authoredEnd } of videos) {
const end = Math.min(authoredEnd, duration);
if (!Number.isFinite(start) || !Number.isFinite(end) || start > end) continue;
const last = Math.max(start, end - frame);
for (let t = start; t < last; t += SHOWN_BOX_STRIDE_S) times.add(t);
for (let step = 0; start + step * SHOWN_BOX_STRIDE_S < last; step += 1) {
times.add(start + step * SHOWN_BOX_STRIDE_S);
}
times.add(last);
}
return [...times].sort((a, b) => a - b);
@@ -58,11 +63,13 @@ export async function measureLocalShownBoxes(
page: Page,
videos: readonly VideoElement[],
fps: { num: number; den: number },
duration: number,
log: ProducerLogger,
): Promise<Map<string, ShownBox> | undefined> {
const times = shownBoxTimes(videos, fps);
let times: number[] = [];
const startedAt = Date.now();
try {
times = shownBoxTimes(videos, fps, duration);
const ranges = await measureVideoShownBoxRanges(
page,
videos.map((video) => video.id),
@@ -3477,11 +3477,6 @@ async function executeRenderPipeline(input: {
compositionHash = computeCompositionObservabilityHash(compiled.html);
fileServer = probeResult.fileServer;
probeSession = probeResult.probeSession;
// Before the video layer may close the probe page; no box means full size, as before.
const shownBoxes =
largerThanCanvas.length > 0 && probeSession?.isInitialized
? await measureLocalShownBoxes(probeSession.page, largerThanCanvas, job.config.fps, log)
: undefined;
job.strictVariablesChecked = probeResult.strictVariablesChecked;
lastBrowserConsole = probeResult.lastBrowserConsole;
let resolvedCaptureBeyondViewport = probeSession?.options.captureBeyondViewport;
@@ -3499,6 +3494,17 @@ async function executeRenderPipeline(input: {
totalFrames,
fps: fpsToNumber(job.config.fps),
});
// Before the video layer may close the probe page; no box means full size, as before.
const shownBoxes =
largerThanCanvas.length > 0 && probeSession?.isInitialized
? await measureLocalShownBoxes(
probeSession.page,
largerThanCanvas,
job.config.fps,
probeResult.duration,
log,
)
: undefined;
perfStages.browserProbeMs = probeResult.browserProbeMs;
perfStages.compileMs = Date.now() - stage1Start;