fix: prototype pollution in deserializer (#2255)

This is not exploitable in practice unless a user maliciously crafts
serialized values in __FRSH_STATE, because `serializer()` never outputs
serialized representation that would be vulnerable to prototype
pollution. But hey, defense in depth.
This commit is contained in:
Luca Casonato
2024-01-15 18:03:59 +00:00
committed by GitHub
parent 3bc43a1327
commit 8583394481
3 changed files with 43 additions and 12 deletions
+19 -1
View File
@@ -1,7 +1,12 @@
// deno-lint-ignore-file no-explicit-any
import { serialize } from "./serializer.ts";
import { assert, assertEquals, assertSnapshot } from "../../tests/deps.ts";
import {
assert,
assertEquals,
assertSnapshot,
assertThrows,
} from "../../tests/deps.ts";
import { deserialize, KEY } from "../runtime/deserializer.ts";
import { signal } from "@preact/signals-core";
import { signal as signal130 } from "@preact/signals-core@1.3.0";
@@ -213,3 +218,16 @@ Deno.test("serializer - multiple reference in signal", async (t) => {
assertEquals(deserialized.s.peek(), inner);
assertEquals(deserialized.inner, inner);
});
Deno.test("deserializer - no prototype pollution with manual input", () => {
const serialized = String.raw`{
"v": {
"*": ["onerror"]
},
"r": [
[["*"], ["constructor", "prototype", "*"]]
]
}`;
assertThrows(() => deserialize(serialized, signal));
assertEquals({}.constructor.prototype["*"], undefined);
});