From 34789f8ff2f2ea49322885e333467754868a7fe0 Mon Sep 17 00:00:00 2001 From: Reece Dunham Date: Sat, 22 Oct 2022 21:30:36 -0400 Subject: [PATCH] [Security] Intentionally remove prototypes from objects being cloned Signed-off-by: Reece Dunham --- components/utils.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/components/utils.ts b/components/utils.ts index 212535c8..a62d23cd 100644 --- a/components/utils.ts +++ b/components/utils.ts @@ -346,20 +346,15 @@ export function fastClone(item: T): T { result[index] = fastClone(child) }) } else if (typeof item === "object") { - // @ts-expect-error JavaScript built-in things. - if (!item.prototype) { - // this is a literal - if (item instanceof Date) { - result = new Date(item) - } else { - // object literal - result = {} - for (const i in item) { - result[i] = fastClone(item[i]) - } - } + // this is a literal + if (item instanceof Date) { + result = new Date(item) } else { - result = item + // object literal + result = {} + for (const i in item) { + result[i] = fastClone(item[i]) + } } } else { result = item