summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorZane Helton <zane99@me.com>2025-06-27 22:23:10 -0400
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2025-06-28 17:08:00 +1000
commitc0f9c22e67f33e9b12eca33432c4a2a849e0c20e (patch)
treef56b192eb193af02040c612a23bceb5d77baa293 /src/api
parentupdate webrtc types package (diff)
downloadserver-ts-c0f9c22e67f33e9b12eca33432c4a2a849e0c20e.tar.xz
Add validation to date_of_birth registration field
Resolves: #1020
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/auth/register.ts18
1 files 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",