Skip to content
Permalink
Browse files
fix(security): Follow up on CVE-2020-28477 where `path: [["__proto__"…
…], "x"]` could still pollute the prototype
  • Loading branch information
mweststrate committed Aug 31, 2021
1 parent 2e0aa95 commit fa671e55ee9bd42ae08cc239102b665a23958237
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
@@ -1258,6 +1258,24 @@ test("maps can store __proto__, prototype and constructor props", () => {
expect(obj.polluted).toBe(undefined)
})

test("CVE-2020-28477 (https://snyk.io/vuln/SNYK-JS-IMMER-1019369) follow up", () => {
const obj = {}

// @ts-ignore
expect(obj.polluted).toBe(undefined)
expect(() => {
applyPatches({}, [
{op: "add", path: [["__proto__"], "polluted"], value: "yes"}
])
}).toThrow(
isProd
? "24"
: "Patching reserved attributes like __proto__, prototype and constructor is not allowed"
)
// @ts-ignore
expect(obj.polluted).toBe(undefined)
})

test("#648 assigning object to itself should not change patches", () => {
const input = {
obj: {
@@ -207,7 +207,7 @@ export function enablePatches() {
let base: any = draft
for (let i = 0; i < path.length - 1; i++) {
const parentType = getArchtype(base)
const p = path[i]
const p = "" + path[i]
// See #738, avoid prototype pollution
if (
(parentType === Archtype.Object || parentType === Archtype.Array) &&

1 comment on commit fa671e5

@childrentime
Copy link
Contributor

@childrentime childrentime commented on fa671e5 Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mweststrate const p = "" + path[i] will cause issue #952, Caused the map to use a number as a key error.

Please sign in to comment.