Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: improve validation
Marc Seitzf626372294d8
diff --git a/lib/zod/url-validation.ts b/lib/zod/url-validation.tsindex c7e33c21..9d26dd2b 100644--- a/lib/zod/url-validation.ts+++ b/lib/zod/url-validation.ts@@ -57,6 +57,11 @@ export const validateUrlSSRFProtection = (url: string): boolean => {return false;}+ // Block IPv6 link-local addresses (fe80::/10)+ if (hostname.toLowerCase().startsWith("fe80:")) {+ return false;+ }+return true;} catch {return false;diff --git a/pages/api/teams/[teamId]/documents/agreement.ts b/pages/api/teams/[teamId]/documents/agreement.tsindex ddd8a7ea..1790b964 100644--- a/pages/api/teams/[teamId]/documents/agreement.ts+++ b/pages/api/teams/[teamId]/documents/agreement.ts@@ -54,7 +54,7 @@ export default async function handle(url: fileUrl,storageType,numPages,- type: fileType,+ type,folderPathName,fileSize,contentType,@@ -66,9 +66,6 @@ export default async function handle(userId,});- // Get passed type property or alternatively, the file extension and save it as the type- const type = fileType || getExtension(name);-const folder = await prisma.folder.findUnique({where: {teamId_path: {@@ -89,7 +86,7 @@ export default async function handle(file: fileUrl,originalFile: fileUrl,contentType,- type: type,+ type,storageType,ownerId: (session.user as CustomUser).id,teamId: teamId,@@ -106,7 +103,7 @@ export default async function handle(versions: {create: {file: fileUrl,- type: type,+ type,storageType,originalFile: fileUrl,contentType,diff --git a/pages/api/webhooks/services/[...path]/index.ts b/pages/api/webhooks/services/[...path]/index.tsindex fd65b735..1a6a6198 100644--- a/pages/api/webhooks/services/[...path]/index.ts+++ b/pages/api/webhooks/services/[...path]/index.ts@@ -290,7 +290,12 @@ async function handleDocumentCreate(// 5. Validate response content type matches expectedconst responseContentType = response.headers.get("content-type");- if (responseContentType && !responseContentType.startsWith(contentType)) {+ if (!responseContentType || responseContentType.startsWith("text/html")) {+ return res+ .status(400)+ .json({ error: "Remote resource is not a supported file type" });+ }+ if (!responseContentType.startsWith(contentType)) {console.warn(`Content type mismatch: expected ${contentType}, got ${responseContentType}`,);