Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: relative url for downloads
Marc Seitzec5572777d01
diff --git a/components/view/dataroom/viewer-download-progress-modal.tsx b/components/view/dataroom/viewer-download-progress-modal.tsxindex 7823034d..21d971b5 100644--- a/components/view/dataroom/viewer-download-progress-modal.tsx+++ b/components/view/dataroom/viewer-download-progress-modal.tsx@@ -207,8 +207,17 @@ export function ViewerDownloadProgressModal({};const handleDownload = (url: string) => {+ // Ensure we use a relative path so the request goes to the current origin+ // (where the session cookie lives), not a potentially different subdomain.+ let href = url;+ try {+ const parsed = new URL(url, window.location.origin);+ href = parsed.pathname + parsed.search;+ } catch {+ // url is already relative, use as-is+ }const a = document.createElement("a");- a.href = url;+ a.href = href;a.rel = "noopener noreferrer";document.body.appendChild(a);a.click();diff --git a/pages/api/links/download/[jobId].ts b/pages/api/links/download/[jobId].tsindex ad8b2136..8f967b25 100644--- a/pages/api/links/download/[jobId].ts+++ b/pages/api/links/download/[jobId].ts@@ -46,20 +46,13 @@ export default async function handler(return res.status(403).json({ error: "Job does not belong to this viewer" });}- // Use the request's origin so download links work on custom domains- const rawProto = req.headers["x-forwarded-proto"];- const proto =- (Array.isArray(rawProto)- ? rawProto[0]- : rawProto?.split(",")[0]?.trim()) || "https";- const host = req.headers["host"] || "app.papermark.com";- const baseUrl = `${proto}://${host}`;-+ // Use relative URLs so the browser resolves them against the current page origin,+ // ensuring the session cookie (scoped to the page host) is always sent.const partCount = job.downloadUrls?.length ?? 0;const proxyDownloadUrls =job.status === "COMPLETED" && partCount > 0? Array.from({ length: partCount }, (_, i) =>- `${baseUrl}/api/links/download/file/${jobId}/${i}?linkId=${encodeURIComponent(linkId)}`,+ `/api/links/download/file/${jobId}/${i}?linkId=${encodeURIComponent(linkId)}`,): undefined;