Create polished demo videos without editing skills. Mac/Windows/Linux
fix(media): approve loopback video paths when minting URLs
wiiiii123326f56840ef1
diff --git a/electron/ipc/project/manager.test.ts b/electron/ipc/project/manager.test.tsindex 375d0f9d..33606541 100644--- a/electron/ipc/project/manager.test.ts+++ b/electron/ipc/project/manager.test.ts@@ -73,4 +73,18 @@ describe("local media path policy", () => {await expect(isAllowedLocalMediaPath(pendingExportPath)).resolves.toBe(true);});++ it("approves media-server access for existing external files resolved through the URL policy", async () => {+ const downloadsPath = path.join(tempRoot, "Downloads");+ const videoPath = path.join(downloadsPath, "external-video.mp4");+ await fs.mkdir(downloadsPath, { recursive: true });+ await fs.writeFile(videoPath, "test-video");++ const { resolveApprovedLocalMediaPath } = await import("./manager");+ const { isAllowedMediaPath } = await import("../../mediaServer");++ expect(isAllowedMediaPath(videoPath)).toBe(false);+ await expect(resolveApprovedLocalMediaPath(videoPath)).resolves.toBe(videoPath);+ expect(isAllowedMediaPath(videoPath)).toBe(true);+ });});diff --git a/electron/ipc/project/manager.ts b/electron/ipc/project/manager.tsindex e13127f6..67e3dead 100644--- a/electron/ipc/project/manager.ts+++ b/electron/ipc/project/manager.ts@@ -83,6 +83,22 @@ export async function rememberApprovedLocalReadPath(filePath?: string | null) {}}+export async function resolveApprovedLocalMediaPath(candidatePath: string): Promise<string | null> {+ const normalizedCandidatePath = normalizePath(candidatePath);+ const realPath = await fs.realpath(normalizedCandidatePath).catch(() => null);++ if (!realPath) {+ return null;+ }++ if (!(await isAllowedLocalMediaPath(realPath))) {+ return null;+ }++ await rememberApprovedLocalReadPath(realPath);+ return realPath;+}+export async function replaceApprovedSessionLocalReadPaths(filePaths: Array<string | null | undefined>) {approvedLocalReadPaths.clear();await Promise.all(filePaths.map((filePath) => rememberApprovedLocalReadPath(filePath)));diff --git a/electron/ipc/register/project.ts b/electron/ipc/register/project.tsindex 29f138dc..94c25b56 100644--- a/electron/ipc/register/project.ts+++ b/electron/ipc/register/project.ts@@ -20,7 +20,6 @@ import {import {getProjectsDir,getProjectThumbnailPath,- isAllowedLocalMediaPath,isPathInsideDirectory,isTrustedProjectPath,listProjectLibraryEntries,@@ -28,6 +27,7 @@ import {loadProjectFromPath,persistRecordingsDirectorySetting,replaceApprovedSessionLocalReadPaths,+ resolveApprovedLocalMediaPath,rememberRecentProject,saveRecentProjectPaths,saveProjectThumbnail,@@ -622,15 +622,10 @@ export function registerProjectHandlers() {if (!baseUrl || !filePath) {return { success: false as const };}- const normalized = path.resolve(filePath);- let resolved: string;- try {- resolved = await fs.realpath(normalized);- } catch {- return { success: false as const };- }- if (!(await isAllowedLocalMediaPath(resolved))) {- console.warn(`[get-local-media-url] Blocked disallowed path: ${resolved}`);+ const resolved = await resolveApprovedLocalMediaPath(filePath);+ if (!resolved) {+ const normalized = path.resolve(filePath);+ console.warn(`[get-local-media-url] Blocked disallowed path: ${normalized}`);return { success: false as const };}return { success: true as const, url: buildMediaUrl(baseUrl, resolved) };diff --git a/electron/mediaServer.test.ts b/electron/mediaServer.test.tsnew file mode 100644index 00000000..f0effc57--- /dev/null+++ b/electron/mediaServer.test.ts@@ -0,0 +1,72 @@+import fs from "node:fs/promises";+import os from "node:os";+import path from "node:path";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++describe("media server path policy", () => {+ let tempRoot: string;+ let appDataPath: string;+ let userDataPath: string;+ let tempPath: string;+ let appPath: string;++ beforeEach(async () => {+ tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "recordly-media-server-"));+ appDataPath = path.join(tempRoot, "AppData");+ userDataPath = path.join(tempRoot, "UserData");+ tempPath = path.join(tempRoot, "Temp");+ appPath = path.join(tempRoot, "App");++ await Promise.all(+ [appDataPath, userDataPath, tempPath, appPath].map((dirPath) =>+ fs.mkdir(dirPath, { recursive: true }),+ ),+ );++ vi.resetModules();+ vi.doMock("electron", () => ({+ app: {+ isPackaged: false,+ getAppPath: () => appPath,+ getPath: (name: string) => {+ if (name === "appData") return appDataPath;+ if (name === "userData") return userDataPath;+ if (name === "temp") return tempPath;+ return tempRoot;+ },+ setPath: () => undefined,+ },+ }));+ });++ afterEach(async () => {+ vi.resetModules();+ vi.doUnmock("electron");+ if (tempRoot) {+ await fs.rm(tempRoot, { recursive: true, force: true });+ }+ });++ it("rejects existing media files outside the session directories until they are approved", async () => {+ const downloadsPath = path.join(tempRoot, "Downloads");+ const videoPath = path.join(downloadsPath, "personal-video.mp4");+ await fs.mkdir(downloadsPath, { recursive: true });+ await fs.writeFile(videoPath, "test-video");++ const { isAllowedMediaPath } = await import("./mediaServer");+ const { rememberApprovedLocalReadPath } = await import("./ipc/project/manager");++ expect(isAllowedMediaPath(videoPath)).toBe(false);++ await rememberApprovedLocalReadPath(videoPath);++ expect(isAllowedMediaPath(videoPath)).toBe(true);+ });++ it("rejects missing media files outside the allowed directories", async () => {+ const missingPath = path.join(tempRoot, "Downloads", "missing.mp4");+ const { isAllowedMediaPath } = await import("./mediaServer");++ expect(isAllowedMediaPath(missingPath)).toBe(false);+ });+});diff --git a/electron/mediaServer.ts b/electron/mediaServer.tsindex 2f790a97..ff783788 100644--- a/electron/mediaServer.ts+++ b/electron/mediaServer.ts@@ -33,7 +33,7 @@ async function resolveRealPath(filePath: string): Promise<string | null> {}}-function isAllowedMediaPath(realPath: string): boolean {+export function isAllowedMediaPath(realPath: string): boolean {return approvedLocalReadPaths.has(realPath);}