Skip to content

Commit fa671e5

Browse files
committed
fix(security): Follow up on CVE-2020-28477 where path: [["__proto__"], "x"] could still pollute the prototype
1 parent 2e0aa95 commit fa671e5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

__tests__/patch.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,24 @@ test("maps can store __proto__, prototype and constructor props", () => {
12581258
expect(obj.polluted).toBe(undefined)
12591259
})
12601260

1261+
test("CVE-2020-28477 (https://snyk.io/vuln/SNYK-JS-IMMER-1019369) follow up", () => {
1262+
const obj = {}
1263+
1264+
// @ts-ignore
1265+
expect(obj.polluted).toBe(undefined)
1266+
expect(() => {
1267+
applyPatches({}, [
1268+
{op: "add", path: [["__proto__"], "polluted"], value: "yes"}
1269+
])
1270+
}).toThrow(
1271+
isProd
1272+
? "24"
1273+
: "Patching reserved attributes like __proto__, prototype and constructor is not allowed"
1274+
)
1275+
// @ts-ignore
1276+
expect(obj.polluted).toBe(undefined)
1277+
})
1278+
12611279
test("#648 assigning object to itself should not change patches", () => {
12621280
const input = {
12631281
obj: {

src/plugins/patches.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export function enablePatches() {
207207
let base: any = draft
208208
for (let i = 0; i < path.length - 1; i++) {
209209
const parentType = getArchtype(base)
210-
const p = path[i]
210+
const p = "" + path[i]
211211
// See #738, avoid prototype pollution
212212
if (
213213
(parentType === Archtype.Object || parentType === Archtype.Array) &&

0 commit comments

Comments
 (0)