AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): Validate and sanitize cron expressions for scheduler API (#10719)
Nicholas Tindlee0520f5e0ae9
diff --git a/autogpt_platform/frontend/src/components/cron-scheduler-dialog.tsx b/autogpt_platform/frontend/src/components/cron-scheduler-dialog.tsxindex aba09ff71e..aa92013ac2 100644--- a/autogpt_platform/frontend/src/components/cron-scheduler-dialog.tsx+++ b/autogpt_platform/frontend/src/components/cron-scheduler-dialog.tsx@@ -39,6 +39,17 @@ export function CronSchedulerDialog({});return;}++ // Validate cron expression before proceeding+ if (!cronExpression || cronExpression.trim() === "") {+ toast({+ variant: "destructive",+ title: "Invalid schedule",+ description: "Please enter a valid cron expression",+ });+ return;+ }+afterCronCreation(cronExpression, scheduleName);setOpen(false);};diff --git a/autogpt_platform/frontend/src/components/cron-scheduler.tsx b/autogpt_platform/frontend/src/components/cron-scheduler.tsxindex ffdca181e8..4f522de444 100644--- a/autogpt_platform/frontend/src/components/cron-scheduler.tsx+++ b/autogpt_platform/frontend/src/components/cron-scheduler.tsx@@ -213,6 +213,11 @@ export function CronScheduler({</Button>))}</div>+ {selectedWeekDays.length === 0 && (+ <p className="text-sm text-red-500">+ Please select at least one day of the week+ </p>+ )}</div>)}{frequency === "monthly" && (@@ -274,6 +279,11 @@ export function CronScheduler({))}</div>)}+ {selectedMonthDays.length === 0 && (+ <p className="text-sm text-red-500">+ Please select at least one day of the month+ </p>+ )}</div>)}{frequency === "yearly" && (@@ -287,7 +297,9 @@ export function CronScheduler({if (selectedMonths.length === months.length) {setSelectedMonths([]);} else {- setSelectedMonths(Array.from({ length: 12 }, (_, i) => i));+ setSelectedMonths(+ Array.from({ length: 12 }, (_, i) => i + 1),+ );}}}>@@ -319,6 +331,11 @@ export function CronScheduler({);})}</div>+ {selectedMonths.length === 0 && (+ <p className="text-sm text-red-500">+ Please select at least one month+ </p>+ )}</div>)}diff --git a/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsxindex 5b1990f716..d6616e5419 100644--- a/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx+++ b/autogpt_platform/frontend/src/hooks/useAgentGraph.tsx@@ -872,6 +872,16 @@ export default function useAgentGraph() => {if (!savedAgent || isScheduling) return;+ // Validate cron expression+ if (!cronExpression || cronExpression.trim() === "") {+ toast({+ variant: "destructive",+ title: "Invalid schedule",+ description: "Please enter a valid cron expression",+ });+ return;+ }+setIsScheduling(true);try {await api.createGraphExecutionSchedule({@@ -891,7 +901,7 @@ export default function useAgentGraph(router.push("/monitoring");}} catch (error) {- console.error(error);+ console.error("Error scheduling agent:", error);toast({variant: "destructive",title: "Error scheduling agent",diff --git a/autogpt_platform/frontend/src/lib/cron-expression-utils.ts b/autogpt_platform/frontend/src/lib/cron-expression-utils.tsindex 7a85082cc4..fc5b9df6d1 100644--- a/autogpt_platform/frontend/src/lib/cron-expression-utils.ts+++ b/autogpt_platform/frontend/src/lib/cron-expression-utils.ts@@ -49,16 +49,19 @@ export function makeCronExpression(params: CronExpressionParams): string {if (frequency === "daily") return `${params.minute} ${params.hour} * * *`;if (frequency === "weekly") {const { minute, hour, days } = params;+ if (days.length === 0) return ""; // Return empty string for invalid weekly scheduleconst weekDaysExpr = days.sort((a, b) => a - b).join(",");return `${minute} ${hour} * * ${weekDaysExpr}`;}if (frequency === "monthly") {const { minute, hour, days } = params;+ if (days.length === 0) return ""; // Return empty string for invalid monthly scheduleconst monthDaysExpr = days.sort((a, b) => a - b).join(",");return `${minute} ${hour} ${monthDaysExpr} * *`;}if (frequency === "yearly") {const { minute, hour, months } = params;+ if (months.length === 0) return ""; // Return empty string for invalid yearly scheduleconst monthList = months.sort((a, b) => a - b).join(",");return `${minute} ${hour} 1 ${monthList} *`;}