1
mirror of https://github.com/thepeacockproject/Peacock synced 2024-11-22 22:12:45 +01:00

[Security] Intentionally remove prototypes from objects being cloned

Signed-off-by: Reece Dunham <me@rdil.rocks>
This commit is contained in:
Reece Dunham 2022-10-22 21:30:36 -04:00
parent b4bb032c99
commit 34789f8ff2

View File

@ -346,20 +346,15 @@ export function fastClone<T>(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