From d8eb517a9c11b4d343971615c354e2bd1ec4b277 Mon Sep 17 00:00:00 2001 From: Vedant Madane <6527493+VedantMadane@users.noreply.github.com> Date: Mon, 24 Aug 2026 23:28:55 +0530 Subject: [PATCH] fix: fix: reject grace values outside 0-7 with validation error - Schema previously clamped grace>7 with Math.min and returned 200. - Now add a Zod issue so out-of-range grace fails validation (400) instead of silent coercion. Fixes #1241 Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com> --- lib/validations.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/validations.ts b/lib/validations.ts index 9f9a8b82b..364ab6d7c 100644 --- a/lib/validations.ts +++ b/lib/validations.ts @@ -569,11 +569,18 @@ const baseStreakParamsSchema = z.object({ grace: z .string() .optional() - .transform((val) => { + .transform((val, ctx) => { if (val === undefined || val === '') return 1; const n = Number(val); if (isNaN(n) || !Number.isInteger(n)) return 1; - return Math.min(7, Math.max(0, n)); + if (n < 0 || n > 7) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'grace must be an integer between 0 and 7', + }); + return z.NEVER; + } + return n; }) .default(1),