Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

security: validate documentVersionId belongs to view's document in pages API

Cursor Agentf8d1e9992153
diff --git a/app/api/views/pages/route.ts b/app/api/views/pages/route.ts
index c390b5a8..fdb0a080 100644
--- a/app/api/views/pages/route.ts
+++ b/app/api/views/pages/route.ts
@@ -32,11 +32,10 @@ export async function POST(request: NextRequest) {
);
}
- // Validate viewId if provided (non-preview requests)
if (viewId) {
const view = await prisma.view.findUnique({
where: { id: viewId },
- select: { id: true },
+ select: { id: true, documentId: true },
});
if (!view) {
@@ -45,6 +44,19 @@ export async function POST(request: NextRequest) {
{ status: 404 },
);
}
+
+ // Verify the document version belongs to the document associated with this view
+ const documentVersion = await prisma.documentVersion.findUnique({
+ where: { id: documentVersionId },
+ select: { documentId: true },
+ });
+
+ if (!documentVersion || documentVersion.documentId !== view.documentId) {
+ return NextResponse.json(
+ { message: "Unauthorized access." },
+ { status: 403 },
+ );
+ }
}
const documentPages = await prisma.documentPage.findMany({