Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: Add authorization check to verify the user has access to the run
Marc Seitz5fab56a07a24
diff --git a/app/(ee)/api/ai/store/runs/[runId]/route.ts b/app/(ee)/api/ai/store/runs/[runId]/route.tsindex cd93d35f..02a88d2a 100644--- a/app/(ee)/api/ai/store/runs/[runId]/route.ts+++ b/app/(ee)/api/ai/store/runs/[runId]/route.ts@@ -2,6 +2,8 @@ import { runs } from "@trigger.dev/sdk/v3";import { NextRequest, NextResponse } from "next/server";import { authOptions } from "@/pages/api/auth/[...nextauth]";+import prisma from "@/lib/prisma";+import { CustomUser } from "@/lib/types";import { getServerSession } from "next-auth";/**@@ -23,6 +25,18 @@ export async function GET(const run = await runs.retrieve(runId);+ // Verify the user is authorized to access this run+ const runTeamId = run.metadata?.teamId as string | undefined;+ const userTeams = await prisma.userTeam.findMany({+ where: { userId: (session.user as CustomUser).id },+ select: { teamId: true },+ });+ const userTeamIds = userTeams.map((ut) => ut.teamId);++ if (!runTeamId || !userTeamIds.includes(runTeamId)) {+ return NextResponse.json({ error: "Unauthorized" }, { status: 403 });+ }+return NextResponse.json({id: run.id,status: run.status,