From b1cd19df2fb9ae47ecc90a68e789607f7f0a3d7e Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 8 Oct 2022 10:31:21 -0400 Subject: [PATCH] Improve error handling on cookie parsing, closes #4246 --- server/utils/authentication.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/utils/authentication.ts b/server/utils/authentication.ts index ca0560c27..a2efde3a8 100644 --- a/server/utils/authentication.ts +++ b/server/utils/authentication.ts @@ -16,9 +16,13 @@ import { User, Event, Team, Collection, View } from "@server/models"; * @returns The session details */ export function getSessionsInCookie(ctx: Context) { - return JSON.parse( - decodeURIComponent(ctx.cookies.get("sessions") || "") || "{}" - ); + try { + const sessionCookie = ctx.cookies.get("sessions") || ""; + const decodedSessionCookie = decodeURIComponent(sessionCookie); + return decodedSessionCookie ? JSON.parse(decodedSessionCookie) : {}; + } catch (err) { + return {}; + } } export async function signIn(