From 81d49d8e94ba9dde2d3de13ef559eddfe5c1233d Mon Sep 17 00:00:00 2001 From: Leonabcd123 <156839416+Leonabcd123@users.noreply.github.com> Date: Tue, 10 Mar 2026 13:52:50 +0200 Subject: [PATCH] Add validation for ape keys --- .../src/ts/elements/account-settings/ape-key-table.ts | 8 +++++++- packages/schemas/src/ape-keys.ts | 10 ++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/src/ts/elements/account-settings/ape-key-table.ts b/frontend/src/ts/elements/account-settings/ape-key-table.ts index bd32d0efc48a..ea3c137c35b1 100644 --- a/frontend/src/ts/elements/account-settings/ape-key-table.ts +++ b/frontend/src/ts/elements/account-settings/ape-key-table.ts @@ -4,7 +4,11 @@ import { showSuccessNotification, } from "../../stores/notifications"; import Ape from "../../ape"; -import { ApeKey, ApeKeys } from "@monkeytype/schemas/ape-keys"; +import { + ApeKey, + ApeKeys, + ApeKeyNameSchema, +} from "@monkeytype/schemas/ape-keys"; import { format } from "date-fns/format"; import { SimpleModal, TextArea } from "../../utils/simple-modal"; import { isAuthenticated } from "../../firebase"; @@ -18,6 +22,7 @@ const editApeKey = new SimpleModal({ type: "text", placeholder: "name", initVal: "", + validation: { schema: ApeKeyNameSchema }, }, ], buttonText: "edit", @@ -129,6 +134,7 @@ const generateApeKey = new SimpleModal({ type: "text", placeholder: "Name", initVal: "", + validation: { schema: ApeKeyNameSchema }, }, ], buttonText: "generate", diff --git a/packages/schemas/src/ape-keys.ts b/packages/schemas/src/ape-keys.ts index 609e37d93e1e..146c4cc658a1 100644 --- a/packages/schemas/src/ape-keys.ts +++ b/packages/schemas/src/ape-keys.ts @@ -1,11 +1,13 @@ import { z } from "zod"; import { IdSchema } from "./util"; +export const ApeKeyNameSchema = z + .string() + .regex(/^[0-9a-zA-Z_.-]+$/) + .max(20); + export const ApeKeyUserDefinedSchema = z.object({ - name: z - .string() - .regex(/^[0-9a-zA-Z_.-]+$/) - .max(20), + name: ApeKeyNameSchema, enabled: z.boolean(), });