Skip to content

Instantly share code, notes, and snippets.

@borisdiakur
Created December 16, 2022 13:08
Show Gist options
  • Save borisdiakur/745c615b5aa7f271eafff57e4c05fef1 to your computer and use it in GitHub Desktop.
Save borisdiakur/745c615b5aa7f271eafff57e4c05fef1 to your computer and use it in GitHub Desktop.
prototype poisoning fix one-liner
// prototype poisoning fix one-liner:
const noProto = (k, v, u) => k === '__proto__' ? u : v
// usage:
const json = '{ "a": 1, "__proto__": { "b": 2 } }'
const obj = JSON.parse(json, noProto)
console.log(obj.a) // 1
console.log(obj.b) // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment