From 6e86fafa5e0373a53deccd1008242800021a321d Mon Sep 17 00:00:00 2001 From: Omar Elshenhabi Date: Mon, 29 Sep 2025 01:15:51 +0300 Subject: [PATCH] fix: improve domain and letsencrypt email validation --- .../dashboard/settings/web-domain.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/dokploy/components/dashboard/settings/web-domain.tsx b/apps/dokploy/components/dashboard/settings/web-domain.tsx index cafb95f53..fdf479816 100644 --- a/apps/dokploy/components/dashboard/settings/web-domain.tsx +++ b/apps/dokploy/components/dashboard/settings/web-domain.tsx @@ -33,9 +33,19 @@ import { import { Switch } from "@/components/ui/switch"; import { api } from "@/utils/api"; +const hostnameRegex = + /^(?=.{1,253}$)(?!-)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.(?!-)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/; + const addServerDomain = z .object({ - domain: z.string(), + domain: z + .string() + .trim() + .toLowerCase() + .regex( + hostnameRegex, + "Invalid hostname (no http://, no slash, no port).", + ), letsEncryptEmail: z.string(), https: z.boolean().optional(), certificateType: z.enum(["letsencrypt", "none", "custom"]), @@ -48,7 +58,11 @@ const addServerDomain = z message: "Required", }); } - if (data.certificateType === "letsencrypt" && !data.letsEncryptEmail) { + if ( + data.https && + data.certificateType === "letsencrypt" && + !data.letsEncryptEmail + ) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: