Skip to content

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

fix(links): reject views on expired links

Marc Seitz9d7db9e95f82
diff --git a/app/api/views-dataroom/route.ts b/app/api/views-dataroom/route.ts
index f7b8b4c7..8e3294dd 100644
--- a/app/api/views-dataroom/route.ts
+++ b/app/api/views-dataroom/route.ts
@@ -138,6 +138,7 @@ export async function POST(request: NextRequest) {
domainSlug: true,
isArchived: true,
deletedAt: true,
+ expiresAt: true,
slug: true,
domainId: true,
linkType: true,
@@ -214,6 +215,13 @@ export async function POST(request: NextRequest) {
);
}
+ if (link.expiresAt && new Date(link.expiresAt) < new Date()) {
+ return NextResponse.json(
+ { message: "Link has expired." },
+ { status: 404 },
+ );
+ }
+
if (link.dataroom?.isFrozen) {
return NextResponse.json(
{ message: "This data room has been closed." },
@@ -1310,8 +1318,8 @@ export async function POST(request: NextRequest) {
? await getFile({ data: page.file, type: storageType })
: null,
pageLinks: inWindow
- ? (await signPageLinks(otherPage.pageLinks)) ??
- otherPage.pageLinks
+ ? ((await signPageLinks(otherPage.pageLinks)) ??
+ otherPage.pageLinks)
: otherPage.pageLinks,
};
}),
diff --git a/app/api/views/route.ts b/app/api/views/route.ts
index 6d8bd091..ef83b611 100644
--- a/app/api/views/route.ts
+++ b/app/api/views/route.ts
@@ -121,6 +121,7 @@ export async function POST(request: NextRequest) {
domainSlug: true,
isArchived: true,
deletedAt: true,
+ expiresAt: true,
slug: true,
allowList: true,
denyList: true,
@@ -188,6 +189,13 @@ export async function POST(request: NextRequest) {
);
}
+ if (link.expiresAt && new Date(link.expiresAt) < new Date()) {
+ return NextResponse.json(
+ { message: "Link has expired." },
+ { status: 404 },
+ );
+ }
+
if (!link.documentId) {
return NextResponse.json(
{ message: "Unauthorized access." },
@@ -822,8 +830,8 @@ export async function POST(request: NextRequest) {
// Always sign overlay URLs alongside whichever pages we sign
// file URLs for; lazy-loaded pages re-sign via /api/views/pages.
pageLinks: inWindow
- ? (await signPageLinks(otherPage.pageLinks)) ??
- otherPage.pageLinks
+ ? ((await signPageLinks(otherPage.pageLinks)) ??
+ otherPage.pageLinks)
: otherPage.pageLinks,
};
}),
diff --git a/lib/api/links/link-data.ts b/lib/api/links/link-data.ts
index 1ed518b1..53479ea3 100644
--- a/lib/api/links/link-data.ts
+++ b/lib/api/links/link-data.ts
@@ -25,6 +25,7 @@ type LinkFetchStatus =
| "not_found"
| "archived"
| "deleted"
+ | "expired"
| "free"
| "frozen";
@@ -975,6 +976,10 @@ export async function fetchLinkDataById({
return { status: "archived" };
}
+ if (link.expiresAt && new Date(link.expiresAt) < new Date()) {
+ return { status: "expired" };
+ }
+
return processLinkData(link, { dataroomDocumentId, isCustomDomain: false });
}
@@ -1013,6 +1018,10 @@ export async function fetchLinkDataByDomainSlug({
return { status: "archived" };
}
+ if (link.expiresAt && new Date(link.expiresAt) < new Date()) {
+ return { status: "expired" };
+ }
+
return processLinkData(link, { dataroomDocumentId, isCustomDomain: true });
}