From 89d756ef4e8987a15a55e1ef5751a2b299613aa9 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Sun, 19 Jan 2025 22:02:54 -0500 Subject: [PATCH] feat: csv validation --- api/src/types/my-servers-config.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/api/src/types/my-servers-config.ts b/api/src/types/my-servers-config.ts index a7c224e2d..36dea5e46 100644 --- a/api/src/types/my-servers-config.ts +++ b/api/src/types/my-servers-config.ts @@ -22,7 +22,23 @@ const RemoteConfigSchema = z.object({ idtoken: z.string(), refreshtoken: z.string(), dynamicRemoteAccessType: z.nativeEnum(DynamicRemoteAccessType), - ssoSubIds: z.string(), + ssoSubIds: z + .string() + .transform((val) => { + // If valid, return as is + if (val === '' || val.split(',').every((id) => id.trim().match(/^[a-zA-Z0-9-]+$/))) { + return val; + } + // Otherwise, replace with an empty string + return ''; + }) + .refine( + (val) => val === '' || val.split(',').every((id) => id.trim().match(/^[a-zA-Z0-9-]+$/)), + { + message: + 'ssoSubIds must be empty or a comma-separated list of alphanumeric strings with dashes', + } + ), }); const LocalConfigSchema = z.object({});