Skip to content

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

feat: add trustedTeam to skip check

Marc Seitz1da556cca970
diff --git a/lib/api/documents/process-document.ts b/lib/api/documents/process-document.ts
index 4ac35ff1..8fa4be4a 100644
--- a/lib/api/documents/process-document.ts
+++ b/lib/api/documents/process-document.ts
@@ -2,6 +2,7 @@ import { get } from "@vercel/edge-config";
import { parsePageId } from "notion-utils";
import { DocumentData } from "@/lib/documents/create-document";
+import { isTrustedTeam } from "@/lib/edge-config/trusted-teams";
import { copyFileToBucketServer } from "@/lib/files/copy-file-to-bucket-server";
import notion from "@/lib/notion";
import { getNotionPageIdFromSlug } from "@/lib/notion/utils";
@@ -81,19 +82,23 @@ export const processDocument = async ({
try {
new URL(key);
- const keywords = await get("keywords");
- if (Array.isArray(keywords) && keywords.length > 0) {
- const matchedKeyword = keywords.find(
- (keyword) => typeof keyword === "string" && key.includes(keyword),
- );
+ // Skip keyword check for trusted teams
+ const trusted = await isTrustedTeam(teamId);
+ if (!trusted) {
+ const keywords = await get("keywords");
+ if (Array.isArray(keywords) && keywords.length > 0) {
+ const matchedKeyword = keywords.find(
+ (keyword) => typeof keyword === "string" && key.includes(keyword),
+ );
- if (matchedKeyword) {
- log({
- message: `Link document creation blocked: ${matchedKeyword} \n\n \`Metadata: {teamId: ${teamId}, url: ${key}}\``,
- type: "error",
- mention: true,
- });
- throw new Error("This URL is not allowed");
+ if (matchedKeyword) {
+ log({
+ message: `Link document creation blocked: ${matchedKeyword} \n\n \`Metadata: {teamId: ${teamId}, url: ${key}}\``,
+ type: "error",
+ mention: true,
+ });
+ throw new Error("This URL is not allowed");
+ }
}
}
} catch (error) {
diff --git a/lib/edge-config/trusted-teams.ts b/lib/edge-config/trusted-teams.ts
new file mode 100644
index 00000000..fff67749
--- /dev/null
+++ b/lib/edge-config/trusted-teams.ts
@@ -0,0 +1,20 @@
+import { get } from "@vercel/edge-config";
+
+export const isTrustedTeam = async (teamId: string): Promise<boolean> => {
+ if (!process.env.EDGE_CONFIG) {
+ return false;
+ }
+
+ let trustedTeams: string[] = [];
+ try {
+ const result = await get("trustedTeams");
+ trustedTeams = Array.isArray(result)
+ ? result.filter((item): item is string => typeof item === "string")
+ : [];
+ } catch (e) {
+ // Already initialized as empty array
+ }
+
+ if (trustedTeams.length === 0) return false;
+ return trustedTeams.includes(teamId);
+};
diff --git a/lib/trigger/pdf-to-image-route.ts b/lib/trigger/pdf-to-image-route.ts
index a225a003..071d5794 100644
--- a/lib/trigger/pdf-to-image-route.ts
+++ b/lib/trigger/pdf-to-image-route.ts
@@ -1,5 +1,6 @@
import { AbortTaskRunError, logger, task } from "@trigger.dev/sdk/v3";
+import { isTrustedTeam } from "@/lib/edge-config/trusted-teams";
import { getFile } from "@/lib/files/get-file";
import prisma from "@/lib/prisma";
import { updateStatus } from "@/lib/utils/generate-trigger-status";
@@ -126,6 +127,9 @@ export const convertPdfToImageRoute = task({
}
}
+ // Check once if this team is trusted (skips keyword checks for all pages)
+ const trustedTeam = await isTrustedTeam(teamId);
+
updateStatus({ progress: 20, text: "Converting document..." });
// 4. iterate through pages and upload to blob in a task
@@ -154,6 +158,7 @@ export const convertPdfToImageRoute = task({
pageNumber: currentPage,
url: signedUrl,
teamId: teamId,
+ trustedTeam: trustedTeam,
}),
headers: {
"Content-Type": "application/json",
diff --git a/pages/api/mupdf/convert-page.ts b/pages/api/mupdf/convert-page.ts
index c3ac07ef..3ae4b368 100644
--- a/pages/api/mupdf/convert-page.ts
+++ b/pages/api/mupdf/convert-page.ts
@@ -31,12 +31,14 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
return;
}
- const { documentVersionId, pageNumber, url, teamId } = req.body as {
- documentVersionId: string;
- pageNumber: number;
- url: string;
- teamId: string;
- };
+ const { documentVersionId, pageNumber, url, teamId, trustedTeam } =
+ req.body as {
+ documentVersionId: string;
+ pageNumber: number;
+ url: string;
+ teamId: string;
+ trustedTeam?: boolean;
+ };
try {
// Fetch the PDF data
@@ -168,8 +170,8 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
return { href: link.getURI(), coords, isInternal: false };
});
- // Check embedded links for blocked keywords
- if (embeddedLinks.length > 0) {
+ // Check embedded links for blocked keywords (skip for trusted teams)
+ if (embeddedLinks.length > 0 && !trustedTeam) {
try {
const keywords = await get("keywords");
if (Array.isArray(keywords) && keywords.length > 0) {
diff --git a/pages/api/teams/[teamId]/documents/[id]/update-link-url.ts b/pages/api/teams/[teamId]/documents/[id]/update-link-url.ts
index 28c74f25..e8733672 100644
--- a/pages/api/teams/[teamId]/documents/[id]/update-link-url.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/update-link-url.ts
@@ -4,6 +4,7 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { get } from "@vercel/edge-config";
import { getServerSession } from "next-auth/next";
+import { isTrustedTeam } from "@/lib/edge-config/trusted-teams";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
import { log } from "@/lib/utils";
@@ -81,24 +82,27 @@ export default async function handle(
return res.status(400).json({ message: "Document has no versions" });
}
- // Check if URL contains blocked keywords
- const keywords = await get("keywords");
- if (Array.isArray(keywords) && keywords.length > 0) {
- const matchedKeyword = keywords.find(
- (keyword) =>
- typeof keyword === "string" && validatedUrl.includes(keyword),
- );
-
- if (matchedKeyword) {
- log({
- message: `Link URL update blocked: ${matchedKeyword} \n\n \`Metadata: {teamId: ${teamId}, documentId: ${documentId}, url: ${validatedUrl}}\``,
- type: "error",
- mention: true,
- });
- return res.status(400).json({
- message: "This URL is not allowed",
- matchedKeyword: matchedKeyword,
- });
+ // Check if URL contains blocked keywords (skip for trusted teams)
+ const trusted = await isTrustedTeam(teamId);
+ if (!trusted) {
+ const keywords = await get("keywords");
+ if (Array.isArray(keywords) && keywords.length > 0) {
+ const matchedKeyword = keywords.find(
+ (keyword) =>
+ typeof keyword === "string" && validatedUrl.includes(keyword),
+ );
+
+ if (matchedKeyword) {
+ log({
+ message: `Link URL update blocked: ${matchedKeyword} \n\n \`Metadata: {teamId: ${teamId}, documentId: ${documentId}, url: ${validatedUrl}}\``,
+ type: "error",
+ mention: true,
+ });
+ return res.status(400).json({
+ message: "This URL is not allowed",
+ matchedKeyword: matchedKeyword,
+ });
+ }
}
}
diff --git a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
index 05c1371b..8c6c3ae5 100644
--- a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
@@ -154,17 +154,6 @@ export default async function handle(
},
});
- // turn off isPrimary flag for all other versions
- await prisma.documentVersion.updateMany({
- where: {
- documentId: documentId,
- id: { not: version.id },
- },
- data: {
- isPrimary: false,
- },
- });
-
if (type === "docs" || type === "slides") {
await convertFilesToPdfTask.trigger(
{