Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix(api/views): close authorization bypass on POST /api/views
Marc Seitz9db429132acd
diff --git a/app/api/views/route.ts b/app/api/views/route.tsindex 50e6158a..b843caef 100644--- a/app/api/views/route.ts+++ b/app/api/views/route.ts@@ -40,7 +40,6 @@ export async function POST(request: NextRequest) {// POST /api/viewsconst {linkId,- documentId,userId,documentVersionId,documentName,@@ -50,7 +49,6 @@ export async function POST(request: NextRequest) {...data} = body as {linkId: string;- documentId: string;userId: string | null;documentVersionId: string;documentName: string;@@ -163,6 +161,41 @@ export async function POST(request: NextRequest) {);}+ if (!link.documentId) {+ return NextResponse.json(+ { message: "Unauthorized access." },+ { status: 403 },+ );+ }++ if (!documentVersionId || typeof documentVersionId !== "string") {+ return NextResponse.json(+ { message: "documentVersionId is required." },+ { status: 400 },+ );+ }++ const requestedVersion = await prisma.documentVersion.findUnique({+ where: { id: documentVersionId },+ select: { documentId: true },+ });++ if (!requestedVersion) {+ return NextResponse.json(+ { message: "Document version not found." },+ { status: 404 },+ );+ }++ if (requestedVersion.documentId !== link.documentId) {+ return NextResponse.json(+ { message: "Unauthorized access." },+ { status: 403 },+ );+ }++ const documentId = link.documentId;+let isEmailVerified: boolean = false;let hashedVerificationToken: string | null = null;// Check if the user is part of the team and therefore skip verification steps