Skip to content

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

fix: parse input

Marc Seitz8ccd7e086259
diff --git a/ee/features/workflows/components/step-form-dialog.tsx b/ee/features/workflows/components/step-form-dialog.tsx
index b01251be..3e5f8fef 100644
--- a/ee/features/workflows/components/step-form-dialog.tsx
+++ b/ee/features/workflows/components/step-form-dialog.tsx
@@ -1,6 +1,7 @@
import { useState } from "react";
import { toast } from "sonner";
+import { z } from "zod";
import { cn } from "@/lib/utils";
@@ -126,6 +127,21 @@ export function StepFormDialog({
return;
}
+ // Validate IDs to prevent SSRF
+ const workflowIdValidation = z.string().cuid().safeParse(workflowId);
+ if (!workflowIdValidation.success) {
+ toast.error("Invalid workflow ID");
+ return;
+ }
+
+ if (step) {
+ const stepIdValidation = z.string().cuid().safeParse(step.id);
+ if (!stepIdValidation.success) {
+ toast.error("Invalid step ID");
+ return;
+ }
+ }
+
setIsSubmitting(true);
try {
diff --git a/ee/features/workflows/components/workflow-header.tsx b/ee/features/workflows/components/workflow-header.tsx
index 67ca657d..2dba3d0e 100644
--- a/ee/features/workflows/components/workflow-header.tsx
+++ b/ee/features/workflows/components/workflow-header.tsx
@@ -1,6 +1,7 @@
import { useState } from "react";
import { useRouter } from "next/router";
import { toast } from "sonner";
+import { z } from "zod";
import { TrashIcon, CopyIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Switch } from "@/components/ui/switch";
@@ -36,6 +37,13 @@ export function WorkflowHeader({
const [isDeleting, setIsDeleting] = useState(false);
const handleToggleActive = async () => {
+ // Validate workflowId to prevent SSRF
+ const workflowIdValidation = z.string().cuid().safeParse(workflowId);
+ if (!workflowIdValidation.success) {
+ toast.error("Invalid workflow ID");
+ return;
+ }
+
try {
const response = await fetch(`/api/workflows/${workflowId}`, {
method: "PATCH",
@@ -59,6 +67,14 @@ export function WorkflowHeader({
};
const handleDeleteWorkflow = async () => {
+ // Validate workflowId to prevent SSRF
+ const workflowIdValidation = z.string().cuid().safeParse(workflowId);
+ if (!workflowIdValidation.success) {
+ toast.error("Invalid workflow ID");
+ setShowDeleteDialog(false);
+ return;
+ }
+
setIsDeleting(true);
try {
diff --git a/ee/features/workflows/pages/workflow-detail.tsx b/ee/features/workflows/pages/workflow-detail.tsx
index 6a834c48..07b15aed 100644
--- a/ee/features/workflows/pages/workflow-detail.tsx
+++ b/ee/features/workflows/pages/workflow-detail.tsx
@@ -1,6 +1,7 @@
import { useRouter } from "next/router";
import { useState } from "react";
+import { z } from "zod";
import { useTeam } from "@/context/team-context";
import { toast } from "sonner";
@@ -73,17 +74,25 @@ export default function WorkflowDetailPage() {
const [showStepDialog, setShowStepDialog] = useState(false);
const [editingStep, setEditingStep] = useState<WorkflowStep | null>(null);
+ // Validate IDs to prevent SSRF
+ const validWorkflowId =
+ workflowId && z.string().cuid().safeParse(workflowId).success
+ ? workflowId
+ : null;
+ const validTeamId =
+ teamId && z.string().cuid().safeParse(teamId).success ? teamId : null;
+
const {
data: workflow,
error,
mutate,
} = useSWR<Workflow>(
- workflowId ? `/api/workflows/${workflowId}` : null,
+ validWorkflowId ? `/api/workflows/${validWorkflowId}` : null,
fetcher,
);
const { data: links } = useSWR<Link[]>(
- teamId ? `/api/teams/${teamId}/workflow-links` : null,
+ validTeamId ? `/api/teams/${validTeamId}/workflow-links` : null,
fetcher,
);
@@ -96,6 +105,15 @@ export default function WorkflowDetailPage() {
};
const handleDeleteStep = async (stepId: string) => {
+ // Validate IDs to prevent SSRF
+ const workflowIdValidation = z.string().cuid().safeParse(workflowId);
+ const stepIdValidation = z.string().cuid().safeParse(stepId);
+
+ if (!workflowIdValidation.success || !stepIdValidation.success) {
+ toast.error("Invalid workflow or step ID");
+ return;
+ }
+
try {
const response = await fetch(
`/api/workflows/${workflowId}/steps/${stepId}`,
@@ -169,9 +187,9 @@ export default function WorkflowDetailPage() {
</div>
{/* Step Form Dialog */}
- {showStepDialog && (
+ {showStepDialog && validWorkflowId && (
<StepFormDialog
- workflowId={workflowId}
+ workflowId={validWorkflowId}
step={editingStep}
links={links || []}
open={showStepDialog}