Skip to content

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

fix: safe parse params

Marc Seitz721562b7ced3
diff --git a/app/(ee)/api/workflows/[workflowId]/executions/route.ts b/app/(ee)/api/workflows/[workflowId]/executions/route.ts
index 6a21272d..ddd0a99f 100644
--- a/app/(ee)/api/workflows/[workflowId]/executions/route.ts
+++ b/app/(ee)/api/workflows/[workflowId]/executions/route.ts
@@ -19,9 +19,15 @@ export async function GET(
const { workflowId } = params;
const searchParams = req.nextUrl.searchParams;
- // Parse pagination parameters
- const page = parseInt(searchParams.get("page") || "1");
- const limit = Math.min(parseInt(searchParams.get("limit") || "20"), 100);
+ // Parse and validate pagination parameters
+ const rawPage = Number.parseInt(searchParams.get("page") || "1", 10);
+ const rawLimit = Number.parseInt(searchParams.get("limit") || "20", 10);
+
+ // Apply defaults for invalid values and enforce constraints
+ const page = Number.isNaN(rawPage) || rawPage < 1 ? 1 : rawPage;
+ const limit = Number.isNaN(rawLimit) || rawLimit < 1
+ ? 20
+ : Math.min(Math.max(rawLimit, 1), 100); // Min 1, Max 100
const skip = (page - 1) * limit;
// Validate workflowId format
diff --git a/pages/api/teams/[teamId]/documents/[id]/views/index.ts b/pages/api/teams/[teamId]/documents/[id]/views/index.ts
index 91293e77..b11a0ad0 100644
--- a/pages/api/teams/[teamId]/documents/[id]/views/index.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/views/index.ts
@@ -178,8 +178,16 @@ export default async function handle(
}
const { teamId, id: docId } = req.query as { teamId: string; id: string };
- const page = parseInt((req.query.page as string) || "1", 10);
- const limit = parseInt((req.query.limit as string) || "10", 10);
+
+ // Parse and validate pagination parameters
+ const rawPage = Number.parseInt((req.query.page as string) || "1", 10);
+ const rawLimit = Number.parseInt((req.query.limit as string) || "10", 10);
+
+ // Apply defaults for invalid values and enforce constraints
+ const page = Number.isNaN(rawPage) || rawPage < 1 ? 1 : rawPage;
+ const limit = Number.isNaN(rawLimit) || rawLimit < 1
+ ? 10
+ : Math.min(Math.max(rawLimit, 1), 100); // Min 1, Max 100
const offset = (page - 1) * limit;
const userId = (session.user as CustomUser).id;