From afb7f4bd2e817d8686ac5ed5c1a1217dfea857af Mon Sep 17 00:00:00 2001 From: Jeremy Gallant <8975765+philon-@users.noreply.github.com> Date: Tue, 22 Jul 2025 16:01:31 +0200 Subject: [PATCH] Change chatId validation schema (#731) Fixes #715 Co-authored-by: philon- --- packages/web/src/routes.tsx | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/packages/web/src/routes.tsx b/packages/web/src/routes.tsx index e0c8dabe..b9f3d21a 100644 --- a/packages/web/src/routes.tsx +++ b/packages/web/src/routes.tsx @@ -14,7 +14,7 @@ import { redirect, } from "@tanstack/react-router"; import type { useTranslation } from "react-i18next"; -import { z } from "zod"; +import { z } from "zod/v4"; import { App } from "./App.tsx"; interface AppContext { @@ -55,23 +55,6 @@ const messagesRoute = createRoute({ }, }); -const chatIdSchema = z.string().refine( - (val) => { - const num = Number(val); - if (Number.isNaN(num) || !Number.isInteger(num)) { - return false; - } - - const isChannelId = num >= 0 && num <= 10; - const isNodeId = num >= 1000000000 && num <= 9999999999; - - return isChannelId || isNodeId; - }, - { - message: "Chat ID must be a channel (0-10) or a valid node ID.", - }, -); - export const messagesWithParamsRoute = createRoute({ getParentRoute: () => rootRoute, path: "/messages/$type/$chatId", @@ -83,7 +66,7 @@ export const messagesWithParamsRoute = createRoute({ message: 'Type must be "direct" or "broadcast".', }) .parse(params.type), - chatId: chatIdSchema.parse(params.chatId), + chatId: z.coerce.number().int().min(0).max(4294967294).parse(params.chatId), // max is 0xffffffff - 1 }), });