Created
December 16, 2022 13:08
-
-
Save borisdiakur/745c615b5aa7f271eafff57e4c05fef1 to your computer and use it in GitHub Desktop.
prototype poisoning fix one-liner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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