Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

isAllowedKey / isConstructorPrototype / throwOnProto logic is unnecessary and harmful #2

Open
zloirock opened this issue Jan 27, 2023 · 0 comments

Comments

@zloirock
Copy link

A superset of #1.

parseJson('{ "__proto__": 1 }'); // => {}
parseJson('{ "constructor": { "prototype": 1 } }'); // => { constructor: {} }

and SyntaxError with throwOnProto,

when native

JSON.parse('{ "__proto__": 1 }'); // => { __proto__: 1 }
JSON.parse('{ "constructor": { "prototype": 1 } }'); // => { constructor: { prototype: 1 } }

It's absolutely nothing dangerous in constructor: prototype in object literal.

__proto__ and custom Object.prototype getters can be worked around via Object.defineProperty:

      if (key in Object.prototype) {
        Object.defineProperty(object, key, {
          value: result.value,
          enumerable: true,
          writable: true,
          configurable: true
        });
      } else object[key] = result.value;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant