From c0f9c22e67f33e9b12eca33432c4a2a849e0c20e Mon Sep 17 00:00:00 2001 From: Zane Helton Date: Fri, 27 Jun 2025 22:23:10 -0400 Subject: [PATCH] Add validation to date_of_birth registration field Resolves: #1020 --- src/api/routes/auth/register.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts index 62152440..9e9d2c98 100644 --- a/src/api/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts @@ -206,10 +206,24 @@ router.post( minimum.setFullYear( minimum.getFullYear() - register.dateOfBirth.minimum, ); - body.date_of_birth = new Date(body.date_of_birth as Date); + + let parsedDob; + try { + parsedDob = new Date(body.date_of_birth as Date); + if (isNaN(parsedDob.getTime())) { + throw new Error("Invalid date"); + } + } catch (e) { + throw FieldErrors({ + date_of_birth: { + code: "DATE_OF_BIRTH_INVALID", + message: req.t("auth:register.DATE_OF_BIRTH_INVALID"), + }, + }); + } // higher is younger - if (body.date_of_birth > minimum) { + if (parsedDob > minimum) { throw FieldErrors({ date_of_birth: { code: "DATE_OF_BIRTH_UNDERAGE",