Skip to content
Myr

fix(security): Follow up on CVE-2020-28477 where `path: [["__proto__"], "x"]` could still pollute the prototype

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by Michel Weststrate · parent 2e0aa95 · Browse files · 2 files+19 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−1 removed

  • tests:+18 added−0 removed
  • other:+1 added−1 removed

2 files+19 added−1 removed

modified:__tests__/patch.js+18 added
1256 unmodified lines
1257 expect(newMap.get("prototype").polluted).toBe("yes")1258 expect(obj.polluted).toBe(undefined)1259})12601261test("CVE-2020-28477 (https://snyk.io/vuln/SNYK-JS-IMMER-1019369) follow up", () => {1262 const obj = {}12631264 // @ts-ignore1265 expect(obj.polluted).toBe(undefined)1266 expect(() => {1267 applyPatches({}, [1268 {op: "add", path: [["__proto__"], "polluted"], value: "yes"}1269 ])1270 }).toThrow(1271 isProd1272 ? "24"1273 : "Patching reserved attributes like __proto__, prototype and constructor is not allowed"1274 )1275 // @ts-ignore1276 expect(obj.polluted).toBe(undefined)1277})12781279test("#648 assigning object to itself should not change patches", () => {1280 const input = {1281 obj: {1282 value: 200
23 unmodified lines
modified:src/plugins/patches.ts+1 added-1 removed
205 unmodified lines
206207 let base: any = draft208 for (let i = 0; i < path.length - 1; i++) {209 const parentType = getArchtype(base)210 const p = path[i]210 const p = "" + path[i]211 // See #738, avoid prototype pollution212 if (213 (parentType === Archtype.Object || parentType === Archtype.Array) &&214 (p === "__proto__" || p === "constructor")
85 unmodified lines