Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(web): tighten folder access checks for personal and space folders
Richie McIlroy97c3abc7e7ae
diff --git a/apps/web/actions/folders/add-videos.ts b/apps/web/actions/folders/add-videos.tsindex debaeaa41..2bd4b2b6d 100644--- a/apps/web/actions/folders/add-videos.ts+++ b/apps/web/actions/folders/add-videos.ts@@ -48,12 +48,12 @@ export async function addVideosToFolder(// space folders require space-admin or org admin/owner access.if (folder.spaceId === null) {if (folder.createdById !== user.id) {- throw new Error("You don't have permission to manage this folder");+ throw new Error("Folder not found");}} else {const access = await getSpaceAccess(user.id, folder.spaceId);if (!access?.canManage) {- throw new Error("You don't have permission to manage this folder");+ throw new Error("Folder not found");}}diff --git a/apps/web/actions/folders/get-folder-videos.ts b/apps/web/actions/folders/get-folder-videos.tsindex 84e02b019..ad7881147 100644--- a/apps/web/actions/folders/get-folder-videos.ts+++ b/apps/web/actions/folders/get-folder-videos.ts@@ -5,7 +5,6 @@ import { getCurrentUser } from "@cap/database/auth/session";import { folders, sharedVideos, spaceVideos } from "@cap/database/schema";import type { Folder, Space, Video } from "@cap/web-domain";import { eq } from "drizzle-orm";-import { getOrganizationAccess } from "@/actions/organization/authorization";import { getSpaceAccess } from "@/actions/organization/space-authorization";export async function getFolderVideoIds(@@ -38,11 +37,10 @@ export async function getFolderVideoIds(}if (folder.spaceId === null) {- const access = await getOrganizationAccess(- user.id,- folder.organizationId,- );- if (!access && folder.createdById !== user.id) {+ // Personal folders are creator-only (mirrors FoldersPolicy.canEdit and+ // add-videos.ts); org membership must NOT grant access to another user's+ // personal folder.+ if (folder.createdById !== user.id) {throw new Error("Folder not found");}} else {diff --git a/apps/web/actions/folders/moveVideoToFolder.ts b/apps/web/actions/folders/moveVideoToFolder.tsindex 47424b72e..8dbcd46ca 100644--- a/apps/web/actions/folders/moveVideoToFolder.ts+++ b/apps/web/actions/folders/moveVideoToFolder.ts@@ -13,6 +13,7 @@ import { and, eq } from "drizzle-orm";import { revalidatePath } from "next/cache";import { requireOrganizationSettingsManager } from "@/actions/organization/authorization";import { getSpaceAccess } from "@/actions/organization/space-authorization";+export async function moveVideoToFolder({videoId,folderId,diff --git a/apps/web/app/(org)/dashboard/folder/[id]/page.tsx b/apps/web/app/(org)/dashboard/folder/[id]/page.tsxindex 0601cc08c..5b8d42655 100644--- a/apps/web/app/(org)/dashboard/folder/[id]/page.tsx+++ b/apps/web/app/(org)/dashboard/folder/[id]/page.tsx@@ -4,7 +4,7 @@ import { makeCurrentUserLayer } from "@cap/web-backend";import { Folder } from "@cap/web-domain";import { Effect } from "effect";import { notFound } from "next/navigation";-import { getOrganizationAccess } from "@/actions/organization/authorization";+import { getSpaceAccess } from "@/actions/organization/space-authorization";import {getChildFolders,getFolderBreadcrumb,@@ -32,22 +32,31 @@ const FolderPage = async (props: PageProps<"/dashboard/folder/[id]">) => {const user = await getCurrentUser();if (!user || !user.activeOrganizationId) return notFound();- // Ensure the folder belongs to a space/org the caller can access before+ // Ensure the folder belongs to a space the caller can access before// disclosing its contents (mirrors FoldersPolicy: personal folders are- // creator-only, space/org folders require org membership/ownership).+ // creator-only, space folders require space/org membership). A missing folder+ // surfaces as notFound() rather than an unhandled 500.const folderForAccess = await getFolderById(folderId).pipe(Effect.provide(makeCurrentUserLayer(user)),+ Effect.catchAll(() => Effect.succeed(null)),runPromise,);+ if (!folderForAccess) return notFound();+if (folderForAccess.spaceId === null) {if (folderForAccess.createdById !== user.id) return notFound();} else {- const access = await getOrganizationAccess(- user.id,- folderForAccess.organizationId,- );- if (!access) return notFound();+ // getSpaceAccess returns a non-null object even for non-members (both roles+ // null), so check for an actual role. Using space access (not org-only)+ // keeps legitimate space members who aren't org members from being blocked.+ const access = await getSpaceAccess(user.id, folderForAccess.spaceId);+ if (+ !access ||+ (access.organizationRole === null && access.spaceRole === null)+ ) {+ return notFound();+ }}return Effect.gen(function* () {